Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Test if a custom method is FALSE for a certain number of bars

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

    Test if a custom method is FALSE for a certain number of bars

    Is there a concise way to check if a custom method is FALSE for the previous XX bars in a multi-time frame strategy?

    I am going create a parameter to alter the amount of bars tested (XX), as needed.

    Thanks in advance!

    #2
    Hello ArmKnuckle,

    You could run the method for each bar and save the true or false value to a bool series.


    Alternatively, you could write the method to accept a bars ago value and use this for any series indexes used in the method.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Great. Thanks!

      Comment


        #4
        I have created the Series<T> as you instructed. It works partially, and I need some help.

        If I use the Series<T> bool from the current bar, I get functioning results:

        Code:
        if ([COLOR=#008000][B]CodeLongOK[0][/B][/COLOR] && SavedBar != CurrentBars[0])
        {
          SavedBar = CurrentBars[0];
          Print (Instrument.FullName + " "+Times[0][AZ+0].ToString("MM/dd/yy  HH:mm:ss")+"  "+CodeLongOK[1]);
        }
        The printout references that correct information from the Series<T> bool from one bar ago.


        When I try to use the Series<T> bool from one bar ago to generate the print statement:

        Code:
        if ([COLOR=#FF0000][B]CodeLongOK[1][/B][/COLOR] && SavedBar != CurrentBars[0])
        {
          SavedBar = CurrentBars[0];
          Print (Instrument.FullName + "  "+Times[0][AZ+0].ToString("MM/dd/yy  HH:mm:ss")+"  "+CodeLongOK[1]);
        }
        I get the following error message:
        "Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

        The correct bool data from one bar ago exists in the logic and is available to print.

        How can I use the Series<T> bool from previous bars in an "if ()" statement to print, iterate counters, etc?

        Thanks for the help.
        Last edited by ArmKnuckle; 05-20-2019, 04:21 AM.

        Comment


          #5
          Hello ArmKnuckle,

          Is CurrentBar greater than 1 when attempting to call 1 bar ago?

          Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Code:
             
             [B][B][COLOR=#0000FF]if (CodeLongOK.Count > 1) [/COLOR]Print (Instrument.FullName + "  "+Times[0][AZ+0].ToString("MM/dd/yy  HH:mm:ss")+"  "+CodeLongOK[1]);[/B][/B]
            You could also use IsValidDataPoint() as a check filter. ref: https://ninjatrader.com/support/help...ddatapoint.htm

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            56 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            132 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            73 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            45 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            49 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X