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-Time Frame index [0] is not current for the larger timeframe

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

    Multi-Time Frame index [0] is not current for the larger timeframe

    I am trying to create an multi-time frame intraday indicator that also includes results from a daily indicator:

    class IndicatorAbc

    Initialize()
    {
    CalculateOnBarClose = false;
    ...
    if (BarsPeriod.Id == PeriodType.Minute)
    Add(PeriodType.Day, 1);
    }

    OnBarUpdate()
    {
    if (BarsInProgress == 0 && CurrentBars[0] >= 2) // if working on intraday, add daily info
    {
    double todaysSignalSoFar = IndicatorAbc(BarsArray[1]).SomeSignal[0]; // daily signal (so far)
    double previousLow = Low[1][1]; // previous daily low
    }
    }

    However todaysSignalSoFar is showing yesterday's EOD signal.
    And previousLow is actually showing the low from 2 days ago.

    Something odd also happens if I access Low[1][0] as it also shows the previous day's low rather than the current low. CalculateOnBarClose = false for both.

    Currently this to chart historical but was planning to use within a strategy and for live charting. I suspect the index values will change with the switch to live charting but I wish the live vs historical to behave consistently for index[0].

    Is there a way to to make BarsArray[1][0] contain the current day's value recalculated at the current intraday point?

    Thanks,
    Chris

    #2
    Chris,

    Thank you for your note.

    Are there any errors in the Log Tab of the Control Center when running this indicator?

    I got an over indexed error and changed the script to include at least one day for the CurrentBars[1] as well in the check and are getting the correct results.

    if (BarsInProgress == 0 && CurrentBars[0] >= 2 && CurrentBars[1] > 1)
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Yes, there was a couple errors so a complete example has been attached.

      The expectation is that the blue and red lines should be tracking the current day rather than the previous.
      Attached Files
      Last edited by crokusek; 11-20-2014, 01:31 AM.

      Comment


        #4
        Chris,

        What are the errors in your log tab?
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Hi,

          I just updated the attachment of the previous reply, there should now be no errors if you download and run it. There is also a picture attached to this message showing the issue.

          The Left side is daily, Right side is 15min for same period. The red and blue lines are showing the previous low and signal rather than the current day's low and signal (which should be changing throughout each day).

          Focusing on 12/30 the daily low is ~14 but on the 15min chart the red line is ~14.68 (the previous day's low).

          If you run the IndicatorAbc attached to the prior email, do you see the same effect? I am running this off hours on historical data.

          Thanks,
          Chris
          Attached Files
          Last edited by crokusek; 11-20-2014, 01:34 AM.

          Comment


            #6
            Chris,

            This line -
            DailyLow0.Set(BarsArray[1][0]);

            Is returning the Close price. If you want the low of the day bar, try using this instead -

            DailyLow0.Set(Lows[1][0])
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Good correction but its really the same problem as the Lows[1][0] is showing the prior day's low.

              Comment


                #8
                Chris,

                Correct, this will continue to happen until the live data starts coming in.

                This is because the historical data is being calculated as COBC = True; meaning that the day bar won't be closed for the current day to get the intra-day close until you get live data coming in.

                What it sounds like you are wanting is a combination of the PriorDayOHLC and CurrentDayOHL indicators mashed together. Is that correct?
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Geez, the claim about COBC=true not being supported for historical is the first sentence of the help guide for CalculateOnBarClose.

                  Well hopefully mode=true for historical can make it into the core someday. For now I will try to insert and update the last bar manually from the smaller time frame into the larger.

                  Thanks for your help,
                  Chris

                  Comment


                    #10
                    Originally posted by crokusek View Post
                    Yes, there was a couple errors so a complete example has been attached.

                    The expectation is that the blue and red lines should be tracking the current day rather than the previous.
                    IndicatorABC is called from within itself. This is dirty code and should not run correctly.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by andrewtrades, Today, 04:57 PM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by chbruno, Today, 04:10 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post chbruno
                    by chbruno
                     
                    Started by josh18955, 03-25-2023, 11:16 AM
                    6 responses
                    436 views
                    0 likes
                    Last Post Delerium  
                    Started by FAQtrader, Today, 03:35 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post FAQtrader  
                    Started by rocketman7, Today, 09:41 AM
                    5 responses
                    19 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X