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

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​
          Brandon H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by DJ888, Yesterday, 10:57 PM
          0 responses
          6 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          158 views
          0 likes
          Last Post loganjarosz123  
          Started by Belfortbucks, Yesterday, 09:29 PM
          0 responses
          7 views
          0 likes
          Last Post Belfortbucks  
          Started by zstheorist, Yesterday, 07:52 PM
          0 responses
          7 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          151 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Working...
          X