if(dayprof = 20.00)
-
That is not a comparison ("==") it is an assignment ("=").
-
Doubles are rarely equal. Understand the links in:
The == operand. - MQL4 programming forum #2 (2013) -
Your code stop only when profit/loss exactly equals 20. What happens if it is one cent past that?
There are a few things wrong there. I recommend not using global variable for dayprof (and it cannot be bool – but double) – just return value of daily profit by your DayProfit() function. Then call this function on every tick and if result is more than assumed daily profit - simply send alert (but then you need to block other alerts for this day) and send return (to block further trading for this day) like:
if(dayprof>=20){
Alert(“dayprof reached”);
return;
}else {
//normal trading
}And also in the Dayprofit function you need to choose only deals that are interesting for you:
so add a few ifs:
if(HistoryDealGetInteger(Ticket,DEAL_TIME) <sdate) continue; //omit trades closed earlier than today
if(HistoryDealGetInteger(Ticket,DEAL_SYMBOL) !=_Symbol) continue; //omit trades from other symbols
etc…

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello guys, please I need help in making my bot to stop trading when my target profit for the day has been reached. I have written down a few codes but it is bringing up an alert of target profit for each currency pair( It is in the picture attached ). All I want is for the bot to alert me when I have reached my target profit of the day maybe stop algo trading when the profit is hit. Please assist me with this guys🙏🏼. Thank you. Here is my code below: