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

Struggles with Intrabar Backtesting in more granular resolution

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

    Struggles with Intrabar Backtesting in more granular resolution

    Hello everybody,

    actually i am working on own Strategies with Strategy Builder. At the moment i am fine with the possibilities the Strategy Builder supplies, but I want to backtest my strategy intrabar. For that reason I read the already existing topics and helpguides.
    Unfortunately I have no programming skills, so I have to ask very basic questions. My main goal is just to unlock a strategy and modifiy it for intrabar backtesting.

    First topic:
    For understanding issues I downloaded the sample strategy (for NT8). I backtested it and there were no intrabar fills. I looked a longer period back, there were not a single one. (see attached picture)
    Is there a general setting I have to change? I haven’t changed the code, so I am a bit irritated. I also used as primary data series the recommended 5 min Chart.
    I tested it with and without tick replay enabled.
    Order fill resolution = high causes an error.


    Strategy: Backtesting NinjaScript Strategies with an intrabar granularity - NinjaTrader Support Forum

    Nontheless i read the code and tried to understand it. So there are more questions about outtakes of that code.


    2)

    Code:
    AddDataSeries(Data.BarsPeriodType.Minute, 1);
    If i find that AddDataSeries in a Code, it will never be the primary data series? In other words are these just optional data series? Will be the primary data series always be the one I enter in the strategy analyser or in Chart / instrument directly?


    3)
    Code:
    Calculate = Calculate.OnBarClose;
    So I don´t need calculation on each tick, because it calculates on every close of 1 min bar? Is this thought correct? Do I have to set tick replay in strategy analyser or is that not necessary?


    4)
    Code:
    [FONT=Calibri][COLOR=black]protected override void OnBarUpdate()[/COLOR][/FONT]
    [FONT=Calibri][COLOR=black]{[/COLOR][/FONT]
    [FONT=Calibri][COLOR=black]if (BarsInProgress == 0)[/COLOR][/FONT]
    [FONT=Calibri][COLOR=black]{[/COLOR][/FONT]
    [FONT=Calibri][COLOR=black]if (CrossAbove(EMA(Fast), EMA(Slow), 1))[/COLOR][/FONT]
    
    [FONT=Calibri][COLOR=black]EnterLong(1, 1, "Long: 1min");[/COLOR][/FONT]
    [FONT=Calibri][COLOR=black]}[/COLOR][/FONT]
    So BarsInProgress == 0 means the script is only proceeding at Data series equals 0, what would be the primary 5 min Chart? If this is correct, how will the EnterLong order with Data series 1 ever get a intrabar signal / or get the Data series 1? Wouldn’t filter BarsInProgress every shorter series than primary?


    5) A question to a unlocked Script of Strategy builder:
    This part

    Code:
    protected override void OnBarUpdate()
    Code:
    [FONT=Calibri][COLOR=black]{[/COLOR][/FONT]
    
    
    [FONT=Calibri][COLOR=black]if (BarsInProgress != [/COLOR][COLOR=black]0)[/COLOR][/FONT]
    [FONT=Calibri][COLOR=black]return;[/COLOR][/FONT]
    
    [FONT=Calibri][COLOR=black]if (CurrentBars[0] < 1)[/COLOR][/FONT]
    [FONT=Calibri][COLOR=black]return;[/COLOR][/FONT]


    is contained in unlocked strategies. In my mind the BarsInProgress sections of Question 4 and 5 have both the same impact? Is this correct?
    And the CurrentBars[0] < 1 is completely missing in Question 4 / Script of the backtest sample. Whats exact the function of this part?

    I read the help for currentbar but I am not really sure whats the reason I need this piece of code. If I understand it the right way, the script only continues, if the currentBar is greaterequal 1.
    But the very first bar in chart eqals 0. Is this just a filter to start not on the first bar but on the second? (If yes, whats the reason)


    Again, I have no programming skills at all and it is really hard to understand the logic if you don’t know where to start.
    As you cleary can see, I have struggles to get started and I would be glad about every help I get!
    Thank you in advice!


    #2
    Hello ,

    If you want to submit orders intra-bar, the Calculate setting can be set to OnEachTick or OnPriceChange.
    https://ninjatrader.com/support/help.../calculate.htm

    The orders would be submitted intra-bar, but would fill at the bar close.

    In historical data, TickReplay will need to be enabled to submit orders intra-bar.
    https://ninjatrader.com/support/help...ick_replay.htm

    For orders to fill intra-bar with a strategy created with the Strategy Builder, High Order fill resolution is needed, but this does not work with TickReplay at the same time.
    Unfortunately, this would mean the script would need to be unlocked, a 1 tick series added, the orders submitted with 1 as the Bars series index.
    https://ninjatrader.com/support/foru...377#post773377

    When calling an entry method, a Bars series index is supplied to the entry method. This is used to submit the order to a specific bar series for fill prices. It does not matter which series is updating OnBarUpdate(), the order will always be submitted to the bars series you have specified.

    if (CurrentBars[1] < 1) return; is used to delay processing data in OnBarUpdate until the second series has two bars. This is typically to prevent invalid indexes.

    As an example if CurrentBars[1] was 0, and you call Closes[1][1], this would result in a run-time error of an invalid index and the script would be disabled.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your Help!
      You improved my understanding.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by alifarahani, Today, 09:40 AM
      3 responses
      15 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by RookieTrader, Today, 09:37 AM
      4 responses
      18 views
      0 likes
      Last Post RookieTrader  
      Started by PaulMohn, Today, 12:36 PM
      0 responses
      5 views
      0 likes
      Last Post PaulMohn  
      Started by love2code2trade, 04-17-2024, 01:45 PM
      4 responses
      40 views
      0 likes
      Last Post love2code2trade  
      Started by junkone, Today, 11:37 AM
      3 responses
      26 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X