Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Separating open and close conditions

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

    Separating open and close conditions

    Hello,

    I'm trying to code a strategy that enters a position at bar close, but exits off of a tick based profit target. However, it appears the strategy itself only evaluates the profit target condition at the bar close instead of right after the position is opened. How would I go about splitting the conditions between the two?

    #2
    SetProfitTarget(CalculationMode.Ticks, 10);
    EnterLong();

    Or, you could use ExitLongLimit() but that would work better after you know the fill price you will receive.

    If you are entering with a limit order, you could presume you will be filled at or about the limit price and go ahead and put the ExitLongLimit in there.

    NinjaTrader won't actually put those exit orders in the market until you get a fill because it understands they are exits.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Thank you. In addition, how do I go about creating and using delta as a variable in the system? I see that NinjaTrader has OrderFlowCumulative Delta, but I'm looking for the delta on a bar by bar basis.

      Comment


        #4
        This is all in the documentation - for instance: https://ninjatrader.com/support/help...ive_delta2.htm
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Hello rsz16,

          Thanks for your post.

          "I'm trying to code a strategy that enters a position at bar close, but exits off of a tick based profit target."

          Logic can be separated between Calculate.OnEachTick and Calculate.OnBarClose using IsFirstTickOfBar. Please note that a hosted script will inherit the Calculate mode of the script that hosts it. You can take the following approach to differentiate logic between OnBarClose and OnEachTick processing.

          Note that you should use Exit methods, such as ExitLongLimit()/ExitLongStopLimit(), if you separate the logic between OnBarClose and OnEachTick processing.

          Please see this reference sample which demonstrates a technique used for those who need to separate their logic to calculate some values on each tick and others only on the close of a bar. You will set your host script to Calculate.OnEachTick and use if(IsFirstTickOfBar) and place all code that needs to calculate once every bar within that condition check. Then place all code that you want to calculate OnEachTick outside of the IsFirstTickOfBar condition check.

          SampleEnterOnceExitEveryTick -https://ninjatrader.com/support/help...either_cal.htm

          In regard to accessing Order Flow Cumulative Delta values in a NinjaScript, please see the sample code in the help guide page: https://ninjatrader.com/support/help...ta2.htm​
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          566 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          330 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          547 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          548 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X