Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss is not dynamic ?

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

    SetStopLoss is not dynamic ?

    Hi

    i would like to move my setstoploss like a trailing stop... but it is not working, here my code, can you help to return my setstoploss dynamic ? the stop loss is not moving

    if (here my buying condition)


    {
    EnterLongLimit(1, Close[0], "divergence haussiere 1");

    SetStopLoss(
    "divergence haussiere 1", CalculationMode.Price, Low[1] - 1*TickSize, false);

    SetProfitTarget (
    "divergence haussiere 1", CalculationMode.Ticks, 200*ATR(atr)[0]);

    }



    if (Position.MarketPosition == MarketPosition.Long && High[0] >= (Position.AvgPrice + 200*ATR(atr)[0] - 2*TickSize))


    {
    // Modifies stop-loss to breakeven + 2TickSize
    ExitLongStop(0, true, 1, Position.AvgPrice+2*TickSize, "Trailing Stop div haussiere 1", "divergence haussiere 1");

    }

    #2
    Thomas,

    From my understanding of your code, your stop loss would only be set if your buying conditions are set. You would need to update the stop loss if you are in a position here.

    Here is a reference sample you may find helpful : http://www.ninjatrader.com/support/f...ead.php?t=3222
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hi Adam_P

      thx for your reply, i read your reference, i did it but it doesn't like when i call on the Initialies() these Set orders:

      protectedoverridevoid Initialize()
      {
      CalculateOnBarClose =
      true;

      Add(RSI(14, 3));
      Add (ATR(10));

      SetStopLoss(CalculationMode.Price, Low[
      1] - TickSize);
      SetProfitTarget (CalculationMode.Ticks,
      2*ATR(10)[0]);

      }

      I mean when i remove the "- TickSize" from the SetStopLoss and the "2*ATR(10)[0]" from the SetProfit and i replace for example by 40 (like 40 Ticks) that works... but i would like to call the stop Low[1]-TickSize and call the value of the ATR indicator as a tick value target...

      can you help ?

      Comment


        #4
        Thomas,

        The Initialize() section is where you set an initial stop based usually on some static value, indicator calculations aren't available there yet. You would want to call both of these in your OnBarUpdate() method instead.

        Perhaps something like :

        if ( Position.MarketPosition == MarketPosition.Long)
        {
        SetStopLoss(CalculationMode.Price, Low[1] - TickSize);
        SetProfitTarget (CalculationMode.Ticks, 2*ATR(10)[0]);
        }
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Hi Adam_P

          It is not working by this way... it is a pity than we have to initialise a static stop loss to move it them with new condition...

          by the way, i find the solution with the iorder and the Iexecution... but this is a lot of script for a small stop move....

          anyway, thank Adam !

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          672 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          379 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          111 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          582 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X