0Predictions
New member
Any idea how to add in a Barsheld to this portion of the below script (highest(high, ATRLength)))? I'm using this on a N day breakout strategy and using the ATR as a trailing stop loss. tyia.
def trailStopLong = (if UseClose then highest(close, ATRLength) else highest(high, ATRLength)) - atr;
def longStopPrev = if IsNan(trailStopLong[1]) then trailStopLong else trailStopLong[1];
def LS =if close[1] > longStopPrev then max(trailStopLong, longStopPrev) else trailStopLong;
def trailStopShort = (if UseClose then lowest(close, ATRLength) else lowest(low, ATRLength)) + atr;
def shortStopPrev = if IsNan(trailStopShort[1]) then trailStopShort else trailStopShort[1];
def SS =if close[1] < shortStopPrev then min(trailStopShort, shortStopPrev) else trailStopShort;
def dir = if close > shortStopPrev then 1 else if close < longStopPrev then -1 else dir[1];
def direction = dir;
def trailStopLong = (if UseClose then highest(close, ATRLength) else highest(high, ATRLength)) - atr;
def longStopPrev = if IsNan(trailStopLong[1]) then trailStopLong else trailStopLong[1];
def LS =if close[1] > longStopPrev then max(trailStopLong, longStopPrev) else trailStopLong;
def trailStopShort = (if UseClose then lowest(close, ATRLength) else lowest(low, ATRLength)) + atr;
def shortStopPrev = if IsNan(trailStopShort[1]) then trailStopShort else trailStopShort[1];
def SS =if close[1] < shortStopPrev then min(trailStopShort, shortStopPrev) else trailStopShort;
def dir = if close > shortStopPrev then 1 else if close < longStopPrev then -1 else dir[1];
def direction = dir;
Last edited by a moderator: