Originally Posted by forextrend
here:
// Closing of Open Orders
void OpenOrdClose()
{
int total=OrdersTotal();
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(total-cnt-1, SELECT_BY_POS);
int mode=OrderType();
bool res = false;
bool condition = false;
if (OrderMagicNumber()==Magic ) condition = true;
if (condition && ( mode==OP_BUY || mode==OP_SELL ))
{
// - BUY Orders
if(mode==OP_BUY)
{
res = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Or derSymbol(),MODE_BID),3,Yellow);
if( !res )
{
Print(" BUY: OrderClose failed with error #",GetLastError());
Print(" Ticket=",OrderTicket());
Sleep(3000);
}
}
else
// - SELL Orders
if( mode == OP_SELL)
{
res = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Or derSymbol(),MODE_ASK),3,White);
if( !res )
{
Print(" SELL: OrderClose failed with error #",GetLastError());
Print(" Ticket=",OrderTicket());
Sleep(3000);
}
}
}
}
}
void TotalProfit()
{
int total=OrdersTotal();
totalPips = 0;
totalProfits = 0;
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
int mode=OrderType();
bool condition = false;
if ( Magic>0 && OrderMagicNumber()==Magic ) condition = true;
else if ( Magic==0 ) condition = true;
if (condition)
{
switch (mode)
{
case OP_BUY:
totalPips += MathRound((MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT));
//totalPips += MathRound((Bid-OrderOpenPrice())/Point);
totalProfits += OrderProfit();
break;
case OP_SELL:
totalPips += MathRound((OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK))/MarketInfo(OrderSymbol(),MODE_POINT));
//totalPips += MathRound((OrderOpenPrice()-Ask)/Point);
totalProfits += OrderProfit();
break;
}
}
if (UseSwap) {
SwapProfit();
totalProfits = totalProfits + valueswap;
}
}
}
void sidePips()
{
int total=OrdersTotal();
shortPips = 0;
longPips = 0;
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
int mode=OrderType();
bool condition = false;
if ( Magic>0 && OrderMagicNumber()==Magic ) condition = true;
else if ( Magic==0 ) condition = true;
if (condition)
{
switch (mode)
{
case OP_BUY:
longPips += MathRound((MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT));
break;
case OP_SELL:
shortPips += MathRound((OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK))/MarketInfo(OrderSymbol(),MODE_POINT));
break;
}
}
}
}
|