Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Manually Moving Stops/Profit Targets set By Automated Strategy

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

    Manually Moving Stops/Profit Targets set By Automated Strategy

    I have a strategy that sets stops in the "Initialize()" section. I want to be able to manually override the settings during the trade --it keeps resetting back to the automated settings upon each bar--

    How do I keep the strategy from resetting the stops ?

    Same question for profit targets

    Thank you..
    Jim-Boulder
    NinjaTrader Ecosystem Vendor - Elephant Tracks

    #2
    Hi Jim-Boulder,

    Are you calling SetStopLoss anywhere in OnBarUpdate()?

    If so, these are likely resetting the stop loss.

    May we see the code you are using in your script?

    If so, please include this with your next post.

    If you would like to keep your code private, please send an email to support [at] ninjatrader [dot] com.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes, I am setting in the OnBarUpdate()---here's the code:

      protected override void Initialize()
      {
      Add(SampleGetHighLowByTimeRange(6, 20, 5, 20));
      Add(SampleGetHighLowByTimeRange(6, 20, 5, 20));
      // SetStopLoss("", CalculationMode.Ticks, SL, false);
      TraceOrders = true;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.UniqueEntries;
      CalculateOnBarClose = false;

      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      if ((ToTime(Time[0]) > 62000 && ToTime(Time[0]) < 150000) && !traded )
      {
      entrypriceL = SampleGetHighLowByTimeRange(6, 20, 5, 20).HighestHigh[0]+ 2 * TickSize ;
      entrypriceS = SampleGetHighLowByTimeRange(6, 20, 5, 20).LowestLow[0]+ -2 * TickSize;

      Print(ToTime(Time[0]).ToString() + "EntrypriceL: " + entrypriceL);
      Print(ToTime(Time[0]).ToString() + "EntrypriceS: " + entrypriceS);

      SneakRange = SampleGetHighLowByTimeRange(6, 20, 5, 20).HighestHigh[0] - SampleGetHighLowByTimeRange(6, 20, 5, 20).LowestLow[0];
      PT = SneakRange /TickSize;
      Print("PT: " + PT);
      // Condition set 1
      if (High[0] >= SampleGetHighLowByTimeRange(6, 20, 5, 20).HighestHigh[0]+ 2 * TickSize)
      {
      EnterLong("Long1");
      EnterLong("Long2");
      SetProfitTarget("Long1", CalculationMode.Ticks, PT);
      SetStopLoss("Long1", CalculationMode.Ticks,SL,false);
      SetStopLoss("Long2", CalculationMode.Price, IchimokuCloud(9,26,52).KijunSen[0] - 1 *TickSize, false);
      traded = true;
      Print(ToTime(Time[0]).ToString() + "Close[0] " + Close[0]);

      }

      // Condition set 2
      if (Low[0] <= SampleGetHighLowByTimeRange(6, 20, 5, 20).LowestLow[0]+ -2 * TickSize)
      {
      EnterShort("Short1");
      EnterShort("Short2");
      SetProfitTarget("Short1", CalculationMode.Ticks, PT);
      SetStopLoss("Short1", CalculationMode.Ticks,SL,false);
      SetStopLoss("Short2", CalculationMode.Price, IchimokuCloud(9,26,52).TenkanSen[0] + 1 *TickSize, false);
      traded = true;
      Print(ToTime(Time[0]).ToString() + "Close[0] " + Close[0]);
      }
      }

      if (ToTime(Time[0]) >= 163000)
      {
      traded = false;
      entrypriceL = 0;
      entrypriceS = 0;
      }

      }
      Jim-Boulder
      NinjaTrader Ecosystem Vendor - Elephant Tracks

      Comment


        #4
        Hi Jim-Boulder,

        From the code it looks like you are referring to Long2 and Short2.

        The stop loss in Initialize() has been commented out. Does this prevent the stop losses from being reset?

        If you set the stop loss for each specific entry signal name in Initialize() does this correct the issue?

        protected override void Initialize()
        {
        SetStopLoss("Long1", CalculationMode.Ticks, SL, false);
        SetStopLoss("Long2", CalculationMode.Ticks, SL, false);
        SetStopLoss("Short1", CalculationMode.Ticks, SL, false);
        SetStopLoss("Short2", CalculationMode.Ticks, SL, false);
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          This didn't stop the SL resetting upon each bar update---any other ideas?

          I have bought a strategy (but can't see the code)--that does do this (where I can move the stops and profit targets it has set)--and it works-so I know there is away to get this to happen.

          Any input you can suggest would be appreciated.
          Jim-Boulder
          NinjaTrader Ecosystem Vendor - Elephant Tracks

          Comment


            #6
            Hi Jim-Boulder,

            It may be that the condition to enter a position is being triggered on each new bar which may be resetting the stop loss.

            Try moving the stop loss to being set after the order fills in OnExecution. This would mean the only time the stop loss can be reset is when an order fills.

            You will need to detect the name of the execution and see that it has filled.

            Below is a link to a sample that demonstrates how to do this.
            http://www.ninjatrader.com/support/f...ead.php?t=7499
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I enabled the sample strategy you suggested--but I can't get it's stops and targets to display on Chart Trader--is there some way to enable that? (My chart trader is on a second chart)
              Jim-Boulder
              NinjaTrader Ecosystem Vendor - Elephant Tracks

              Comment


                #8
                I restarted NT--and it now display's the PT and SL and I can move them manually---are there any downsides of using the order handling contained in the sample strategy?
                Jim-Boulder
                NinjaTrader Ecosystem Vendor - Elephant Tracks

                Comment


                  #9
                  Hello Jim,

                  Ensure that you have the same account selected on the chart trader that you placing the orders to from the strategy.

                  Additionally, there is no downside from the sample.

                  Let me know if I can be of further assistance.
                  Cal H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  633 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  364 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  105 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  567 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  568 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X