Is there any 'template code' that accomplishes at least 90% of this?
My EA is basic - just needs to know if trade is there. No trailing stop or anything.
I have language like this:
int trade;
for(trade=OrdersTotal()-1;trade>=0;trade--)
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==false)
continue;
if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
continue;
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
if(OrderType()==OP_BUY)
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue);
}//for
Will that catch previously opened trades?
The following when called will detect the number of open and pending orders.
int CountTrades()
{
int count=0;
int trade;
for(trade=OrdersTotal()-1;trade>=0;trade--)
{
OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
continue;
if(OrderSymbol()==Symbol() && OrderMagicNumber()== MagicNumber)
{
if((OrderType()==OP_SELL) || (OrderType()==OP_SELLSTOP) || (OrderType()==OP_SELLLIMIT) ||
(OrderType()==OP_BUY) || (OrderType()==OP_BUYSTOP) || (OrderType()==OP_BUYLIMIT))
count++;
}
}//for
return(count);
}

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Is there anything special I need to do with an EA when restarting if there is a current trade open on the currency pair?