PHP Code:
if(AccountEquity()<AccountBalance()) {
{
int ttotal = OrdersTotal();
for(int i=ttotal-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
break;
//Close opened short positions
case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
}
if(result == false)
{
Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(3000);
}
}
return(0);
}
}
}
ok this is what I tried ..it's mostly copied from another code someone else here made...but it's just closing everything as fast as they open and not paying any attention to the 'if' condition before executing closes....oy I'm not good at this....I obviously don't have the part that is doing the closing of orders sufficiently attached to the conditional line that compares the account equity to the account balance. Could someone please help me with this?