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 CaptainJack, 05-29-2026, 05:09 AM
          0 responses
          264 views
          0 likes
          Last Post CaptainJack  
          Started by CaptainJack, 05-29-2026, 12:02 AM
          0 responses
          168 views
          0 likes
          Last Post CaptainJack  
          Started by charlesugo_1, 05-26-2026, 05:03 PM
          0 responses
          171 views
          1 like
          Last Post charlesugo_1  
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          257 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          209 views
          0 likes
          Last Post CarlTrading  
          Working...
          X