Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // © Amjad_S
- //@version=5
- //------------------------------------------------------------------------------
- // Indictort, Library Import & User Inputs
- //-----------------------------------------------------------------------------{
- indicator("Gaussian Fisher Transform Price Reversals", shorttitle = "FTR", overlay = true)
- // Use Inputs //
- src = input.source(hl2, title = "Source of transformation")
- lkb = input.int(14, title = "Fisher Transformation lookback period")
- lkb_volu = input.int(14, "Volume Average and stdev lookback")
- lkb_avg = input.int(5, title = "Lagged Fisher Transformation Trigger lookback period")
- alpha = input.float(0.33, title = "Normalized Price smoothing filter", minval = 0, maxval = 1)
- sigma = input.float(1.00, title = "Standard deviation / Fisher value for valid S&R zone")
- Q = input.int(20, title = "Max labels")
- fr_col = input.color(color.red, title = "Fisher Resistance color")
- fs_col = input.color(color.green, title = "Fisher Support color")
- //------------------------------------------------------------------------------
- // Function Deriviations
- //-----------------------------------------------------------------------------{
- // Gussian Fisher Transform with Fisher Transform Average
- FT(src_, lkb_, lkb_avg_) =>
- // max and min of time series
- float maxH = ta.highest(high, lkb_)
- float minL = ta.lowest(low, lkb_)
- // Gussian normal distribution Transform
- var float val1 = 0
- // alpha smoothing of 0.33
- val1 := na(val1[1]) ? alpha * 2 * ((src_ - minL) / (maxH - minL) - 0.5) + (0.67 * nz(val1[1], 0)) :
- alpha * 2 * ((src_ - minL) / (maxH - minL) - 0.5) + (0.67 * val1[1])
- if val1 > 0.99
- val1 := 0.999
- else if val1 < -0.99
- val1 := -0.999
- // fish transform
- var float fish_trsf = 0
- fish_trsf := na(fish_trsf[1]) ? 0.5 * math.log((1 + val1) / (1 - val1)) + (0.5 * nz(fish_trsf[1], 0)) :
- 0.5 * math.log((1 + val1) / (1 - val1)) + (0.5 * fish_trsf[1])
- // Trigger line
- fish_trsf_lag = ta.sma(fish_trsf, lkb_avg)
- // Function Sub function call
- [fish_trsf, fish_trsf_lag]
- //------------------------------------------------------------------------------
- // Function Calls / Calculations and plots
- //-----------------------------------------------------------------------------{
- [fish_trsf, fish_trsf_lag] = FT(src, lkb, lkb_avg)
- // Calculate volatility bars //
- i(q) =>
- barstate.isrealtime ?
- q[1] : q[0]
- vol = ta.sma(volume, lkb_volu)
- dev = ta.stdev(volume, lkb_volu)
- // pos
- posdev1 = vol + (dev)
- posdev2 = vol + (dev*2)
- posdev3 = vol + (dev*3)
- // neg
- negdev1 = vol - (dev)
- negdev2 = vol - (dev*2)
- negdev3 = vol - (dev*3)
- // plot relative volume bars
- barpos1 = color.rgb(255, 19, 157)
- barpos2 = color.rgb(204, 0, 255)
- barpos3 = color.rgb(111, 0, 255)
- barneg1 = #0066ff
- barneg2 = #00e1ff
- barneg3 = #91f2ff
- barcolor(volume >= i(posdev1) ? barpos1 :
- volume >= i(posdev2) ? barpos2 :
- volume >= i(posdev3) ? barpos3 :
- volume <= i(negdev1) ? barneg1 :
- volume <= i(negdev2) ? barneg2 :
- volume <= i(negdev3) ? barneg3 :
- na)
- // Reversals & Reversal plots //
- res = ta.crossunder(fish_trsf, fish_trsf_lag) and fish_trsf >= sigma
- sup = ta.crossover(fish_trsf, fish_trsf_lag) and fish_trsf <= -1*(sigma)
- // support and resistance lines
- var line[] linetop = array.new<line>()
- var line[] linebot = array.new<line>()
- // labels
- var label[] linetop_label = array.new<label>()
- var label[] linebot_label = array.new<label>()
- // resistance reversal
- if res[1]
- array.unshift(linetop, line.new(bar_index, high, bar_index + 100, high, extend = extend.none, color = fr_col))
- array.unshift(linetop_label, label.new(bar_index, high, yloc = yloc.abovebar, text = "FT : "+ str.tostring(math.round(fish_trsf[1], 2)) +" ", color = na, textcolor = fr_col, style = label.style_none, size = size.small))
- // support reversal
- if sup[1]
- array.unshift(linebot, line.new(bar_index, low, bar_index + 100, low, extend = extend.none, color = fs_col))
- array.unshift(linebot_label, label.new(bar_index, low, yloc = yloc.belowbar,text = "FT : "+ str.tostring(math.round(fish_trsf[1], 2)) +" ", color = na, textcolor = fs_col, style = label.style_none, size = size.small))
- // ploting resistance reversal
- for i = (array.size(linetop) > 0 ? array.size(linetop) - 1 : na) to 0
- l = line.get_price(array.get(linetop, i), bar_index)
- if high > l
- line.set_x2(array.get(linetop, i), bar_index)
- array.remove(linetop, i)
- else if high < l
- line.set_x2(array.get(linetop, i), bar_index)
- // ploting support reversal
- for i = (array.size(linebot) > 0 ? array.size(linebot) - 1 : na) to 0
- l = line.get_price(array.get(linebot, i), bar_index)
- if low < l
- line.set_x2(array.get(linebot, i), bar_index)
- array.remove(linebot, i)
- else if low > l
- line.set_x2(array.get(linebot, i), bar_index)
- if array.size(label.all) > Q
- label.delete(array.get(label.all, 0))
Advertisement
Add Comment
Please, Sign In to add comment