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

How to include Friday's daily data within backtest without waiting until Monday

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

    How to include Friday's daily data within backtest without waiting until Monday

    I'm aiming to run back tests each evening to identify which stocks to trade intraday on the following trading day. For example, backtesting the 500 component stocks within the S&P500 to see which ones are trading near their 52wk high, and which have had 3 days of green candles. In essence its preparation for the next day. To do this, I choose Daily data and backtest over the last 180 days.

    Let's say I wanted to to this right now (10pm on Friday 25th Nov 2022), and include the data from today (11/25/22) so I'm lined up ready for Monday morning. Using OnBarClose, I understand that todays bar (even though I can see data on my chart for today 11/25/22) isn't available to the backtest until it is closed by the next days bar opening on Monday.

    If I do OnPriceChange, then presumably my bars might get messed up if the OHLC is the same in consecutive days (maybe trivial), but am I correct in thinking that even if the price changed today vs yesterday (11/25 vs 11/23, skipping thanksgiving) I still won't get Friday's Daily bar formed until Monday morning?

    If so, is there any way of achieving the desired goal outlined above of being able to do evening prep that includes todays data within it? (I can't add an additional minute data series because running over 180 days would take too long).

    Many thanks in advance

    ChainsawDR

    #2
    Hello ChainsawDR,

    Thanks for your post.

    You are correct. Backtests will calculate values with Calculate.OnBarClose so the data for a Daily bar on Friday wouldn't be available until that bar closes.

    When in historical data, only the Open, High, Low, and Close will be available and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the known information.

    Please review the help guide document on the differences on real-time vs backtest (historical).
    http://ninjatrader.com/support/helpG...ime_vs_bac.htm

    To access the values of a bar before the bar closes, you would have to add an additional data series, such as a 1-Minute series, as you have mentioned as well as use Tick Replay. Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data. Then, you could access values from that added data series.

    ​TickReplay — https://ninjatrader.com/support/help...ick_replay.htm

    Developing for Tick Replay -
    https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm?zoom_highlightsub= developing+for+tick+replay

    Additional information may be found in this NinjaTrader Forum post —
    https://ninjatrader.com/support/foru...mance?t=102504

    Please let us know if we may be of further assistance to you.​
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thank you Brandon. Given the timeframe needed to form 52wk highs & lows, it unfortunately rules out adding an additional timeseries like 1-mins - unless you know of any methods of only adding the additional 1-min timeseries for the last X days? (e.g. run 365 days of 1 day data, but then run only the last day of 1-min data)

      With the same objective of being able to run daily prep in mind, I'm wondering if you know if there is a way of tricking the system into closing the bar early? For example, I'm wondering whether on Friday evening (11/25) I can import in fake data for the coming Monday (11/28) so that the Fri 11/25 bar is closed - please let me know if you have any thoughts on this

      Comment


        #4
        Hello ChainsawDR,

        Thanks for your note.

        Unfortunately, when adding an additional data series to a script, there are no properties or arguments that would allow you to specify x number of days to add for that additional series.

        AddDataSeries: https://ninjatrader.com/support/help...dataseries.htm

        There is no supported or documented workaround for 'tricking the system into closing the bar early'.

        Let me know if you have further questions.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by lightsun47, Today, 03:51 PM
        0 responses
        4 views
        0 likes
        Last Post lightsun47  
        Started by 00nevest, Today, 02:27 PM
        1 response
        8 views
        0 likes
        Last Post 00nevest  
        Started by futtrader, 04-21-2024, 01:50 AM
        4 responses
        44 views
        0 likes
        Last Post futtrader  
        Started by Option Whisperer, Today, 09:55 AM
        1 response
        13 views
        0 likes
        Last Post bltdavid  
        Started by port119, Today, 02:43 PM
        0 responses
        9 views
        0 likes
        Last Post port119
        by port119
         
        Working...
        X