Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Multi timeframe issues

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

    Multi timeframe issues

    Hi,

    Sorry to bother you but I appear to be banging my head against a wall on this one, so thought that I would seek help.

    I am trying to create a strategy that uses three time frames, one for daily, one for weekly, and the third for monthly. I think that I have managed that ok.

    When I try and access the CurrentBar in the daily chart (in OnBarUpdate()) they do not start at one, it has been 5 or 20, (I think that the differing values might be to do with the start date of the chart that I am using), but I cannot get the values to begin at one. I use the CurrentBar value to get values from the chart and put them into an array, then carry out processing on them. The problem is that if currentBar value is bigger than the array it is accessing, the program fails (obviously)

    I think I can get around the CurrentBar not beginning at one, (as I think this has something to do with the additional periodtypes) but I would just like to get to the bottom of it.

    Also, do you know if it is possible to delete/remove periodTypes e.g. the opposite of Add(PeriodType.Day,1); ?

    I'm sorry if this is not as clear as I mean it to be, but if you require any further information, please just let me know.

    TIA,

    Graham.

    SAmple code below

    protected override void Initialize()
    {
    // Add(PeriodType.Day,1);
    Add(PeriodType.Week,1);
    Add(PeriodType.Month,1);
    CalculateOnBarClose = true;
    BarsRequired = 0;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    int i;
    i = BarsArray.Length;
    // BarsArray[BarsInProgress].Period.Id == "Day"
    // LTTR = CalcRSI();
    // AofT.Add(LTTR);
    // i = AofT[CurrentBar].CalcRSIReturnFlag;

    if (BarsInProgress == 0){
    i = CurrentBar;
    // LTTR = CalcRSI();
    return;
    }

    if (BarsInProgress == 1 ) {
    i = CurrentBar;
    // LTTR = CalcRSI();
    return;
    }

    if (BarsInProgress == 2) {
    i = CurrentBar;
    // LTTR = CalcRSI();
    return;
    }

    #2
    Graham,

    You cannot remove bar objects once you Add() them.

    The reason it does not start at 1 is likely due to the requirement that ALL series have at bars before processing. Even though you set BarsRequired = 0, it still needs all series to be flowing before your strategy can run properly.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for that Josh,

      So it depends what date in the month the start date was, as to the count of CurrentBar when processing begins. As least I now know what is going on.

      I will just need to adjust my original code to deal with that issue. I was accessing an array using array[CurrentBar] which meant at times it fell out of the end of the array, since I thought I had only added 1 item and CurrentBar thought it was 5.

      No problems though.

      Thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Option Whisperer, Today, 07:58 PM
      0 responses
      2 views
      0 likes
      Last Post Option Whisperer  
      Started by cupir2, Today, 07:44 PM
      0 responses
      4 views
      0 likes
      Last Post cupir2
      by cupir2
       
      Started by reynoldsn, Today, 07:23 AM
      6 responses
      19 views
      1 like
      Last Post reynoldsn  
      Started by reynoldsn, Today, 07:26 PM
      0 responses
      5 views
      0 likes
      Last Post reynoldsn  
      Started by ETFVoyageur, 05-07-2024, 07:05 PM
      12 responses
      79 views
      0 likes
      Last Post bltdavid  
      Working...
      X