Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      581 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      338 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X