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

Can Strategy Builder Enter on Tick Change but Exit on Bar Close?

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

    Can Strategy Builder Enter on Tick Change but Exit on Bar Close?

    I have an EMA crossover strategy built using the condition builder.

    It gets better entries when calculating each tick but better exits when using calculate on bar close.

    My question is, is there a way to combine the two methods on the same strategy?

    For example, can I set it to calculate on each tick but add some logic that waits after the exit condition is triggered until the bar closes and then checks if the condition still exists,

    or better yet, only checks for the exit condition on the bar close?

    Appreciate your help on this,
    Last edited by anotherone1; 04-14-2023, 05:16 PM.

    #2
    Hello anotherone1,

    In the Strategy Builder, it is possible to set Calculate to OnEachTick, and then in some conditions require Misc -> IsFirstTickOfBar to be true to trigger actions when the bar closes.

    That said, the Strategy Builder cannot implement 1-tick intra-bar granularity, so in historical even with TickReplay orders will be filled with end of bar information.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello anotherone1,

      In the Strategy Builder, it is possible to set Calculate to OnEachTick, and then in some conditions require Misc -> IsFirstTickOfBar to be true to trigger actions when the bar closes.

      That said, the Strategy Builder cannot implement 1-tick intra-bar granularity, so in historical even with TickReplay orders will be filled with end of bar information.
      https://ninjatrader.com/support/foru...377#post773377
      Thanks for this suggestion; it seems to work but still needs improvement.

      What I need is for the condition to be true on this bar and then STILL be true on the close of the bar, or for our purposes, the first tick of the next bar.

      With this update, it's only checking if the condition is true on the first tick of the bar and then exits, even if the condition wasn't true at the close of the previous bar, or at the close of the next bar




      Last edited by anotherone1; 04-18-2023, 09:11 AM.

      Comment


        #4
        Hello anotherone1,

        In real-time with Calculate.OnEachTick, IsFirstTickOfBar will only be true on the first tick of a new bar, which is when the previous bar closes. Meaning, the first tick of the new bar is what closes the previous bar.

        When Calculate is OnBarClose, the most recently updated bar, barsAgo [0], is the most recently fully closed bar.
        When Calculate is OnEachTick, the most recently updated bar, barsAgo [0], is the currently building unclosed bar. The most recently fully closed bar is [1] barAgo.

        See the help guide on how bar information is accessed.



        If your condition is true 1 bar ago, use 1 as the barsAgo indexes in the conditions.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Example with EMA crossover

          I went long on EMA crossover, and now EMA crosses under on a 5m bar. so if we calculate each tick, it will exit as soon as crossunder happens. However, I want it to wait until the bar closes, and then check if fast ema is still below slow EMA.

          So I should change this to 1 instead of 0, and then it will work oven with Calculate is OnEachTick?

          Click image for larger version

Name:	image.png
Views:	140
Size:	78.5 KB
ID:	1246940

          ​​

          Comment


            #6
            Hello anotherone1,

            Unfortunately, CrossAbove / CrossBelow do not work with barsAgo values.

            Instead you will need two conditions in the set. One condition where the EMA with BarsAgo 2 is greater than EMA with BarsAgo 2, and the other where EMA with BarsAgo 1 is less than EMA with BarsAgo 1. (Meaning it was greater than 2 closed bars ago, and is less than 1 closed bar ago)
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by geddyisodin, 04-25-2024, 05:20 AM
            8 responses
            60 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            4 responses
            3,285 views
            1 like
            Last Post jgualdronc  
            Started by Option Whisperer, Today, 09:55 AM
            0 responses
            5 views
            0 likes
            Last Post Option Whisperer  
            Started by halgo_boulder, 04-20-2024, 08:44 AM
            2 responses
            22 views
            0 likes
            Last Post halgo_boulder  
            Started by mishhh, 05-25-2010, 08:54 AM
            19 responses
            6,189 views
            0 likes
            Last Post rene69851  
            Working...
            X