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

Dynamic ATR SetStopLoss - Price absolute vs offset?

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

    Dynamic ATR SetStopLoss - Price absolute vs offset?

    I'm using a dynamic ATR SetStopLoss in OnBarUpdate() section .. To activate the Stop as soon as position is entered (not wait for next bar), I added it in the Entry Condition below.

    1) My ExitLongLimit orders are not being triggered at all, even when the position is alive for several 100 bars and StopLoss isn't active. When i comment out the SetStopLoss, the ExitLongLimit works fine. Is there some issue with my SetStopLoss code?

    2) How do i change the SL price depending on # of Bars of position? I want to say
    if (Position.Bars ==0) SetStopLoss(entryPrice - 2*SlAtr*ATR(10)[0]);
    else SetStopLoss(entryPrice - SlAtr*ATR(10)[0])
    Note - since my SetStopLoss is in Entry condition, no Position object formed yet, so i can't check for the position bars.


    if (MACD(Close, MacdPer, MacdPer*2, 9).Diff[0] > MACD(MacdPer, MacdPer*2, 9).Diff[1])
    {
    double entryPrice = Close[0]-entryTicks*TickSize;
    EnterLongLimit(DefaultQuantity, entryPrice, "Enter-Lim");
    SetStopLoss("", CalculationMode.Price, entryPrice-SlAtr*ATR(10)[0], true); //
    }

    // Condition set 2
    if (MACD(Close, MacdPer, MacdPer*2, 9).Diff[0] < MACD(MacdPer, MacdPer*2, 9).Diff[1])
    {
    ExitLongLimit(Close[0] + exitTicks* TickSize, "Exit-lim", "");

    }
    Last edited by kbellare; 08-28-2015, 05:20 PM. Reason: nature of problem changed as i tested this out ..

    #2
    Originally posted by kbellare View Post
    I'm using a dynamic ATR SetStopLoss in OnBarUpdate() section .. To activate the Stop as soon as position is entered (not wait for next bar), I added it in the Entry Condition below.

    1) My ExitLongLimit orders are not being triggered at all, even when the position is alive for several 100 bars and StopLoss isn't active. When i comment out the SetStopLoss, the ExitLongLimit works fine. Is there some issue with my SetStopLoss code?

    2) How do i change the SL price depending on # of Bars of position? I want to say
    if (Position.Bars ==0) SetStopLoss(entryPrice - 2*SlAtr*ATR(10)[0]);
    else SetStopLoss(entryPrice - SlAtr*ATR(10)[0])
    Note - since my SetStopLoss is in Entry condition, no Position object formed yet, so i can't check for the position bars.


    if (MACD(Close, MacdPer, MacdPer*2, 9).Diff[0] > MACD(MacdPer, MacdPer*2, 9).Diff[1])
    {
    double entryPrice = Close[0]-entryTicks*TickSize;
    EnterLongLimit(DefaultQuantity, entryPrice, "Enter-Lim");
    SetStopLoss("", CalculationMode.Price, entryPrice-SlAtr*ATR(10)[0], true); //
    }

    // Condition set 2
    if (MACD(Close, MacdPer, MacdPer*2, 9).Diff[0] < MACD(MacdPer, MacdPer*2, 9).Diff[1])
    {
    ExitLongLimit(Close[0] + exitTicks* TickSize, "Exit-lim", "");

    }
    Documented in the NT Help here: http://ninjatrader.com/support/helpG...d_approach.htm

    Look at the last item on the page.

    Comment


      #3
      Hello kbellare,

      Thank you for your post.

      1. Koganam linked you over to the Internal Order Handling Rules that would dictate that the SetStopLoss or Exit method would ignore the other. Only one will work at the same time, not both.

      2. Use BarsSinceEntry: http://ninjatrader.com/support/helpG...sinceentry.htm

      I would also recommend reviewing the sample at the following link: http://ninjatrader.com/support/forum...ead.php?t=3222

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Balage0922, Today, 07:38 AM
      0 responses
      5 views
      0 likes
      Last Post Balage0922  
      Started by JoMoon2024, Today, 06:56 AM
      0 responses
      6 views
      0 likes
      Last Post JoMoon2024  
      Started by Haiasi, 04-25-2024, 06:53 PM
      2 responses
      19 views
      0 likes
      Last Post Massinisa  
      Started by Creamers, Today, 05:32 AM
      0 responses
      6 views
      0 likes
      Last Post Creamers  
      Started by Segwin, 05-07-2018, 02:15 PM
      12 responses
      1,786 views
      0 likes
      Last Post Leafcutter  
      Working...
      X