Stanton Roux:
Compiled, not tested. Hi There
I have an EA and would like to not enter any more trades if the profit target has been reached for the day.
If I have a 5% target for the day
I have put this code in the ontick function but it does not seem to be doing anything.
if(m_account.Equity()>=m_account.Balance()*5) return;
Any help would be appreciated.
Thanks
You need to code the close positions and delete pending orders part.
#include <Trade\AccountInfo.mqh> CAccountInfo m_account; int day; double day_balance; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- day=DayOfYear(); day_balance=m_account.Balance(); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- new day if(day!=DayOfYear()) { day=DayOfYear(); day_balance=m_account.Balance(); } if(m_account.Equity()>=day_balance*1.05) { CloseAllPositions(); DeleteAllPending(); return; } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int DayOfYear() { MqlDateTime cur_time; TimeToStruct(TimeCurrent(),cur_time); return cur_time.day_of_year; } //+------------------------------------------------------------------+ //| Here code to close open positions | //+------------------------------------------------------------------+ void CloseAllPositions() { } //+------------------------------------------------------------------+ //| Here code to delete pending orders | //+------------------------------------------------------------------+ void DeleteAllPending() { }
Amir Yacoby:
Compiled, not tested.
You need to code the close positions and delete pending orders part.
Compiled, not tested.
You need to code the close positions and delete pending orders part.
it seems to be working.
Only change I made was to replace.
if(m_account.Equity()>=m_account.Balance()*1.05) { CloseAllPositions(); DeleteAllPending(); return; } } with if(m_account.Equity()>=day_balance*1.05) { CloseAllPositions(); DeleteAllPending(); return; } }
Stanton Roux:
Yes, I replaced it shortly after first publish.
it seems to be working.
Only change I made was to replace.
Amir Yacoby:
Yes, I replaced it shortly after first publish.
Yes, I replaced it shortly after first publish.
Thanks for this will investigate further and do some back tests.
Much appreciated

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi There
I have an EA and would like to not enter any more trades if the profit target has been reached for the day.
If I have a 5% target for the day
I have put this code in the ontick function but it does not seem to be doing anything.
if(m_account.Equity()>=m_account.Balance()*5) return;
Any help would be appreciated.
Thanks