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

Passing values to different time frames

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

    Passing values to different time frames

    I am trying to get a strategy going that uses 3 time frames. I understand how to use the barsinprogress,barsarray calls to find indicator values using different time frames.

    My question is if its possible to pass any values to different time frames

    For example,

    if (BarsInProgress == 1 )
    variable1 = Swing(5).SwingHigh[0];

    if (BarsInProgress ==2)
    Print (variable1.ToString)

    I keep getting an error when I try to do this. I understand that if I use barsarray I will have no problem but for some reason when I use barsarray my values are a little messed up. It would be easier if I could pass values from one barsinprogress to the next, but obviously I dont think this is possible since I am getting errors all the time

    Any ideas?

    #2
    eurostoxx trader, ToString is a method, hence you need to use this syntax when calling it in your code -

    Code:
     
    Print(variable1.ToString());
    BertrandNinjaTrader Customer Service

    Comment


      #3
      thanks bertrand, sorry I just wrote the code quickly,shorthand.

      Even when I do use the correct syntax, I am still stuck

      Any thoughts? I am thinking of just using the stream writer

      Comment


        #4
        What exactly the issue you're running into here? Have you checked for log errors already?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Ok I think i found where the problem is... this is the error i have been getting

          **NT** Error on calling 'OnBarUpdate' method for strategy 'highestbar/561ad8c1a5ad4afea7ea71f05760bf29': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

          I think it has to do with the following. I have 3 time frames in the strategy. Assuming I use 1min in the strategy as the main, i have added:

          Add(PeriodType.Minute, 3);
          Add(PeriodType.Minute, 5);
          Add(PeriodType.Minute, 30);

          I assume that " BarsInProgress == 1 " is for the 3min, 2 --> 5min and 3--> 30min

          I think it has do with that... Also I think I need to call BarsInProgress == 1 then BarsInProgress ==2 etc etc... is this correct? Because I tried calling ==3 and that is when I got the error

          Here is the code
          Code:
          if (BarsInProgress == 0)
          {
          PrintWithTimeStamp("The value of the past 3 swings highs, using 3 min intervals are");
                  Print(SHigh3min_1.ToString() ); 
                  Print(SHigh3min_2.ToString() + " at " + Time[ba_SHigh3min_2 *3].ToShortTimeString()+ " using the ba of " + ba_SHigh3min_2.ToString()  ); 
                  Print(SHigh3min_3.ToString() + " at " + Time[ba_SHigh3min_3 *3].ToShortTimeString()+ " using the ba of " + ba_SHigh3min_3.ToString()  ); 
                      Print(SHigh3min_4.ToString() + " at " + Time[ba_SHigh3min_4 *3].ToShortTimeString() + " using the ba of " + ba_SHigh3min_4.ToString()  
          } // closing brack for baring in progress 0        
                      
                  if (BarsInProgress == 1 )
                  {
                  SHigh3min_1 = Swing(5).SwingHigh[0];    
                  ba_SHigh3min_2 = Swing(5).SwingHighBar(0,2,50) ;
                  SHigh3min_2 = High[ba_SHigh3min_2];
                  ba_SHigh3min_3 = Swing(5).SwingHighBar(0,3,100) * 3;
                  SHigh3min_3 = High[ba_SHigh3min_3];
                  ba_SHigh3min_4 = Swing(5).SwingHighBar(0,4,100) * 3;
                  SHigh3min_4 = High[ba_SHigh3min_4];            
                  }

          Comment


            #6
            eurostoxx trader, you don't have to call them in order - but you should add a current bars check for related to each series so you don't run into the issue to access bars that are not available ...

            if (CurrentBars[0] < 0 || CurrentBars[1] < 0 || CurrentBars[x] < 0.....) return;
            BertrandNinjaTrader Customer Service

            Comment


              #7
              thanks guys for your help.. I think I found where the problem is and perhaps some others may have encountered. Here are my thoughts

              When using multi time frame strategies, i found that the order of using if (BarsInProgress == XX) makes a large difference. For instance, if I want to grab data from BarsInProgress ==2 and then use it in BarsInProgress== 0, I have to put it in the correct order in the script. If I call BarsInProgress==0 first, without having written the script for BarsInProgress ==2, the script values wont calculate correctly.

              Anyway, problem solved on my end, and I really appreciate all the help

              Thanks again

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Gerik, Today, 09:40 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by RookieTrader, Today, 09:37 AM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by alifarahani, Today, 09:40 AM
              0 responses
              5 views
              0 likes
              Last Post alifarahani  
              Started by KennyK, 05-29-2017, 02:02 AM
              3 responses
              1,284 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by AttiM, 02-14-2024, 05:20 PM
              11 responses
              185 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X