Different value of Exponential moving average ???
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
Replies
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
hiba7rain
01 Sep 2014, 08:59 ( Updated at: 21 Dec 2023, 09:20 )
as below example
@hiba7rain