Files
xPineScript/xSamples/indicators/chandelier-stop.pine
T
2024-01-25 04:07:49 +03:30

33 lines
1.5 KiB
Plaintext

//+------------------------------------------------------------------+
//| Edited original VStop Script from LazyBear using info from |
//| ChandelierStops_v1.mq4 |
//| Copyright © 2006, Forex-TSD.com |
//| Written by IgorAD,igorad2003@yahoo.co.uk |
//| http://finance.groups.yahoo.com/group/TrendLaboratory |
//+------------------------------------------------------------------+
study("Chandelier Stop", overlay=true)
//input variables
Length=input(title="Look Back Period", type=integer, defval=22)
ATRPeriod=input(title="ATR Period", type=integer, defval=22)
Mult=input(title="ATR Multiplier", type=integer, defval=3)
//calculate stop value
short_stop = lowest(Length)+Mult*atr(ATRPeriod)
long_stop = highest(Length)-Mult*atr(ATRPeriod)
shortvs=na(shortvs[1]) ? short_stop : iff(close>shortvs[1], short_stop , min(short_stop,shortvs[1]))
longvs=na(longvs[1]) ? long_stop : iff(close<longvs[1], long_stop, max(long_stop,longvs[1]))
longswitch=iff (close>=shortvs[1] and close[1]<shortvs[1] , 1 , 0)
shortswitch=iff (close<=longvs[1] and close[1]>longvs[1] , 1 , 0)
direction= iff(na(direction[1]), 0,
iff (direction[1]<=0 and longswitch, 1,
iff (direction[1]>=0 and shortswitch, -1, direction[1])))
pc=direction>0?longvs:shortvs
plot(pc, color=direction>0?aqua:fuchsia, style=circles, linewidth=2)
plot(pc, color=direction>0?aqua:fuchsia, style=line, linewidth=2)