Advertisement
PineCoders

Grover Llorens Activator with option for HA calcs

Feb 8th, 2020
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. // This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License https://creativecommons.org/licenses/by-sa/4.0/
  2. // © alexgrover & Lucía Llorens
  3.  
  4. //@version=4
  5. strategy("Grover Llorens Activator", "", true)
  6. length = input(480)
  7. mult = input(14)
  8. useHA = input(true, "Use Heikin Ashi instead of chart prices to calculate strategy")
  9.  
  10.  
  11. // ——————————————— Functions
  12. // Detect if chart is HA, code from @everget.
  13. f_isHA() =>
  14. var int gapsCount = -1
  15. var int matchedCandles = -1
  16. gapsCount := low[1] > high or high[1] < low ? gapsCount + 1 : gapsCount
  17. matchedCandles := open == (open[1] + close[1]) / 2 ? matchedCandles + 1 : matchedCandles
  18. isHA = matchedCandles == bar_index - 1 and matchedCandles != -1 and gapsCount == -1
  19.  
  20. ticker = tickerid(syminfo.prefix, syminfo.ticker)
  21. source = not useHA or f_isHA() ? close : avg(open, high, low, close)
  22.  
  23. //----
  24. f_gla(_source, _length) =>
  25. ts = 0.
  26. diff = _source - nz(ts[1],_source[1])
  27. atr = atr(_length)
  28. //----
  29. up = crossover(diff,0)
  30. dn = crossunder(diff,0)
  31. val = valuewhen(up or dn,atr/_length,0)
  32. bars = barssince(up or dn)
  33. ts := up ? nz(ts[1],_source) - atr*mult : dn ? nz(ts[1],_source) + atr*mult : nz(ts[1],_source) + sign(diff)*val*bars
  34. [diff, ts, up, dn]
  35. //----
  36. [diffC, tsC, upC, dnC] = f_gla(source, length)
  37. diff = not useHA or f_isHA() ? diffC : security(ticker, timeframe.period, diffC)
  38. ts = not useHA or f_isHA() ? tsC : security(ticker, timeframe.period, tsC)
  39. up = not useHA or f_isHA() ? upC : security(ticker, timeframe.period, upC)
  40. dn = not useHA or f_isHA() ? dnC : security(ticker, timeframe.period, dnC)
  41.  
  42. css = diff > 0 ? #2196f3 : #ff1100
  43. plot(iff(up or dn,na,ts),"Activator",css,2,plot.style_linebr,transp=0)
  44. plotshape(iff(up,ts,na),"Buy Circle",shape.circle,location.absolute,#2196f3,0,size=size.tiny)
  45. plotshape(iff(dn,ts,na),"Sell Circle",shape.circle,location.absolute,#ff1100,0,size=size.tiny)
  46.  
  47. plotshape(iff(up,ts,na),"Buy Label",shape.labelup,location.absolute,#2196f3,0,text="Buy",textcolor=color.white,size=size.tiny)
  48. plotshape(iff(dn,ts,na),"Sell Label",shape.labeldown,location.absolute,#ff1100,0,text="Sell",textcolor=color.white,size=size.tiny)
  49.  
  50. //----
  51. if up
  52. strategy.entry("Buy", strategy.long)
  53. if dn
  54. strategy.entry("Sell", strategy.short)
  55. //----
  56. cap = strategy.initial_capital
  57. eq = strategy.equity
  58. rmax = 0.
  59. rmax := max(eq,nz(rmax[1]))
  60.  
  61.  
  62. // css = eq > cap ? #0cb51a : #e65100
  63. // a = plot(eq,"Equity",#2196f3,2,transp=0)
  64. // b = plot(rmax,"Maximum",css,2,transp=0)
  65. // fill(a,b,css,80)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement