Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Checking Accuracy of my Custom Variables

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

    Checking Accuracy of my Custom Variables

    As I appraoch a full config of my strategies and variables, I want to test the values over a couple of days and make sure that they are pulling the correct market data.

    Example, if I want to backtest yesterday's high in AAPL, i simply code:

    protectedoverridevoid Initialize()
    {

    Add(PeriodType.Minute,
    1); // Index 1
    Add(PeriodType.Day, 1); // Index 2
    CalculateOnBarClose = true;

    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()

    {
    if (BarsInProgress == 2) // Do something with day bars
    {

    Print(Highs [
    2][0]);

    }
    }

    using AAPL as my instrument from the backltest menu;

    When this works I get 5 days of data to print to the output window instead of instead of simply yesterday's close which was 325.80...what am I doing wrong?

    Thanks in advance.

    #2
    alabell,

    I'm not sure if anything is wrong. When the script is run, it processes all historical bars. It's expected that you will get output for each historical bar.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      but when I request only 6/21-6/22 or 6/20-6/22 or some varitation therof, i get no output at all...if i go back 6 weeks, then i get output data. how would ask the backtester to "print yesterday's high" only"?

      regards.

      Comment


        #4
        The minimum bars required setting must be satisfied for all series. If you have this set to 20, then the strategy will not start processing until after 20 days.

        To print yesterday's high only requires custom programming, working with date/ time objects. Instead of going this route, maybe consider printing the time stamp associated with the bars to identify.

        If you're using a BarsInProgress filter you don't have to also use Highs[][] Times[], etc. These are used when you need to access these values from another BIP.

        if (BarsInProgress == 2) // Do something with day bars
        {

        Print(Time[0] + " " + High[0]);

        }
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          At what time does kinetic update its day bars (i have a subscription)...is it in real time? or somewhat later than market close ?

          I am trying to an sma(10) of the AAPL close and instead of averaging days 1-10 (including today) it is averaging days 2-11 (as if yesterday were day one).

          I am currently considering today's 4PM close to be [0] so i am looking to average [0]-[9].

          Comment


            #6
            Subscript Kinetick daily bars are updated in real time. This is not related to Kinetick updating.

            In a backtest, bars are only processed on bar close. A bar isn't considered closed until the next one begins. You do not then have access to the last daily bar in a backtesting.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              thank you ryan; so basically what this means is:

              -- if i am using a [10 day sma of closing prices] as a component of a strategy in live trading, it will refer to yesterday's close and the nine prior days;

              however,

              -- if i am backtesting and I want to make sure the methods in my strat are coded correctly then I should use the value of the SMA excluding yesterday, in other words;

              if yesterday were day[0],

              my backtest SMA(10) would calculate the average of days [1] through [10].

              If I am understanding this correctly then I am happy with my progress so far.

              Regards.

              Comment


                #8
                In live trading with CalculateOnbarClose = false, it will process for the latest daily bar. The sma 10 includes the most recent bar, and the prior 9 bars in its calculation.

                In backtesting, the latest SMA value you can access is the last "closed" bar, which is not the last visible bar. Admittedly a bit confusing so please let me know if I can offer additional clarification here.
                Ryan M.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                649 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                370 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                109 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                573 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                576 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X