Announcement

Collapse
No announcement yet.

ATR Trailing Stop

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

  • ATR Trailing Stop

    Does anyone know how to create an ATR trailing stop in EFS? I'd like to have a line plotted that equals the last closing price of a security minus a specific ATR value.

    Thanks for any help,

  • #2
    sgroff,

    Here's some sample code you can use as a starting point. It is assumed you have defined the variables used somewhere else in your program.

    For the initial stop value:
    PHP Code:
            if(bDirection// LONG
        
    vStop vCostBasis - (vATR.getValue(-1) * vATRMultiplier);  
    else  
    // SHORT
        
    vStop vCostBasis + (vATR.getValue(-1) * vATRMultiplier); 
    Adjusting the stop at each NEWBAR
    PHP Code:
            if(bDirection// LONG, only move up
        
    vStop Math.max(vStopclose(-1) - (vATR.getValue(-1) * vATRMultiplier));
    else  
    // SHORT, only move down
        
    vStop Math.min(vStopclose(-1) + (vATR.getValue(-1) * vATRMultiplier)); 
    This code assumes you will multiply the ATR value by vATRMultiplier. The multiplier would typically be assigned a value in the 1.0-5.0 range.

    Steve

    Comment

    Working...
    X