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

Multiple Timeframe Strategy not updating fast enough

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

    Multiple Timeframe Strategy not updating fast enough

    Hi,
    I am in the process of creating a strategy in strategy builder that utilizes 3 minute chart data to set a background color on the 1 minute chart. I am wanting to have the background of the 1 minute chart be a different color when the 3 minute fast MACD is rising or falling; however, there seems to be a delay of when the MACD actually starts rising/falling and when the chart actually changes colors. I am utilizing "on each tick" so that it will change colors as fast as possible, but there is like a 2 minute delay. For instance, when the 3 minute fast MACD turns up, the 1 minute chart doesn't update and change colors until about 2 minutes later. Is there a way to fix this so that the 1 minute background updates in real time? If I try to do the same thing utilizing 9 minute data, there is almost a 5 minute difference from when the 9 minute fast MACD turns up and when the background of the 1 minute chart updates. Any help is greatly appreciated. Thanks

    - Ian

    #2
    Hello Tradwell385,

    With Calculate set to .OnEachTick, this will affect all series.
    With TickReplay enabled and historical tick data available this can also work in historical data.

    Try adding a simple print above (outside) of all conditions in OnBarUpdate() to verify what data is updating.

    Print(string.Format("{0} | BarsInProgress: {1}, {2} {3} {4}", Time[0], BarsInProgress, Instrument.FullName, BarsPeriod.Value, BarsPeriod.BarsPeriodType));
    https://ninjatrader.com/support/foru...121#post791121

    Save the output to a text file and include this with your reply.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Does this require updating in coding or doing it in the strategy builder? I have no idea how to code and don't really understand what you are asking me to do. Can you clarify?

      Comment


        #4
        Hello Tradwell385,

        This particular information would not be available in the Strategy Builder and would require unlocking the script.

        In the Strategy Builder you could print the indicator values used in the conditions along with the time of the bar. But this wouldn't tell you which series are being updated in OnBarUpdate().
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          For what it's worth, I've attached a picture of what the code looks like right now.
          Attached Files

          Comment


            #6
            I've unlocked the script and tried pasting the code above, but it gave me all kinds of error messages. Where exactly in the code would I paste this info and update the information needed to just update the 3 minute data?

            Comment


              #7
              Chelsea,
              I think I figured out what you meant in the coding and I copy and pasted it but the background colors that are being printed on the 1 minute chart are still delayed by 2 minutes. Here is a copy of the code.
              Attached Files

              Comment


                #8
                Also, Attached is a picture of what I'm talking about on the chart.
                Attached Files

                Comment


                  #9
                  Hello Tradwell385,

                  Thank you for posting the code.

                  With the code you have generated by the Strategy Builder the conditions and actions will only be evaluated on the primary series.

                  if (BarsInProgress != 0)
                  return;

                  This returns out of OnBarUpdate() if the series updating OnBarUpdate() is not 0, the primary series.
                  This means the background color will be set when the primary bar updates.

                  The Calculate setting will control if the logic is evaluated when OnBarUpdate is run with .OnBarClose, .OnEachTick, or .OnPriceChange. (This is discussed in the Strategy Builder 301 training video)

                  In the Strategy Builder you could add prints (to a condition set with no conditions) to see if the conditions are evaluating as true. (See the 'Debugging using prints with the Strategy Builder' video)

                  Print the time of the bar, print TopDogMomentum1.Mom[0], print IsRising(TopDogMomentum1.Mom), print IsFalling(TopDogMomentum1.Mom).

                  In an unlocked script this would print would appear as:
                  Print(string.Format("{0} | TopDogMomentum1.Mom[0]: {1}, IsRising(TopDogMomentum1.Mom): {2}, IsFalling(TopDogMomentum1.Mom)))

                  This would let you know on each bar whether or not the condition will be true, and when the background color will be set.

                  Below I am also including a link to a forum post with helpful information about getting started with NinjaScript that includes a link to the Strategy Builder 301 training video.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    To clarify, would I delete the Bars in Progress code and replace it with that code?

                    Comment


                      #11
                      Hello Tradwell385,

                      No code would be deleted to add prints for understanding behavior.

                      The prints would be above the conditions you are needing to see the values for in an unlocked script.

                      In the Strategy Builder the print actions would be in a separate condition set with no conditions (so it prints for every bar).


                      Are you trying to evaluate code on another series?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        I am trying to have the data from a 3 minute chart print correctly on a 1 min chart. For some reason a 3 minute indicator works perfectly fine on a 1 minute chart, but having the background of the 1 minute chart print colors when the 3 minute indicator moves is lagging. I have no idea why this happens and it is very very frustrating

                        Comment


                          #13
                          Hello Tradwell385,

                          If you are wanting to plot a higher time frame on a lower time frame primary, you will need to set the empty bars to the previous bars value.

                          Below is a link to an example of plotting a higher time frame onto a lower time frame.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Chelsea, I don't need to plot an indicator from a higher timeframe, I already know how to do that. I'm trying to plot the background of the 1 minute chart BASED on the INDICATOR of a higher timeframe WITHOUT a lag in time from when the indicator changes values and when the background plot changes. There is a 2 minute lag from when the indicator changes and the background changes. Nothing that you have sent me has worked so far.

                            Comment


                              #15
                              Hello Tradwell385,

                              Set the BackBrush when the bars in progress of that series is updating the indicator value that changing, to set color when the series updates.

                              If indicator is updating with an input series of BarsArray[1], then set the background color when BarsInProgress 1 is updating.

                              Use prints to understand the behavior.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by nandhumca, Today, 03:41 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post nandhumca  
                              Started by The_Sec, Today, 03:37 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post The_Sec
                              by The_Sec
                               
                              Started by GwFutures1988, Today, 02:48 PM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by ScottWalsh, 04-16-2024, 04:29 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by frankthearm, Today, 09:08 AM
                              10 responses
                              36 views
                              0 likes
                              Last Post frankthearm  
                              Working...
                              X