Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
      Paul H.NinjaTrader Customer Service

      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.
          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by rajendrasubedi2023, Today, 09:50 AM
          2 responses
          14 views
          0 likes
          Last Post rajendrasubedi2023  
          Started by geddyisodin, Today, 05:20 AM
          4 responses
          28 views
          0 likes
          Last Post geddyisodin  
          Started by geotrades1, Today, 10:02 AM
          2 responses
          8 views
          0 likes
          Last Post geotrades1  
          Started by ender_wiggum, Today, 09:50 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by bmartz, Today, 09:30 AM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Erick  
          Working...
          X