iMA not displaying correctly in backtesting

iMA not displaying correctly in backtesting

Manage alerts

Loading saved threads...

Lorenzo W. · External communityPost link
External question — Stack Overflow Stack Exchange Author: Lorenzo W. Original post: https://stackoverflow.com/questions/69502698 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I developed and started testing an EA in MQL4 that uses iMA function. Basically the program compares the iMA value of the current candle with the iMA value of the previous candle. When I test the EA using the Strategy Tester (Every Tick) my EA is not opening and closing trades correctly. What I mean is the trade does not open on the correct candle. Upon further investigating I noticed, on the current candle the value for iMA in the data window and chart are the same, but they difer from the 'Print' value. The value for the previous candle is correct. When I did a Google search I found that someone in 2008 reported this exact same issue. In 2008 there didn't appear to be a solution. Now that we are in a new decade, I'm wondering if there is a solution? Does anyone know if iMA works in MQL5 Strategy Tester? double MAEMACurrent = iMA(NULL,0,3,0,MODE_EMA,PRICE_CLOSE,0); double MAEMAPrevious = iMA(NULL,0,3,0,MODE_EMA,PRICE_CLOSE,1); double MASlowEMACurrent = iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,0); double MASlowEMAPrevious = iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,1); Print("MAEMACurrent " + MAEMACurrent + " MAEMAPrevious " + MAEMAPrevious + " MASlowEMACurrent " + MASlowEMACurrent + " MASlowEMAPrevious " + MASlowEMAPrevious); Chart & Data Window: MAEMACurrent: 1.95552 MAEMAPrevious: 1.95572 MASlowEMACurrent: 1.95201 MASlowEMAPrevious: 1.95097 Print Value: MAEMACurrent: 1.95538 MAEMAPrevious: 1.95572 MASlowEMACurrent: 1.951086 MASlowEMAPrevious: 1.950972 As you can see from the above example the 'Chart & Data Window' values for MAEMACurrent and the MASlowEMACurrent do not match 'Print Value'. This is the first time that I'm asking a question, so if I've missed something or I am not following the correct protocol for asking a question please let me know.
Quote
Report
amirfg · External communityPost link
External answer — Stack Overflow Stack Exchange Author: amirfg Original post: https://stackoverflow.com/a/69539588 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. First, always use the "NormalizeDouble" function to round the values to a proper number of fractions. In your case, if there are just 5 digits after fraction, use the following code to round the values of "MASlowEMACurrent" and "MASlowEMAPrevious" to 5 digits: double dNormalizedValue = NormalizeDouble(MASlowEMACurrent, 5); In addition, never compare the value of the in-progress candle on the chart with the values which are returned by the indicator or price functions like (iMA, iClose, etc). Please note that even a very slight time difference could cause differences in the two values. For other candles (in your case the previous candle), since they all have been closed and there are no changes in progress so you can compare the values on the chart with the values returned by the functions. So, iMA is working as expected.
Quote
Report

Post Reply

Checking account access…