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

Basic Multi Time Frame Problem

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

    Basic Multi Time Frame Problem

    I am having trouble with multi frames.

    I have “Add(PeriodType.Minute, 10);” in the “Initialize()” section.

    If I just write the following in “OnBarUpdate()”
    “if (BarsInProgress == 0)
    Plot0.Set(1);“

    It works and outputs a 1. But if I just have
    “if(BarsInProgress == 1)
    Plot0.Set(2);”

    It outputs a 0.

    My data feed is TD Ameritrade.

    I feel like I must be missing something basic. Any ideas why I'm having trouble? Thanks in advance.

    #2
    Hello TheDarg,

    Thank you for your note and welcome to the NinjaTrader Support Forum!

    From your code I do not see any items you might have missed. Are there any other conditions to set the value of the plot? Does this only run on real-time data (if(Historical)return? Do you see the correct plot after one bar update? Are both conditions detailed in your post used at the same time in the code?

    I look forward to your response.

    Comment


      #3
      Hi and thank you for the quick response.

      By conditions, do you mean the options that come up when I click "Columns" in market analyzer?

      Also, where do I find "if(Historical)return"? I did not find the word "Historical" in my code.

      No, I ran the two pieces of code separately. I also just added "CalculateOnBarClose = false;" in "Initialize()".

      But why would it output a 0? I don't even have that as an option to output. I don't think it's a garbage value either because I just tried the following code by itself:

      " if (BarsInProgress == 1)
      Plot0.Set(2);

      else Plot0.Set(3);"

      and it still outputs a 0.

      Are not enough bars loaded? I have the default time period set to 5 minutes.

      Comment


        #4
        Originally posted by NinjaTrader_PatrickH View Post
        Hello TheDarg,

        Thank you for your note and welcome to the NinjaTrader Support Forum!

        From your code I do not see any items you might have missed. Are there any other conditions to set the value of the plot? Does this only run on real-time data (if(Historical)return? Do you see the correct plot after one bar update? Are both conditions detailed in your post used at the same time in the code?

        I look forward to your response.
        Don't you need to:
        Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series<T> (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for

        Comment


          #5
          Hello TheDarg,

          Thank you for your note.

          I do not believe it is because of how many bars you have loaded. Historical check (if(Historical)) can be used to ensure you only process the calculations on the real-time data and not the historical. For information on Historical please visit the following link: http://www.ninjatrader.com/support/h...historical.htm

          Can you provide your full code in the indicator or attach the indicator file to your response so I may test this item on my end?

          I look forward to your response.

          Comment


            #6
            Sure, I have attached my code. The code outputs a 0 in market analyzer. Note if I change "if (BarsInProgress == 1) " to "if (BarsInProgress == 0) " it outputs a 1.

            I also noticed if I write "if (BarsInProgress == 0)
            Plot0.Set(1);
            else Plot0.set(2)" it no longer works and outputs a 0.

            Thank you so much for the help!
            Attached Files

            Comment


              #7
              Hello TheDarg,

              Thank you for your response.

              I will review this further on my end and follow up with you here.

              Comment


                #8
                Hello TheDarg,

                Thank you for your patience.

                Please add the following check to the beginning of the OnBarUpdate() method:
                Code:
                if(CurrentBars[1] < BarsRequired || CurrentBars[0] < BarsRequired)
                				return;
                For information on CurrentBars please visit the following link: http://www.ninjatrader.com/support/h...urrentbars.htm

                Please let me know if I may be of further assistance.

                Comment


                  #9
                  Thank you! When I added those lines of code, it worked I believe. Why does it work with that? If it prints what I want it to, that means it does have enough bars loaded, correct? Then why does it not work without it? Also, what would be outputted if there were not enough bars? Garbage values?

                  Comment


                    #10
                    Hello TheDarg,

                    Thank you for your response.

                    This isn't due to how many bars you have on the chart or Market Analyzer but how many the indicator has loaded before it calculates. Using if(CurrentBar < BarsRequired) return; means the indicator will not begin to calculate until the set number of bars for BarsRequired have been loaded for the indicator.

                    For information on this matter please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3170

                    Please let me know if I may be of further assistance.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bortz, 11-06-2023, 08:04 AM
                    47 responses
                    1,603 views
                    0 likes
                    Last Post aligator  
                    Started by jaybedreamin, Today, 05:56 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post jaybedreamin  
                    Started by DJ888, 04-16-2024, 06:09 PM
                    6 responses
                    18 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by Jon17, Today, 04:33 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post Jon17
                    by Jon17
                     
                    Started by Javierw.ok, Today, 04:12 PM
                    0 responses
                    12 views
                    0 likes
                    Last Post Javierw.ok  
                    Working...
                    X