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

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 Stanfillirenfro, Today, 07:23 AM
            4 responses
            18 views
            0 likes
            Last Post Stanfillirenfro  
            Started by DayTradingDEMON, Today, 09:28 AM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            8 responses
            31 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by helpwanted, Today, 03:06 AM
            2 responses
            22 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by navyguy06, Today, 09:28 AM
            0 responses
            6 views
            0 likes
            Last Post navyguy06  
            Working...
            X