Library "UtilLibrary"
getTablePos(pos)
Parameters:
pos (series TablePositions)
findLastLocalHigh(lookback, remainingBars)
Parameters:
lookback (int)
remainingBars (int)
findLastLocalLow(lookback, remainingBars)
Parameters:
lookback (int)
remainingBars (int)
getTrailPrice(trailSource, trailMethod, trailPercent, swingLookback, atrPeriod, atrMultiplier, positionSize, curTrailPrice)
Declare trailing price variable (stores our trail stop value)
var float trailPrice = na
Draw trailing price to chart
plot(strategy.position_size != 0 ? trailPrice : na, style = plot.style_steplinebr, color=color.red, title="Trailing Stop")
using trailPrice
if closeType == "Price Hit"
strategy.exit(id="Trail Exit", from_entry="Trade", limit=na, stop=trailPrice)
else if (strategy.position_size > 0 and close < trailPrice) or (strategy.position_size < 0 and close > trailPrice)
strategy.close("Trade")
Parameters:
trailSource (string)
trailMethod (string)
trailPercent (float)
swingLookback (int)
atrPeriod (simple int)
atrMultiplier (float)
positionSize (float)
curTrailPrice (float)