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 llanqui, Today, 03:53 AM
      0 responses
      6 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      10 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      15 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      14 views
      0 likes
      Last Post strategist007  
      Working...
      X