Maybe the following modified code will help (I find it simpler and thus, less prone to error and perhaps easier for another person to spot any issue(s) ... but this is just my opinion):
static double ADX15minValues[81]; static int count = 0; int interval = 15;//15 seconds int timeBack = 60 * 20;//20 minutes static int waitTime = 0; static bool isFirst = true; if ( isFirst ) {//have to use isFirst for waitTime static to prevent TimeCurrent() - initialization expected error waitTime = TimeCurrent() + interval; isFirst = false; } if ( TimeCurrent() >= waitTime ) { waitTime = TimeCurrent() + interval; ADX15minValues[count] = iADX(NULL, PERIOD_M15, 5, PRICE_CLOSE, MODE_MAIN, 0); count++; } if ( count >= (timeBack / 15) ) { string MINagoADX = DoubleToStr(ADX15minValues[0], 6); Print("the ADX for EXACTLY 20 minutes ago was, ", MINagoADX) ; count = 0;//reset count }
Additionally, your 2 minute average delay could be attributed to other issues. For example, if the market is slow you may not be receiving ticks every second, thus it is quite possible that some of your 15 second intervals could actually be larger. You may want to try adding a tick sender script. The above code seemed to work for me when using a tick sender (seemed to be within +/-20 seconds or so) ...
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
I am currently working on making my EA able to look at the ADX exactly 20 minutes ago. This is a continued idea from https://www.mql5.com/en/forum/144585 but I have worked over the weekend on this and think its appropriate to open another thread (if I'm wrong here, sorry administrators)
My code is close except when I backtest (over one day since it will have so many values) the spread from the instantaneous ADX value (from the iADX) to looking at the value 20 minutes in the future is on average 2 minutes early. This is not always the case so just adding a few more spaces to my array is not the answer. I have already tried that. This is close, but any advice/suggestions are highly valued. Thank you in advance.