Different value of Exponential moving average ???

Created at 31 Aug 2014, 19:51
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
HI

hiba7rain

Joined 20.07.2014

Different value of Exponential moving average ???
31 Aug 2014, 19:51


Hi

am trying to use the exponential moving average on a Cbot as follows

         [Parameter("MAType", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MaType { get; set; }

public ExponentialMovingAverage ema; 

protected override void OnStart()

        {
            
            ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 12);

 Print("{0}", ema);

but i noticed that the values printed are not as same as the moving average indicator shows and I dont know why , your help will be much appreciated

Thanks  


@hiba7rain
Replies

hiba7rain
01 Sep 2014, 08:59 ( Updated at: 21 Dec 2023, 09:20 )

as below example


@hiba7rain

Spotware
01 Sep 2014, 09:53

Please make sure that Periods of indicators are the same. Also, it is not clear how do you print values of indicator, because statement Print("{0}", ema) supposed to print name of indicator instead of its values.


@Spotware

hiba7rain
01 Sep 2014, 10:06

RE:

sorry apologize for the typing mistake, the statement used to print the values is

protected override void OnBar()
        {

            var emaa = ema.Result.LastValue;
            Print("{0}", emaa);

I did check the indicators period several times and change both on the indicator and the Cbot statement but still I get a difference in values between actual indicator value and the printed value

Spotware said:

 

Please make sure that Periods of indicators are the same. Also, it is not clear how do you print values of indicator, because statement Print("{0}", ema) supposed to print name of indicator instead of its values.

 


@hiba7rain

Spotware
01 Sep 2014, 10:33

OnBar event happens when new bar is opened. At that moment MarketSeries collection already contains tick from new bar. It means that last bar is not formed and in general cases open = high = low = close. If you want to access to last formed bar you need take previous one.

            Print("{0}", ema.Result.Last(1));

 


@Spotware

hiba7rain
01 Sep 2014, 10:54

RE:

Thanks its fine on previous bar value , so if someone decide to go OnTick instead of OnBar the values would be accurate or still with some difference?

 

Spotware said:

OnBar event happens when new bar is opened. At that moment MarketSeries collection already contains tick from new bar. It means that last bar is not formed and in general cases open = high = low = close. If you want to access to last formed bar you need take previous one.

            Print("{0}", ema.Result.Last(1));

 

 


@hiba7rain

Spotware
01 Sep 2014, 11:07

RE: RE:

hiba7rain said:

Thanks its fine on previous bar value , so if someone decide to go OnTick instead of OnBar the values would be accurate or still with some difference?

 

Spotware said:

OnBar event happens when new bar is opened. At that moment MarketSeries collection already contains tick from new bar. It means that last bar is not formed and in general cases open = high = low = close. If you want to access to last formed bar you need take previous one.

            Print("{0}", ema.Result.Last(1));

 

 

In case of usage OnTick handler last bar is a live bar as well. You need to use previous values if you want to calculate indicator based on formed bars.


@Spotware