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

ATR based Stop Loss

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

    ATR based Stop Loss

    I am trying to have a ATR based stop loss. For example, if I entered a long EURUSD position at 1.5600 at close of bar, and ATR(14) at close of bar is 0.0020, my static stop loss will be 1.5600 - 0.0020 = 1.5580.

    Under Initialize(), I included the following:

    SetStopLoss("", CalculationMode.Ticks, ATR(14)[0], false);

    However, when I tried to run the strategy, the log says:

    "Failed to call method "Initialize for strategy 'SimpleMACross': ATR[barsAgo]: barsAgo out of valid range 0 through -2, was 0.


    I would appreciate any advice.

    #2
    a) please make sure there is historical data available for the instrument you backtest by e.g. pulling up a chart while connected.
    b) try moving your SetStopLoss statement to the OnBarUpdate method

    Comment


      #3
      Hi Dierk,

      Thanks. Your statement (b) works.

      Here's my sample for readers facing the same problem:

      if (CrossAbove(EMA(14), EMA(24), 1))
      {
      EnterLong(1, "");
      SetStopLoss("", CalculationMode.Price, Close[0]-ATR(14)[0], false);
      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Bogdan097, Yesterday, 03:25 PM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by knowmad, Yesterday, 03:52 AM
      3 responses
      44 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by MSerag, 05-06-2024, 11:52 PM
      5 responses
      30 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Aviram Y, Today, 06:03 AM
      0 responses
      2 views
      0 likes
      Last Post Aviram Y  
      Started by Skifree, Yesterday, 11:21 AM
      5 responses
      17 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X