Hello all,
I want to build an EA for this purpose, “when account equity reach to defined value by user, close all positions of all symbols”,
I write below code, but it doesn’t work.
Please help me for modify it.
Thanks.
#property strict
#include <stdlib.mqh>
extern int TargetEquity=5000;
void OnTick()
{
if(AccountEquity()>=TargetEquity)
{
int ticket=0;
int total=OrdersTotal();
int i = 0;
for(i = total; i >=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY || OrderType()==OP_SELL)
{
ticket = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_ASK),5);
ticket = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_BID),5);
}
}
}
}
}