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

Using an indicator to exit positions

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

    Using an indicator to exit positions

    Hi,

    My current strategy has a calculated entry, which attaches a fixed profit target and stop loss. I want to change this to use an indicator to exit an active trade.

    That being said, so I rewrote my strategy that still uses the same entry conditions, calculate the entry and stop loss. I am now stuck on how to add an indicator to exit the position when a certain condition is met.

    For instance, let's say I enter a long trade at X price. The order is filled and attaches my calculated stop loss as an OCO. Now let's say price rallies up and close outside of a channel, I want to use that indicator to exit the trade and cancel the OCO order to flatten the position. Secondly, let's say price retraces under a MA the I also want to exit the trade and cancel all other attached orders.

    Is this possible through the builder or what will the code look like in the script editor?

    thanks

    #2
    Hello Induna,

    You can set the stop or limit price of an exit order to an indicator.

    You would want to first check that the indicator price is valid for the order type and side of the market. (Meaning above or below the ask or bid as appropriate)

    This would be possible with the strategy builder by clicking set in the Stop or Limit price of an exit order and selecting the indicator. This would not be possible using the stop loss and profit targets on the last page in the strategy builder as these are not updated dynamically.

    True OCO is not possible in the strategy builder and would require unlocking the script, but NinjaTrader will send cancellation orders for any orders attached to a position and the position closes.

    Exit orders submitted by the strategy will automatically be cancelled if they are not called on each new bar as they will be submitted without using isLiveUntilCancelled as true.

    Below is a link to an example script that sets the price of an exit order created with the strategy builder.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Let me rephrase, I want to exit a position for instance when the double stochastic crosses above its oversold line. I do not want to look at price at this moment when closing the position. I want to close a position when an indicator is above or below a specified parameter, not the price. Another example is I maybe want to close the position when the Keltner Channel closes above the upper line of the channel for a long position.

      On the ExitLong method I can only specify price, and this is not what i want to do. If this cannot be done, how can I do it by unlocking the code? Typically what will the code be for this method?

      Comment


        #4
        I found the answer to my own question... I just had to create additional sets in the builder and then add the conditions and then an exit action, based upon those conditions.

        Thanks

        Comment


          #5
          Hello Induna,

          The exit long position is a market order which does not accept a price (as it fills immediately at market price), and you can send this in a condition set with conditions for a Keltner Channel Midline being greater than the Keltner Channel Upper.

          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by briansaul, Today, 05:31 AM
          0 responses
          1 view
          0 likes
          Last Post briansaul  
          Started by fwendolynlpxz, Today, 05:19 AM
          0 responses
          4 views
          0 likes
          Last Post fwendolynlpxz  
          Started by traderqz, Yesterday, 12:06 AM
          11 responses
          28 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by PaulMohn, Today, 03:49 AM
          0 responses
          8 views
          0 likes
          Last Post PaulMohn  
          Started by inanazsocial, Today, 01:15 AM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Jason  
          Working...
          X