Hi guys am new here (to the forum & to coding)
Am trying to code a strategy that executes positions based on candle data collected at the close of each candle, the problem I have is that the ontick function completely messes up the strategy because each time a new tick is released the strategy calculates and sends orders based on incomplete information
I'd like to know if there's a way to run the strategy at the close of each candle rather than each time a new tick is generated.
If anyone knows of a method or a way that can help or bring me closer to what I need please help
Thank you
- Execute Trade only at the open on next New Candle- Need help
- Please help.....
- Need some help with mql5 code please
Learn to use the search function
https://www.mql5.com/en/search#!keyword=new%20candle&module=mql5_module_forum
void OnTick() { if (isNewBar())
and then add this to the bottom of EA. It's messy but it'll do what you want
bool isNewBar() { //--- memorize the time of opening of the last bar in the static variable static datetime last_time=0; //--- current time datetime lastbar_time=SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE); //--- if it is the first call of the function if(last_time==0) { //--- set the time and exit last_time=lastbar_time; return(false); } //--- if the time differs if(last_time!=lastbar_time) { //--- memorize the time and return true last_time=lastbar_time; return(true); } //--- if we passed to this line, then the bar is not new; return false return(false); }
Keith Watford #:
Noted
Learn to use the search function
https://www.mql5.com/en/search#!keyword=new%20candle&module=mql5_module_forum
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