Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Time frame - how do you do it, where do you put stuff and why?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Multiple Time frame - how do you do it, where do you put stuff and why?

    Hi. I have been working with mutliple time frames (secondary series) for a few years now. Sometimes I think I know what I am doing, but in moving to NT8, I think I want to review some coding strategy as to where code goes and why. Bottom line is: the secondary time frame indicators are not working as I expect, and I can't complete my strategies in NT8 until then.

    Here is what I am doing and why.

    NT Support, please don't just send the links to the sample code. I have used the ones you sent, read the manuals.. they are either not complete or not complex enough of an example for me to fully understand things.

    Strategy premise is fairly simple: Use a long time frame (DAILY bars) for direction using CCI and trend lines, shorter time frames for trade execution (30 MINUTE bars).

    I am asking about 2 options:

    OPTION 1: Calculate ALL the second series indicators in the primary data stream (IE: Calcuate the DAILY CCI in the 30 MINUTE time frame - in BarsInProgress==0 (I do want to know the CURRENT value for the CCI in Daily

    CODE SNIPPITS:
    1) #region Variables
    private Series<double> CCIData_1; // holds the CCI data for TF1


    2) protected override void OnStateChange()
    {
    if (State == State.SetDefaults)

    // standard defaults
    BarsRequiredToPlot = 20;
    CCIPeriod = 6;

    2) else if (State == State.Configure)

    //Add the second data series here
    AddDataSeries(Data.BarsPeriodType.Day, 1);


    3) else if (State == State.Historical)
    /* Syncs another DataSeries object to the secondary bar object.
    We use an arbitrary indicator overloaded with an ISeries<double> input to achieve the sync.
    The indicator can be any indicator. The Series<double> will be synced to whatever the
    BarsArray[] is provided.
    */

    QUESTION: NT - Given Option 1 below, do I need to do this step IF the DAILY (second series) is calculated in BarsInProgress==0 ?
    CCIData_1 = new Series<double>(SMA(BarsArray[1], 50));

    4) protected override void OnBarUpdate()
    {
    if ((CurrentBars[0] <= BarsRequiredToPlot) ||
    (CurrentBars[1] <= BarsRequiredToPlot))
    return;
    This is standard, but


    OPTION 1: Calculate all DAILY indicators on every TICK (or IsFirstTickOfBar)
    if(BarsInProgress == 0)
    {
    CCIData_1[0] = CCI(BarsArray[1], CCIPeriod)[0];

    // this would give me the most up to date value for the DAILY CCI

    ISSUE: NT Support - this is NOT working correctly - Even at end of day, I get a different value for the calculated value for CCI using this method, than I do on a chart where I just add the indicator to the daily chart. The numbers are NOT the same.

    OPTION 2: Calculate ALL DAILY indicators in BarsInProgress==1, then reference the data in BarsInProgress==0

    else if(BarsInProgress == 1)
    {
    CCIData_1[0] = CCI(BarsArray[1], CCIPeriod)[0];

    // this way would calculate the CCI only on ticks in BIP1, rather than the more frequent ticks of BIP0. You could reference CCIData_1[0] in BIP0.

    QUESTION 1) What is the best practises on using multiple time frames? Should we use the fastest time frame in BIP0? (I have typically tried to put it fastest (BarsInProcess==0) to slowest time frame (BarsInProcess==1)

    QUESTION 2) Am I doing all the right things here? Do most people use Option 1 or Option 2?

    #2
    Hello,

    The short story is that you do appear to be doing things correctly.

    Is there a separate issue here other than the one we are addressing in the other post?



    If not, please see my reply from this morning, and you can expect me to update that post when further information is available.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Hi Dave, yes. the reason for this post is to understand where my processing is to be done.

      Take for example the CCI. I want to calculate CCI in 3 time frames (Daily, 30 min, say 5 min) and then make decisions on that in the strategy.

      Option 1 - calculate everything in the fastest time frame (which I set to be BarsInProcesss==0)

      or

      Option 2 - calculate CCI in EACH of the BarsInProcesss==2, BarsInProcesss==1 and BarsInProcesss==0 then reference each of those calculated variables.

      The issue with Option 2 is that the longer bars don't give me a value until the END of that bar, and I need to have the current values in the shortest time frame - so I calculate everything in BarsInProcess==0

      There is now a LOT of code in there, that probably doesn't need to be run on every tick in BIP0.

      I am looking for guidance on the coding - how does everyone else do it?

      Thanks

      Comment


        #4
        The answers to both questions will really depend upon exactly how often you need to update the data to suit your purposes. Option 2 (calculating once per daily bar then passing the value) will have a smaller performance impact, while giving you delayed updates from the perspective of your smaller timeframe, whereas Option 1 (calculating once per OnBarUpdate() of the smaller timeframe) will have a larger impact while giving you more frequent updates. Although, if this is the extent of what you are doing, then either option should not have a noticeable impact in terms of user experience.

        I will leave it to other forum users to comment on which option they would consider a best practice in their own code, but the official response that I can offer is that both approaches should work, and as long as you do not really need the more frequent updates, then I would suggest going with Option 2.

        That being said, using either of these options successfully will likely depend upon the solution that we find to the issue of the CCI method overload always using BarsArray[0] as input when a different index is specified.
        Dave I.NinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bmartz, Today, 09:30 AM
        2 responses
        11 views
        0 likes
        Last Post bltdavid  
        Started by f.saeidi, Today, 11:02 AM
        1 response
        2 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by geotrades1, Today, 10:02 AM
        4 responses
        12 views
        0 likes
        Last Post geotrades1  
        Started by rajendrasubedi2023, Today, 09:50 AM
        3 responses
        16 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by lorem, Today, 09:18 AM
        2 responses
        11 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X