Download MetaTrader 5
To add comments, please log in or register
Publish your application in Cobe Base. Millions of traders will see it!
sd59
499
sd59 2015.08.01 15:23 

Just messing around with code to get it right before implementing - this is to find the first trade of a particular type in the history pool.

Code below + printed output.

Does anybody know why it seems to think that GBPUSD is the same as EURUSD?

void OnStart()
{
  int Magic = 170715;
  for(int i=OrdersHistoryTotal()-1;i>=0;i--)
  {                                                     
   if(OrderSelect(i, SELECT_BY_POS,MODE_HISTORY)== True)       
   {                                                     
    Print(i,"  ",OrderTicket());
    //if order is for this symbol & magic number
    if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY || OrderType() == OP_SELL)
    {
     Print(OrderSymbol(),"  ",Symbol());
     Print(OrderTicket()+"  ",OrderType());
    
     if(OrderType() == OP_BUY && OrderProfit() > 0){Print(Symbol(),"buy > 0");break;}
     if(OrderType() == OP_BUY && OrderProfit() < 0){Print(Symbol(),"buy < 0");break;}
     
     if(OrderType() == OP_SELL && OrderProfit() > 0){Print(Symbol(),"sell > 0");break;}
     if(OrderType() == OP_SELL && OrderProfit() < 0){Print(Symbol(),"sell < 0");break;}
    } 
   }
  }
}
sd59
499
sd59 2015.08.01 16:30  

I think I found the problem: extra brackets!

if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == OP_BUY || OrderType() == OP_SELL))
/
To add comments, please log in or register