help needed

 

i want my ea to be closing all the trade s when the equity is greater than accountbalance, but all my efforts are in vain. this how i used ;


int start()

if(AccountEquity()-AccountBalance()>=my_profit*my_lot)closenow=true;

if(closenow==true)
{
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
double price;
if (OrderType()==OP_BUY)
price = MarketInfo(OrderSymbol(), MODE_BID);
}
if (OrderType()==OP_SELL)
price = MarketInfo(OrderSymbol(), MODE_ASK);
{
OrderClose(OrderTicket(), OrderLots(), price, Slippage,Violet);
Print("??????? ???????", OrderTicket());
}
}
}
return(0);

i discovered that it closes at minus without the profit realised.

please help

 

You probably would like to remove/move the "}" after the OP_BUY if because it closes the for statement before checking for OP_SELL.

for(cnt=0;cnt<total;cnt++)
{
  OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
  double price;
  if (OrderType()==OP_BUY) price = MarketInfo(OrderSymbol(), MODE_BID);
} // ----> this one closes the for cnt statement

thank you

Automated

--

real time grid trading video, +531 pips in 24 hours:

http://www.gridtradingcourse.com/videos/news_grid_trading_chfjpy_3/Grid_Trading_CHFJPY.html


http://grid9.forexmosaic.com/ - 8621 pips in 7 weeks of grid trading

 
keylove:

i discovered that it closes at minus without the profit realised.


One more thing:

Reason: