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

MultiTimeframe Loop question

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

    MultiTimeframe Loop question

    I have the following code that works fine with a single timeframe. When I add the second time array I added a for loop to calculate/index each time frame. I am using range bars and when I loop 1 time (x=1) the plot is correct. When I add the second pass (x=2) neither plot is correct. I tried moving the loop inside the 'else' statement, but got a context error for the x variable.

    This is my first attempt at multi timeframe and I am sure I am making a basic indexing error in my logic, but it has stumped me. Any suggestions would be appreciated.

    Ryan
    Attached Files

    #2
    Hi RyanR,

    Thanks for the post and welcome to the forum!

    The CurrentBar<26 that you have is unfortunately not checking for both time series.
    You will need to use CurrentBars to index the time series's you want to check. The code should look something like this -
    Code:
    if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired)
    The link for CurrentBars - http://www.ninjatrader.com/support/h...urrentbars.htm

    You may also want to use BarsInProgress to filter the For loop and what you are trying to do.
    Click here for more info on BarsInProgress

    There is also a sample strategy called SampleMultiTimeFrame that is available through NinjaTrader. This can be accessed by Tools>Edit NinjaScript>Strategy,
    Select the SampleMultiTimeFrame.


    Please let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      MultiTimeframe Loop question

      Cal,

      Thanks for the information- I applied the changes you suggest and the lower timeframe is correct now but there are gaps on the higher timeframe line. I am trying to have the lines show real time status of that particular timeframe (either higher or lower than charted time). I have seen it done before but I am missing how the refresh should work. I tried 'CalculateOnBarClose' in both states but the problem persists. Once I have the concept working on 2 timeframes I plan to add several more.

      Thanks,

      Ryan

      PS - I tried to add the code to the body with the [code] tag and it said too many characters -I thought I have seen more lines than this posted.
      Attached Files

      Comment


        #4
        Hi RyanR,

        Could you provide a screenshot of the gaps you are seeing?

        To send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

        For detailed instructions please visit the following link

        http://take-a-screenshot.org/

        Do you see any errors? This will be in the Log tab of the control center.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Cal,

          Then upper line represents the higher timeframe and the orange color is the default color, so those are the areas that are not being updated. The more I try and understand the multitimeframe process the more questions I have. Should I be adding another loop inside the 'barsinprogress==x' condition to calculate the plot for each index position?

          Thanks,
          Ryan
          Attached Files

          Comment


            #6
            Cal,

            An update. I tried adding a loop within the loop and that filled in the bar but the higher timeframe is not showing changes correctly. And the lower timeframe is incorrect again. Could you clarify something - The OnBarUpdate is called when a bar change occurs? Then the InBarProgress is used to determine which bar called the update? If so the higher timeframe is not calling the update as I planned. Also I will have to change some logic for the flags.

            Thanks,

            Ryan

            Comment


              #7
              Hi RyanR,

              Yes, the BarsInProgress is an index value of the current Bars object that has called the OnBarUpdate() method.

              OnBarUpdate() is called whenever a bar is updated. For multi-timeframe and instrument strategies, this method is called for each Bars object of a strategy and you MUST filter for the exact bar update events using the "BarsInProgress" property you want your system logic to execute against.

              Were you able to try it out and see if this made any difference?

              Please let me know if I can be of further assistance.
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                Cal,

                Thanks for the clarification. I will definitely have t change some core logic to take that into account. If I want to track the flags per timeframe is there a way besides a data series per timeframe, I guess an array may work. Sorry for all the questions this is kind of new to me.

                Thanks,
                Ryan

                Comment


                  #9
                  Hi RyanR,

                  If I'm following you correctly, anything you want to measure or track that can happen more than once per bar then, yes you would want to use an Array or List.

                  I have attached a link to the Microsoft Developer Network on how to use Arrays and Lists.
                  Click here for more info on Arrays in C#
                  Click here for more info on Lists in C#

                  Please note that custom Lists and Arrays are unsupported with NinjaTrader.

                  Please let me know if I can be of further assistance.
                  Cal H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by giulyko00, Today, 12:03 PM
                  1 response
                  4 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by f.saeidi, Today, 12:14 PM
                  1 response
                  4 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by aprilfool, 12-03-2022, 03:01 PM
                  2 responses
                  326 views
                  0 likes
                  Last Post BottomShark77  
                  Started by AnnBarnes, Today, 12:17 PM
                  1 response
                  2 views
                  0 likes
                  Last Post NinjaTrader_Zachary  
                  Started by Lopat, 03-05-2023, 01:19 PM
                  4 responses
                  169 views
                  0 likes
                  Last Post Sam2515
                  by Sam2515
                   
                  Working...
                  X