-
if(prev_calculated == 0) limit = rates_total - 1-10; else limit = rates_total - prev_calculated;
Do your lookbacks correctly #9 — #14 & #19. (2016)
-
pricesArray[i] = iMA(NULL, HigherTimeframe(), 1, 0, MODE_SMA, PRICE_CLOSE, i)
-
On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019) -
Is pricesArray an array and did you resize it properly, or a buffer?
Always post all relevant code (using Code button) or attach the source file.
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problem
Thank you. I'm aware about the mistakes you mentioned. But forget those. I'm curious about another problem. Why iMA() return different values on same indicator (one is attached to chart (tester template) and the other one select by strategy tester)?
I attached a screenshot from strategy tester
In strategy tester one, iMA() returns new data with forwarding the chart, but in attached one, iMA() return same old data. Both are 1 function, why act different?
Always post all relevant code
//+------------------------------------------------------------------+ //| test.mq4 | //| Copyright 2023, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2023, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_separate_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- Print("Window: ",WindowOnDropped()," MA: ",iMA(Symbol(),PERIOD_M15,1,0,MODE_SMA,PRICE_CLOSE,1)); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
I have deleted all distraction codes. attach this to a chart, save template as tester.tpl. Then open strategy tester and select this indicator and M5 timeframe. After start you see 2 same indicator but they print different values. First one prints same price all time,but second one updates correctly
- 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. I attached my custom indicator to a naked chart and save the template as "tester.tpl". Then I run strategy tester and select the indicator again. So in visual mode I see 2 of this indicator.
These 2 indicators works different! After many checks, I found that the one is attached by template doesn't update pricesArray[]. Chart goes forward but iMA() still returns same values. How can I solve this problem?
This problem not solved even by replacing CopyClose() instead of iMA()
Edit: When I press start button I see both indicators draw fine at the past, but after the starting time, the one that is in template not update correctly