Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi Guys,
I know from some other posts that I may not get the solution for free.
I'm trying to create an EA that will stop trading when it reaches a profit target.
I have managed to get it to switch autotrading off but it keeps repeating. I've only just started learning so any guidance is helpful.
Here is what I have.
extern bool CloseOrder=true; //Close All Order
bool CExpert::CloseAll(double lot);
bool PositionCloseBy(
const ulong ticket, // position ticket
const ulong ticket_by // opposite position ticket
);
extern bool disableexpert=true; //Disable Expert Advisor
extern double EquityTarget=3700; //Equity Take Profit (USD)
extern double EquityStop=0; //Equity Stop Loss (USD)
void OnTick()
{
double equity=AccountInfoDouble(ACCOUNT_EQUITY);
double accbalance=AccountInfoDouble(ACCOUNT_BALANCE);
double profit=AccountInfoDouble(ACCOUNT_PROFIT);
int total=OrdersTotal();
if(AccountInfoInteger(ACCOUNT_TRADE_EXPERT))
{
if(equity>=EquityTarget)
{
if(total!=0 && CloseOrder==true)
{
CloseAllTrade();
}
if(disableexpert)
{
DisableEA();
}
Print("reached equity Target level");
}
}
}
//disable autotrading
void DisableEA()
}
keybd_event(17,0,0,0);
keybd_event(69,0,0,0);
keybd_event(69,0,2,0);
keybd_event(17,0,2,0);
}
I realise that it might be totally wrong.
Thanks in advance!