Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop loss that is below lowest and profit target that is 1.5x the stop

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

    Stop loss that is below lowest and profit target that is 1.5x the stop

    I am trying to make a system that will create a stop loss that is say the lowest value within 10 bars from the entry and then it will calculate the difference between the entry price and stop loss and multiply that by 1.5 and place the profit target at that level

    #2
    Hello jmass13,

    Thanks for your post.

    You can use the MIN indicator with the Low PriceSeries as input to get the Lowest Low from 10 bars ago. You can save this value to a private variable for later use in the strategy.

    MIN - https://ninjatrader.com/support/help...inimum_min.htm

    Working with PriceSeries - https://ninjatrader.com/support/help...ice_series.htm

    You can then check OnOrderUpdate for when your entry order's OrderState reaches OrderState.Filled so you can check the AverageFillPrice property of the order.

    Then in OnExecutionUpdate, you can submit the stop loss with ExitLongStopMarket using the Lowest Low saved in your private variable. You can also use this variable to calculate the difference from the AverageFillPrice of your entry order, multiply it by 1.5, then use that result to submit your profit target with ExitLongLimit.

    OnOrderUpdate - https://ninjatrader.com/support/help...rderupdate.htm

    Order.AverageFillPrice is a property of Order objects. Order object documentation can be found below.

    Order objects - https://ninjatrader.com/support/help.../nt8/order.htm

    An example that uses Order objects, OnOrderUpdate, and OnExecutionUpdate can be found below.

    SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

    Let us know if you have any additional questions.

    Comment


      #3
      Thank you for the reply. I am not a very experienced programmer so a lot of this went over my head and am not sure how to do this all. what am I putting in the OnOrderUpdate to check the order state?

      Comment


        #4
        Hello jmass13,

        You could check:

        if (order.Name == "MyEntrySignalName" && order.OrderState == OrderState.Filled) to confirm the order is filled. Different OrderStates can be found in the OnOrderUpdate documentation.

        If the above approach is too complicated, you could consider using the current market price to distance the profit target instead of the average fill price of the entry order and this would work very similarly for market orders. In that case you could simply use OnBarUpdate without using OnOrderUpdate/OnExecutionUpdate, and do the following:

        1. Calculate the prices for the stop and target before submitting your entry order
        2. Call SetStopLoss and SetProfitTarget when Position.MarketPosition == MarketPosition.Flat before you submit your entry order. (Set methods prep NinjaTrader to submit target/stop upon the execution of an entry order and should be called before that entry order is submitted.)

        You can also consider using Position.AveragePrice in OnBarUpdate when you are Long to distance the profit target, but this would mean we will have to wait for the next bar to be processed to deploy the profit target.
        Last edited by NinjaTrader_Jim; 08-25-2021, 07:20 AM.

        Comment


          #5
          I have been trying to come up with alternative methods for creating stops and targets other than using moving averages. Could some one tell or show me how I could calculate a prior bars entire length (wicks included) as the measurement of distance to attach to the SetStopLoss method to create the stop distance below a long entry. For example If I were to enter a long position and one bar ago there was a real long bar then the stop for the long entry should be pretty far below the entry and vise verse if the prior bar was very short. On a time based chart the stop distance would be constantly changing and on a range chart it should always be the same distance below a long entry because range bars will all be the same lengths.

          I appreciate any help on this Thanks!

          Futures Phantom

          Comment


            #6
            Hello FuturesPhantom,

            If you want to measure the distance in ticks from the previous bars High/Low, it would be High[1] - Low[1]. This would be in points so to convert it to ticks, you can divide it by TickSize.

            (High[1] - Low[1]) / TickSize

            You can additional ticks to this result to have a greater sized stop if you wish.

            Comment


              #7
              Thanks appreciate you help!

              Future Phantom

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              20 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              119 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              63 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              41 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              45 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X