Buffer values don't faithfully in chart? (Should have been simple!)

 

Hi All,


I am currently using the rudimentary peice of code to populate 2 buffers .. one for a slow Ma and one for a fast Ma.


TestC1HandleFast = iMA(SymbolArray[SymbolLoop],PERIOD_CURRENT,FastMALength,0,MODE_EMA,PRICE_CLOSE);   

TestC1HandleSlow = iMA(SymbolArray[SymbolLoop],PERIOD_CURRENT,SlowMALength,0,MODE_EMA,PRICE_CLOSE);    

   double TestC1Arr0[],TestC1Arr1[];

   bool FillTestC1Arr0 = CopyBuffer(TestC1HandleFast,0,0,3,TestC1Arr0);

   bool FillTestC1Arr1 = CopyBuffer(TestC1HandleSlow,0,0,3,TestC1Arr1);


Everything matches up for candle 1 (the most recent confirmed candle)

However when I look to confirm candle 2 (the completed candle prior) then the results fail to match up between data window and what has been captured in the array.

In the example below i have mouse'd over the candle prior:

This is done with the built in EMA in MT5. Any idea what causes this?? It seems so very odd! I can't do MA crossovers as things stand.


Thanks!!


Dan

 
Jdan43: . Any idea what causes this?? It seems so very odd
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
          General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
              Messages Editor
          Forum rules and recommendations - General - MQL5 programming forum (2023)

  2.  double TestC1Arr0[],TestC1Arr1[];
       bool FillTestC1Arr0 = CopyBuffer(TestC1HandleFast,0,0,3,TestC1Arr0);
       bool FillTestC1Arr1 = CopyBuffer(TestC1HandleSlow,0,0,3,TestC1Arr1);

    In MT5, you must set the direction.

    To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] arrays, call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
              Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5