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 CarlTrading, 03-31-2026, 09:41 PM
          1 response
          133 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          75 views
          1 like
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          117 views
          2 likes
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          113 views
          1 like
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          90 views
          0 likes
          Last Post CarlTrading  
          Working...
          X