Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop loss at wrong location

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

    Stop loss at wrong location

    I am using a swing stop code below, in backtesting it seems to work fine but half the time it exits trades at the same price as they were entered (see screenshot link)
    if(Position.MarketPosition == MarketPosition.Long
    && GetCurrentBid() > Swing(5).SwingLow[1]);

    {
    SetStopLoss(CalculationMode.Price, Swing(5).SwingLow[1] - 5 * TickSize);
    }

    if(Position.MarketPosition == MarketPosition.Short
    && GetCurrentAsk() < Swing(5).SwingHigh[1]);
    {
    SetStopLoss(CalculationMode.Price, Swing(5).SwingHigh[1] + 5 * TickSize);
    }

    #2
    Ok so it looks like I was able to fix it, but how would I go about changing the swing stop loss location to breakeven once it reaches x ticks?
    IE change swing stops to breakeven + 5 ticks after reaching 10 ticks
    Last edited by brucelevy; 01-19-2016, 09:15 PM.

    Comment


      #3
      Hello brucelevy,

      Thanks for your posts.

      This is where you would access and use the entry price. The entry price can be found with Position.AvgPrice. http://ninjatrader.com/support/helpG.../?avgprice.htm

      For example (going long here),

      if (Close[0] >= Position.AvgPrice + 10 * TickSize)
      {
      SetStopLoss(CalculationMode.Price, Position.AvgPrice); // breakeven
      }

      if you wanted to add + 5 ticks (going long here) you can also do that:
      SetStopLoss(CalculationMode.Price, Position.AvgPrice + 5 * TickSize); // breakeven + 5 ticks

      Comment


        #4
        is there a way to use a changestop order instead of setstoploss

        Comment


          #5
          Hello brucelevy,

          Thanks for your reply.

          No, once you have used the SetStopLoss() method you can only move it by reissuing the SetStopLoss() with new values.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X