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 SalmaTrader, 07-07-2026, 10:26 PM
      0 responses
      47 views
      0 likes
      Last Post SalmaTrader  
      Started by CarlTrading, 07-05-2026, 01:16 PM
      0 responses
      22 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 06-17-2026, 10:32 AM
      0 responses
      15 views
      0 likes
      Last Post CaptainJack  
      Started by kinfxhk, 06-17-2026, 04:15 AM
      0 responses
      21 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 06-17-2026, 04:06 AM
      0 responses
      23 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Working...
      X