Calculated Moving average mode SMMA different in strategy tester visualization compared to normal chart

 

Dear all,

I found out that the calculated moving average (mode SMMA) is different vom the same moving average in the normal chart window.

The consequence is a wrong behavour of the EA.


Let's take this small "EA" to show the problem:

void OnTick()
  {
      // Create an array
      double myMovingAverageArray[];
      
      // define properties of moving average
      int MovingAverageDefinition = iMA (_Symbol, _Period, 400, 0, MODE_SMMA, PRICE_CLOSE);
      
      // sort the price array downwards
      ArraySetAsSeries (myMovingAverageArray, true);
      
      // Copy values
      CopyBuffer (MovingAverageDefinition, 0, 0, 3, myMovingAverageArray);
      
      // Calculate moving average for the current candle
      double myMovingAverageValue = myMovingAverageArray[0];
      
      // Print the value on chart
      Comment ("myMovingAverageValue: ", myMovingAverageValue);
   
  }


The EA is working with the dow jones index and has the following settings:

EA settings


This is the standard chart with the moving average (black line):

Standard Chart Window

This is the settings of the moving average:


I saved exactly this chart as template "tester.tpl".

Then I start the EA.

Result:

As you can see, the values for the moving average on the "standard chart" is different from the moving average produced by the tester:

Date Mode Value Standard Chart Value Tester
28.12.2018 SMMA 22107 23334
 
Jorg1: I found out that the calculated moving average (mode SMMA) is different vom the same moving average in the normal chart window.
  1. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. To come even close to a correct value, your 400 SMMA requires at least 2760 bars — Your problem isn't the tester, it's lack of bars in the tester.
    1. Never any reason to use the SMMA(L) it's equivalent to the EMA(2L-1).
                The Smoothed Moving Average or SMMA - How to Avoid It - NinjaTrader Programming | futures.io

    2. EMA requires 3.45×(Length+1) bars to converge to 1/10 percent.
                Moving average - Wikipedia

 
Jorg1:

Do not double post!

I have deleted your other topic.

Reason: