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

strat builder limit exit condition

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

    strat builder limit exit condition

    my on bar close long strategy has a stopLoss and a profit Target. However, if price starts to weaken and a bar crosses and closes below a specific sma, I would like to replace my original profit target with one x ticks relative to that sma or the bar that opened above it and closed below it. How might this be built?

    is this possible in an "on bar close" environment or do I need to replace that profit target relative to the bar(s) which preceded the cross below the sma? or are both possible depending on whether i add a data series to accomodate the sma's integer-converted value?

    basically, say i'm in a good long trade in an "on bar close" environment, but that sma is my line in the sand and i want out if we close a bar below it. I DON'T want to exit at the market if I get a close below that sma, because I'll get a terrible fill. Instead, I'd like to hold tight, but move my profit target x ticks above the sma or or at some price relative to that bar that closed below it. It has to be a limit order above the action.

    thanks,
    David
    Last edited by trader3000a; 10-13-2021, 06:20 PM.

    #2
    Hello David,

    Thanks for your post.

    The SetStopLoss and SetProfitTarget are not dynamically adjustable in the Strategy Builder. If you wish to use those methods in that manner you would need to unlock your strategy builder strategy and work directly in Ninjascript.

    Otherwise, to stay within the Strategy Builder you have to remove the Set methods and replace them with Limit and stopLimit type orders. These orders can be adjusted as you wish. However, as these are limit-type orders, in the strategy builder, these orders will automatically be canceled if not filled on the bar they are placed. That means your logic has to continue to resubmit them until they are filled or the position is closed.

    Moving a limit or a stop limit type order in an OnBarClose type strategy can be done, however, your logic would need to do a check of the current ask/bid price to make sure the order is only moved if it is an appropriate move (correct side) as otherwise you risk moving an order and generating an error that will disable your strategy.

    For an example of moving an order, please see these two examples: https://ninjatrader.com/support/foru...der#post806596

    The strategy builder is a confining environment to program your specified logic in and you may have a difficult time achieving your goals. If you would like a strategy created for you, we can provide a link to 3rd party programmers that can create a strategy that meets your specifications.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul, this is a great reply, thanks. In those example strategies that you recommended, is there a way, illustrated within the builder, to keep that limit order alive if it's not filled on that candle?

      Comment


        #4
        Hello David,

        Thanks for your reply.

        Yes, in both examples note the logic used to basically resubmit the orders.

        I've attached another example that may be clearer. It uses a limit type order (EnterLongStopMarket) to enter a long trade and then uses ExitLongLimit for the profit and ExitLomngStopMarket for the stop.

        In Set 1 is the entry conditions of a moving average cross and the market position is flat. When that occurs the intended entry price is saved, the stop price is saved, an arrow is drawn and the bar number is saved.

        In Set 2, the conditions are that the position is flat, that the entry price is NOT 0, and that the signal bar is the same as the current bar (so that this order is only submitted once and must be filled on that next bar). The set submits the entry order at the entry price and draws a dot. Note that If the entry order is not filled on the next bar, the entry order is automatically canceled, this would be indicated by an arrow/dot but no order filled on the next bar.

        In Set 3, The only condition is the position is long (meaning the entry order has been filled). The actions are to submit the profit order (based on the actual entry price + 4 ticks) and submit the stop order based on the previously saved stop price and finally resetting the entryprice variable back to 0 for the next entry.

        Please note that like all our examples this is for educational reference only and is not intended to be anything but an educational reference to test on a sim101 account to demonstrate the concepts of maintaining limit type orders and the use of drawing objects to show when condition sets are true.

        ExampleLimitEntryandStopProfit.zip

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          amazing, thank you

          Comment


            #6
            Hi Paul, I'm running the sample to learn how it works, and I'm getting an unexpected behavior, so i just wanted to check with you in case I didn't read correctly. I ran it on a one minute chart, and when the cross happened, instead of placing the stop market entryat the high of [0] + 2 ticks on the 1 minute chart, it placed it at the high of [0] + 2 ticks on the 5 minute chart instead. I didn't get any drawings/dots... thanks!
            Attached Files

            Comment


              #7
              Hello David,

              Thanks for your reply.

              Not sure what you have going on there.

              Please create a new 1 minute (not heiken-ashi) chart of ES 12-21 and do not use a chart template, so this should be a basic 1 minute 5-day chart of ES 12-21.

              If you want to see the live orders generated by the strategy, enable the chart trader on that chart.

              Apply the strategy to just that chart and enable the strategy.

              Once enabled, look back through the history of the chart to see the historical orders.

              Note: If you have other strategies or are manually trading on ES 12-21, then please choose another instrument that is not currently being traded.


              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by cre8able, Today, 03:20 PM
              0 responses
              5 views
              0 likes
              Last Post cre8able  
              Started by Fran888, 02-16-2024, 10:48 AM
              3 responses
              47 views
              0 likes
              Last Post Sam2515
              by Sam2515
               
              Started by martin70, 03-24-2023, 04:58 AM
              15 responses
              114 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by The_Sec, Today, 02:29 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by jeronymite, 04-12-2024, 04:26 PM
              2 responses
              31 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Working...
              X