SmartQuant Discussion

Accessing indicators from different time frames
Page 1 of 1

Author:  aomega [ Wed Nov 07, 2007 6:46 am ]
Post subject:  Accessing indicators from different time frames


I'm trying to access indicators from multiple time frames in the strategy. In particular, I have 2 bar series, one for 30 minutes and one for 4 hours. The indicator is the stochastic indicator. I cannot find how to get access to the indicator for the 4 hour time frame.

Consider this OnStrategyStart method:
public override void OnStrategyStart()
      _dSlow = new D_Slow(Bars, 5, 3, 3, Color.Red);
      _kSlow = new K_Slow(Bars, 5, 3, Color.Blue);
      Draw(_dSlow, 2);
      Draw(_kSlow, 2);         

I note that the above code produces two bar charts for each time frame. When I switch between the 30m and 4h charts, I can clearly see the correct (30m or 4h) stochastic indicator chart at the bottom. Therefore, somehow the indicator for 4h is being built - I just can't get access to it in code.

I tried two things. First, the member variable _dSlow always refers to the indicator in the 30 minute timeframe, even when OnBar() is called with a 4 hour bar. So that's not it.

I also tried making a new indicator and specifying the 4h bar series like this (in OnStrategyStart):

_fourDSlow = new D_Slow(GetBars(BarType.Time, 14400), 5, 3, 3, Color.Red);

however, the indicator is also built with 30minute bars - it is identical to the _dSlow indicator.

How can I get the 4h indicator???

- AO

Author:  ivb73077 [ Wed Apr 06, 2011 6:10 pm ]
Post subject:  Re: Accessing indicators from different time frames


Did you ever figure out the solution to this problem? I am encountering the same issue and would appreciate any guidance you can provide.

Thank you.

Author:  RedEye [ Fri Apr 22, 2011 6:34 am ]
Post subject:  Re: Accessing indicators from different time frames


Author:  Dr. Anton Fokin [ Fri Apr 22, 2011 8:58 am ]
Post subject:  Re: Accessing indicators from different time frames


- add 30 min and 4 hour bars to the market data folder of your strategy. Make sure you are getting these bars into your strategy.
- get reference to these bar series in your strategy

bars30m = GetBars(30*60);
bars4h = GetBars(4*60*60);

This is the key point. You should not use default Strategy.Bars if you have more than one time frame. You have no guarantee if Bars refers to 30 min or 4 hour series.

- use these series as inputs to corresponding indicators.

Though I still don't fully understand the original question. What do you mean you can not access indicators?


Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group