Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License https://creativecommons.org/licenses/by-sa/4.0/
- // © alexgrover & Lucía Llorens
- //@version=4
- strategy("Grover Llorens Activator", "", true)
- length = input(480)
- mult = input(14)
- useHA = input(true, "Use Heikin Ashi instead of chart prices to calculate strategy")
- // ——————————————— Functions
- // Detect if chart is HA, code from @everget.
- f_isHA() =>
- var int gapsCount = -1
- var int matchedCandles = -1
- gapsCount := low[1] > high or high[1] < low ? gapsCount + 1 : gapsCount
- matchedCandles := open == (open[1] + close[1]) / 2 ? matchedCandles + 1 : matchedCandles
- isHA = matchedCandles == bar_index - 1 and matchedCandles != -1 and gapsCount == -1
- ticker = tickerid(syminfo.prefix, syminfo.ticker)
- source = not useHA or f_isHA() ? close : avg(open, high, low, close)
- //----
- f_gla(_source, _length) =>
- ts = 0.
- diff = _source - nz(ts[1],_source[1])
- atr = atr(_length)
- //----
- up = crossover(diff,0)
- dn = crossunder(diff,0)
- val = valuewhen(up or dn,atr/_length,0)
- bars = barssince(up or dn)
- ts := up ? nz(ts[1],_source) - atr*mult : dn ? nz(ts[1],_source) + atr*mult : nz(ts[1],_source) + sign(diff)*val*bars
- [diff, ts, up, dn]
- //----
- [diffC, tsC, upC, dnC] = f_gla(source, length)
- diff = not useHA or f_isHA() ? diffC : security(ticker, timeframe.period, diffC)
- ts = not useHA or f_isHA() ? tsC : security(ticker, timeframe.period, tsC)
- up = not useHA or f_isHA() ? upC : security(ticker, timeframe.period, upC)
- dn = not useHA or f_isHA() ? dnC : security(ticker, timeframe.period, dnC)
- css = diff > 0 ? #2196f3 : #ff1100
- plot(iff(up or dn,na,ts),"Activator",css,2,plot.style_linebr,transp=0)
- plotshape(iff(up,ts,na),"Buy Circle",shape.circle,location.absolute,#2196f3,0,size=size.tiny)
- plotshape(iff(dn,ts,na),"Sell Circle",shape.circle,location.absolute,#ff1100,0,size=size.tiny)
- plotshape(iff(up,ts,na),"Buy Label",shape.labelup,location.absolute,#2196f3,0,text="Buy",textcolor=color.white,size=size.tiny)
- plotshape(iff(dn,ts,na),"Sell Label",shape.labeldown,location.absolute,#ff1100,0,text="Sell",textcolor=color.white,size=size.tiny)
- //----
- if up
- strategy.entry("Buy", strategy.long)
- if dn
- strategy.entry("Sell", strategy.short)
- //----
- cap = strategy.initial_capital
- eq = strategy.equity
- rmax = 0.
- rmax := max(eq,nz(rmax[1]))
- // css = eq > cap ? #0cb51a : #e65100
- // a = plot(eq,"Equity",#2196f3,2,transp=0)
- // b = plot(rmax,"Maximum",css,2,transp=0)
- // fill(a,b,css,80)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement