Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © tanmay159
- //@version=4
- study(title="Chart Game Daily Pivot & Fibo Range With Ultimate Indicator", shorttitle="Ultimate Pivot", overlay=true)
- daily_cpr = input (title="Select Days", type= input.integer , defval=1, minval=0)
- FPeriod = input('D', title="Day/Week/Month", options=["D", "W", "M", "Y"])
- adjust = input (title="1-Today 2-Tomorrow", type= input.integer, defval=1, minval=0)
- up_fibo = input(title="Upper Fibo levels", type=input.bool, defval=false)
- down_fibo = input(title="Lower Fibo levels", type=input.bool, defval=false)
- up_pivots = input(title="Upper Pivot levels", type=input.bool, defval=false)
- down_pivots = input(title="Lower Pivot levels", type=input.bool, defval=false)
- inner_zones = input(title="Inner zones", type=input.bool, defval=true)
- minor_zones1 = input(title="Minor +ve SR zones", type=input.bool, defval=false)
- minor_zones2 = input(title="Minor -ve SR zones", type=input.bool, defval=false)
- High_probable = input(title="High_probable", type=input.bool, defval=false)
- //Outside_fibo = input(title="Fibo levels", type=input.bool, defval=false)
- //small_fibo = input(title="Minor fibo levels", type=input.bool, defval=false)
- //Outside_pivots = input(title="Pivot levels", type=input.bool, defval=false)
- new_bar(res) => change(time(res)) != 0
- new_period(condition, src) =>
- result = 0.0
- result := condition ? src : result[1]
- result
- Fhigh = security(syminfo.tickerid, FPeriod, high[adjust], lookahead = barmerge.lookahead_on)
- Flow = security(syminfo.tickerid, FPeriod, low[adjust], lookahead = barmerge.lookahead_on)
- Fclose = security(syminfo.tickerid, FPeriod, close[adjust], lookahead = barmerge.lookahead_on)
- Fopen = security(syminfo.tickerid, FPeriod, open[0], lookahead = barmerge.lookahead_on)
- pivot = (Fhigh + Flow + Fclose) / 3.0
- bc = (Fhigh + Flow) / 2.0
- tc = (pivot - bc) + pivot
- R1 = (2*pivot) - Flow
- S1 = (2*pivot) - Fhigh
- R2 = pivot + ( Fhigh - Flow)
- S2 = pivot - ( Fhigh - Flow)
- R3 = Fhigh + (2*(pivot - Flow))
- S3 = Flow - (2*(Fhigh - pivot ))
- R4 = R3 + (R2 - R1)
- S4 = S3 - (S1 - S2)
- PH = Fhigh
- PL = Flow
- PO = Fopen
- P_HALF = (Fhigh + Flow) / 2
- F1618 = (Fhigh-Flow)*1.618+Flow
- F2618 = (Fhigh-Flow)*2.618+Flow
- F3618 = (Fhigh-Flow)*3.618+Flow
- FE618 = (Fhigh-Flow)*(-0.618)+Flow
- FE1618 = (Fhigh-Flow)*(-1.618)+Flow
- FE2618 = (Fhigh-Flow)*(-2.618)+Flow
- F1382 = (Fhigh-Flow)*1.382+Flow
- F2000 = (Fhigh-Flow)*2.000+Flow
- F3000 = (Fhigh-Flow)*3.000+Flow
- FE382 = (Fhigh-Flow)*(-0.382)+Flow
- FE1000 = (Fhigh-Flow)*(-1.000)+Flow
- FE2000 = (Fhigh-Flow)*(-2.000)+Flow
- one_day = 1000 * 60 * 60 * 24
- new_day = daily_cpr > 0 and timenow - time < one_day * daily_cpr and new_bar(FPeriod)
- dpp_ = new_period(new_day, pivot)
- dtc_ = new_period(new_day, tc)
- dbc_ = new_period(new_day, bc)
- dR1_ = new_period(new_day, R1)
- dS1_ = new_period(new_day, S1)
- dR2_ = new_period(new_day, R2)
- dS2_ = new_period(new_day, S2)
- dR3_ = new_period(new_day, R3)
- dS3_ = new_period(new_day, S3)
- dR4_ = new_period(new_day, R4)
- dS4_ = new_period(new_day, S4)
- dPH_ = new_period(new_day, PH)
- dPL_ = new_period(new_day, PL)
- dPO_ = new_period(new_day, PO)
- dP_HALF_ = new_period(new_day, P_HALF)
- d16_ = new_period(new_day, F1618)
- d26_ = new_period(new_day, F2618)
- d36_ = new_period(new_day, F3618)
- dE06_ = new_period(new_day, FE618)
- dE16_ = new_period(new_day, FE1618)
- dE26_ = new_period(new_day, FE2618)
- d13_ = new_period(new_day, F1382)
- d20_ = new_period(new_day, F2000)
- d30_ = new_period(new_day, F3000)
- dE03_ = new_period(new_day, FE382)
- dE10_ = new_period(new_day, FE1000)
- dE20_ = new_period(new_day, FE2000)
- plotR2=plot(up_pivots and dR2_ ? dR2_ : na, title='R2', title="Daily TC", style= plot.style_line , color=#800080, linewidth=1)
- label_R2 = label.new(bar_index, up_pivots and dR2_ ? dR2_ : na, text="R2", style=label.style_none)
- label.delete(label_R2[1])
- plotS2=plot(down_pivots and dS2_ ? dS2_ : na, title='S2', title="Daily TC", style= plot.style_line , color=#008069, linewidth=1)
- label_S2 = label.new(bar_index, down_pivots and dS2_ ? dS2_ : na, text="S2", style=label.style_none)
- label.delete(label_S2[1])
- plotR3=plot(up_pivots and dR3_ ? dR3_ : na, title='R3', title="Daily TC", style= plot.style_line , color=#800080, linewidth=1)
- label_R3 = label.new(bar_index, up_pivots and dR3_ ? dR3_ : na, text="R3", style=label.style_none)
- label.delete(label_R3[1])
- plotS3=plot(down_pivots and dS3_ ? dS3_ : na, title='S3', title="Daily TC", style= plot.style_line , color=#008069, linewidth=1)
- label_S3 = label.new(bar_index, down_pivots and dS3_ ? dS3_ : na, text="S3", style=label.style_none)
- label.delete(label_S3[1])
- plotR4=plot(up_pivots and dR4_ ? dR4_ : na, title='R4', title="Daily TC", style= plot.style_line , color=#800080, linewidth=1)
- label_R4 = label.new(bar_index, up_pivots and dR4_ ? dR4_ : na, text="R4", style=label.style_none)
- label.delete(label_R4[1])
- plotS4=plot(down_pivots and dS4_ ? dS4_ : na, title='S4', title="Daily TC", style= plot.style_line , color=#008069, linewidth=1)
- label_S4 = label.new(bar_index, down_pivots and dS4_ ? dS4_ : na, text="S4", style=label.style_none)
- label.delete(label_S4[1])
- plot(up_fibo and d16_ ? d16_ : na, title='1.618', title="Fibo 1.618", style= plot.style_cross , color=#ff9800, linewidth=1)
- label_f1 = label.new(bar_index, up_fibo and d16_ ? d16_ : na, text="1.618%", style=label.style_none)
- label.delete(label_f1[1])
- plot(down_fibo and dE06_ ? dE06_ : na , title='-0.618', title="Fibo -0.618", style= plot.style_cross , color=#ff9800, linewidth=1)
- label_ef1 = label.new(bar_index, down_fibo and dE06_ ? dE06_ : na, text="-0.618%", style=label.style_none)
- label.delete(label_ef1[1])
- plot(up_fibo and d26_ ? d26_ : na, title='2.618', title="Fibo 2.618", style= plot.style_cross , color=color.green, linewidth=1)
- label_f2 = label.new(bar_index, up_fibo and d26_ ? d26_ : na, text="2.618%", style=label.style_none)
- label.delete(label_f2[1])
- plot(down_fibo and dE16_ ? dE16_ : na, title='-1.618', title="Fibo -1.618", style= plot.style_cross , color=color.green, linewidth=1)
- label_ef2 = label.new(bar_index, down_fibo and dE16_ ? dE16_ : na, text="-1.618%", style=label.style_none)
- label.delete(label_ef2[1])
- plot(up_fibo and d36_ ? d36_ : na , title='3.618', title="Fibo 3.618", style= plot.style_cross , color=#787b86, linewidth=1)
- label_f3 = label.new(bar_index, up_fibo and d36_ ? d36_ : na, text="3.618%", style=label.style_none)
- label.delete(label_f3[1])
- plot(down_fibo and dE26_ ? dE26_ : na , title='-2.618', title="Fibo -1.618", style= plot.style_cross , color=#787b86, linewidth=1)
- label_ef3 = label.new(bar_index, down_fibo and dE26_ ? dE26_ : na, text="-1.618%", style=label.style_none)
- label.delete(label_ef3[1])
- plot(up_fibo and d13_ ? d13_ : na, title='1.382', title="Fibo 1.382", style= plot.style_cross , color=color.green, linewidth=1)
- label_f4 = label.new(bar_index, up_fibo and d13_ ? d13_ : na, text="1.382%", style=label.style_none)
- label.delete(label_f4[1])
- plot(down_fibo and dE03_ ? dE03_ : na , title='-0.382', title="Fibo -0.382", style= plot.style_cross , color=color.green, linewidth=1)
- label_ef4 = label.new(bar_index, down_fibo and dE03_ ? dE03_ : na, text="-0.382%", style=label.style_none)
- label.delete(label_ef4[1])
- plot(up_fibo and d20_ ? d20_ : na, title='2.000', title="Fibo 2.000", style= plot.style_cross , color=color.green, linewidth=1)
- label_f5 = label.new(bar_index, up_fibo and d20_ ? d20_ : na, text="2.000%", style=label.style_none)
- label.delete(label_f5[1])
- plot(down_fibo and dE10_ ? dE10_ : na , title='-1.000', title="Fibo -1.000", style= plot.style_cross , color=color.green, linewidth=1)
- label_ef5 = label.new(bar_index, down_fibo and dE10_ ? dE10_ : na, text="-1.000%", style=label.style_none)
- label.delete(label_ef5[1])
- plot(up_fibo and d30_ ? d30_ : na, title='3.000', title="Fibo 3.000", style= plot.style_cross , color=#787b86, linewidth=1)
- label_f6 = label.new(bar_index, up_fibo and d30_ ? d30_ : na, text="3.000%", style=label.style_none)
- label.delete(label_f6[1])
- plot(down_fibo and dE20_ ? dE20_ : na , title='-2.000', title="Fibo -2.000", style= plot.style_cross , color=#787b86, linewidth=1)
- label_ef6 = label.new(bar_index, down_fibo and dE20_ ? dE20_ : na, text="-2.000%", style=label.style_none)
- label.delete(label_ef6[1])
- //minor zones
- plotaR2=plot(minor_zones1 and dR2_ ? dR2_ : na, title='R2', color=#52BE80, style= plot.style_cross, linewidth=0)
- plota1382=plot(minor_zones1 and d13_ ? d13_ : na, title='1.382%', color=#3498DB, style= plot.style_cross, linewidth=0)
- plotaR3=plot(minor_zones1 and dR3_ ? dR3_ : na, title='R3', color=#52BE80, style= plot.style_cross, linewidth=0)
- plota2=plot(minor_zones1 and d20_ ? d20_ : na, title='2.000%', color=#3498DB, style= plot.style_cross, linewidth=0)
- plotaR4=plot(minor_zones1 and dR4_ ? dR4_ : na, title='R4', color=#52BE80, style= plot.style_cross, linewidth=0)
- plota2618=plot(minor_zones1 and d26_ ? d26_ : na, title='2.618%', color=#3498DB, style= plot.style_cross, linewidth=0)
- plota1618=plot(minor_zones1 and d16_ ? d16_ : na, title='1.618%', color=#3498DB, style= plot.style_cross, linewidth=0)
- plotaS2=plot(minor_zones2 and dS2_ ? dS2_ : na, title='S2', color=#E74C3C, style= plot.style_cross, linewidth=0)
- plotae0382=plot(minor_zones2 and dE03_ ? dE03_ : na, title='-0.382%', color=#D4AC0D, style= plot.style_cross, linewidth=0)
- plotaS3=plot(minor_zones2 and dS3_ ? dS3_ : na, title='S3', color=#E74C3C, style= plot.style_cross, linewidth=0)
- plotae1=plot(minor_zones2 and dE10_ ? dE10_ : na, title='-1.000%', color=#D4AC0D, style= plot.style_cross, linewidth=0)
- plotaS4=plot(minor_zones2 and dS4_ ? dS4_ : na, title='S4', color=#E74C3C, style= plot.style_cross, linewidth=0)
- plotae1618=plot(minor_zones2 and dE16_ ? dE16_ : na, title='-1.618%', color=#D4AC0D, style= plot.style_cross, linewidth=0)
- plotae0618=plot(minor_zones2 and dE06_ ? dE06_ : na, title='-0.618%', color=#D4AC0D, style= plot.style_cross, linewidth=0)
- fill(plotaR2, plota1382, color=#D8FFF0, transp=94)
- fill(plotaR3, plota2, color=#D8FFF0, transp=94)
- fill(plotaR4, plota2618, color=#D8FFF0, transp=94)
- fill(plotaS2, plotae0382, color=#D8FFF0, transp=94)
- fill(plotaS3, plotae1, color=#D8FFF0, transp=94)
- fill(plotaS4, plotae1618, color=#D8FFF0, transp=94)
- //No trade zone
- plotbR1=plot(inner_zones and dR1_ ? dR1_ : na, title='R1', color=#FF0000, style= plot.style_line, linewidth=0)
- plotbS1=plot(inner_zones and dS1_ ? dS1_ : na, title='S1', color=#00FF00, style= plot.style_line, linewidth=0)
- plotbPDH=plot(inner_zones and dPH_ ? dPH_ : na, title='Previous High', color=#048617, style= plot.style_line, linewidth=1)
- plotbPDL=plot(inner_zones and dPL_ ? dPL_ : na, title='Previous Low', color=#C4061F, style= plot.style_line, linewidth=1)
- plotbTC=plot(inner_zones and dtc_ ? dtc_ : na, title='TC', color=#FF0000, style= plot.style_cross, linewidth=0)
- plotbpp=plot(inner_zones and dpp_ ? dpp_ : na, title='PP', color=#10d4ed, style= plot.style_line, linewidth=1)
- plotbBC=plot(inner_zones and dbc_ ? dbc_ : na, title='BC', color=#FF0000, style= plot.style_cross, linewidth=0)
- fill(plotbR1, plotbPDH, color=#00FF00, transp=95)
- fill(plotbS1, plotbPDL, color=#FF0000, transp=95)
- fill(plotbTC, plotbBC, color=#00FFFF, transp=95)
- // High_probable
- plotbPDHh=plot(High_probable and dPH_ ? dPH_ : na, title='Previous High', color=#048617, style= plot.style_circles, linewidth=2)
- plotbPDLh=plot(High_probable and dPL_ ? dPL_ : na, title='Previous Low', color=#C4061F, style= plot.style_circles, linewidth=2)
- plotbpph=plot(High_probable and dP_HALF_ ? dP_HALF_ : na, title='HALF', color=#363A45, style= plot.style_circles, linewidth=1)
- plotbpoh=plot(High_probable and dPO_ ? dPO_ : na, title='PO', color=color.yellow, style= plot.style_circles, linewidth=1)
- // Camarilla
- is_cm = input(title="Camarilla", type=input.bool, defval=true)
- mode =input(title = "HTF Method", defval = 'User Defined', options=['Auto', 'User Defined'], tooltip = "Choose Of the method to Select the Timeframe")
- HTFm = input('D', title = "Time Frame (if HTF Method=User Defined)", type=input.resolution, tooltip = "Manual Timeframe Selection")
- showlast = input(title = "Show Only Last Period", defval = true, tooltip = "Shows only Today levels bar by bar")
- showlabels = input(title = "Show Labels", defval = true, tooltip = "Shows labels on plotted pivots")
- cturnon = input(title = "Turn On Camarilla", defval = true, tooltip = "Turn Camarilla ON")
- //auto higher time frame
- HTFo =timeframe.period == '1' ? '30' :
- timeframe.period == '3' ? '60' :
- timeframe.period == '5' ? '60' :
- timeframe.period == '15' ? '240' :
- timeframe.period == '30' ? 'D' :
- timeframe.period == '45' ? 'D' :
- timeframe.period == '60' ? 'D' :
- timeframe.period == '240' ? 'W' :
- timeframe.period == 'D' ? '12M' :
- timeframe.period == 'W' ? '12M' :
- '6M'
- HTF = mode == 'Auto' ? HTFo : HTFm
- hhtf = security(syminfo.tickerid, HTF, high[1], lookahead = barmerge.lookahead_on)
- lhtf = security(syminfo.tickerid, HTF, low[1], lookahead = barmerge.lookahead_on)
- chtf = security(syminfo.tickerid, HTF, close[1], lookahead = barmerge.lookahead_on)
- rng = hhtf - lhtf
- // is this last bar for HTF?
- islast = showlast ? security(syminfo.tickerid, HTF, barstate.islast, lookahead = true) : true
- linestyleL = plot.style_circles
- // Calculation Camarilla
- H4 = chtf + rng * 1.1/2
- H3 = chtf + rng * 1.1/4
- H2 = chtf + rng * 1.1/6
- H1 = chtf + rng * 1.1/12
- L1 = chtf - rng * 1.1/12
- L2 = chtf - rng * 1.1/6
- L3 = chtf - rng * 1.1/4
- L4 = chtf - rng * 1.1/2
- L5 = L4 - 1.168 * (L3 - L4) //L5 = chtf - (H5 - chtf)
- H5 = H4 + 1.168 * (H4 - H3) //H5 = (hhtf / lhtf) * chtf
- H6 = (hhtf/lhtf) * chtf //H6 = H5 + 1.168 * (H5 - H4)
- L6 = chtf - (H6 - chtf) //L6 = chtf - (H6 - chtf)
- SLbull = (H4 + H3) / 2
- SLbear = (L4 + L3) / 2
- mid = (H3 + L3) / 2
- // Color Settings
- plot(islast and cturnon ? mid :na,"Mid-H3-L3",color=color.new(#9598a1 ,40), linewidth = 1, style = linestyleL)
- plot(islast and cturnon ? SLbull : na,"SLBull H3-H4",color=color.new(#ff0000 , 40), linewidth = 1, style = linestyleL)
- plot(islast and cturnon ? SLbear : na, "SLBear L3-L4",color=color.new(#ff0000,40), linewidth = 1, style = linestyleL)
- // Label for S/R
- mndr = time - time[1]
- mndr := change(mndr) > 0 ? mndr[1] : mndr
- Round_it(valu)=>
- a = 0
- num = syminfo.mintick
- s = valu
- if na(s)
- s := syminfo.mintick
- if num < 1
- for i = 1 to 20
- num := num * 10
- if num > 1
- break
- a := a +1
- for x = 1 to a
- s := s * 10
- s := round(s)
- for x = 1 to a
- s := s / 10
- s := s < syminfo.mintick ? syminfo.mintick : s
- s
- // Labels
- if showlabels and cturnon
- var label s3label = na, var label s4label = na, var label s5label = na, var label s6label = na
- var label r3label = na, var label r4label = na, var label r5label = na, var label r6label = na
- label.delete(s3label), label.delete(s4label), label.delete(s5label), label.delete(s6label)
- label.delete(r3label), label.delete(r4label), label.delete(r5label), label.delete(r6label)
- s3label := label.new(x = time + mndr * 20, y = L3, text = "......br • " + tostring(Round_it(L3)), color = color.new(color.lime,100), textcolor=color.teal, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
- s4label := label.new(x = time + mndr * 20, y = L4, text = "......bd • " + tostring(Round_it(L4)), color = color.new(color.lime,100), textcolor=color.teal, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
- s5label := label.new(x = time + mndr * 20, y = L5, text = "......t • " + tostring(Round_it(L5)), color = color.new(color.lime,100), textcolor=color.black, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
- s6label := label.new(x = time + mndr * 20, y = L6, text = "......t • " + tostring(Round_it(L6)), color = color.new(color.lime,100), textcolor=color.black, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
- r3label := label.new(x = time + mndr * 20, y = H3, text = "......sr • " + tostring(Round_it(H3)), color = color.new(color.lime,100), textcolor=color.maroon, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
- r4label := label.new(x = time + mndr * 20, y = H4, text = "......bd • " + tostring(Round_it(H4)), color = color.new(color.lime,100), textcolor=color.maroon, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
- r5label := label.new(x = time + mndr * 20, y = H5, text = "......t • " + tostring(Round_it(H5)), color = color.new(color.lime,100), textcolor=color.black, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
- r6label := label.new(x = time + mndr * 20, y = H6, text = "......t • " + tostring(Round_it(H6)), color = color.new(color.lime,100), textcolor=color.black, style=label.style_label_left, xloc = xloc.bar_time, yloc=yloc.price,size=size.normal)
- // Exponential Moving Averages
- is_EMAs = input(title="Display the EMAs?", type=input.bool, defval=false)
- var float ema111 = na
- var float ema200 = na
- var float ema800 = na
- if is_EMAs
- ema111 := ema(close, 111)
- ema200 := ema(close, 200)
- ema800 := ema(close, 800)
- plot(ema111, color=color.silver,linewidth=1, title='111 EMA')
- plot(ema200, color=color.olive,linewidth=1, title='200 EMA')
- plot(ema800, color=color.blue,linewidth=1, title='800 EMA')
- //Moving average
- Moving_Average1 = input(title="Moving_Average_1", type=input.bool, defval=false)
- ma_len1 = input(8, minval=1, title="Moving_Average1")
- ma_out1 = ema(close, ma_len1)
- plot(Moving_Average1 and ma_out1 ? ma_out1 : na, title="EMA1", color=close >= ma_out1 ? #4CAF50 : #FF5252, linewidth = 2, transp=50)
- Moving_Average2 = input(title="Moving_Average_2", type=input.bool, defval=false)
- ma_len2 = input(27, minval=1, title="Moving_Average2")
- ma_out2 = ema(close, ma_len2)
- plot(Moving_Average2 and ma_out2 ? ma_out2 : na, title="EMA2", color=close >= ma_out2 ? #07b80e : #dc0202, linewidth = 2, transp=0)
- //vwap
- Vwap_get = input(title="Vwap", type=input.bool, defval=false)
- //plot(Vwap_get and vwap ? vwap : na, title="vwap", color=#00606D, linewidth = 1, transp=0)
- plot(Vwap_get and vwap ? vwap : na, title="vwap", color=close >= vwap ? #4CAF50 : #FF5252, linewidth = 2, transp=0)
- //mvwap
- mvwap_get = input(title="Mvwap", type=input.bool, defval=false)
- mvwap_len = input(50, minval=1, title="mvwap length")
- mvwap = ema(vwap,mvwap_len)
- plot(mvwap_get and mvwap ? mvwap : na, title="mvwap", color=#AB1200, linewidth = 1, transp=0)
- // Bollinger Bands
- is_bb = input(title="Bollinger Bands", type=input.bool, defval=true)
- length = input(20, minval=1)
- src = input(close, title="Source")
- mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
- basis = sma(src, length)
- dev = mult * stdev(src, length)
- upper = basis + dev
- lower = basis - dev
- offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
- plot(basis, "BB Basis", color=#872323, offset = offset)
- ip1 = plot(upper, "BB Upper", color=#00897B, offset = offset)
- ip2 = plot(lower, "BB Lower", color=#00897B, offset = offset)
- fill(ip1, ip2, title = "BB Background", color=color.rgb(33, 150, 243, 95))
- // SSL Period
- is_ssl = input(title="SSL Period", type=input.bool, defval=true)
- len = input(10, "SSL Period") //Period of SMA
- sma_high = sma(high,len) //SMA of HIGH with period "len"
- sma_low = sma(low,len) //SMA of LOW with period "len"
- hlv = 0 //Init the "High-Low Value"
- ioffset = input(1,"SSL Offset") //Option to offset MA values back
- //if close is above MA of high, green line on top
- //if close is below MA of low, green line on bottom
- hlv := close > sma_high[1] ? 1 : close < sma_low[1] ? -1 : hlv[1]
- ssld = hlv == -1 ? sma_high[ioffset] : sma_low[ioffset]
- sslu = hlv == -1 ? sma_low[ioffset] : sma_high[ioffset]
- //Plotting
- plot(ssld,"SSL Down",color.red,1)
- ATRTsl = input(false,"Trailing SL", tooltip = "Trailing SL")
- // ATR Trailing SL
- nATRPeriod = input(5)
- nATRMultip = input(3.5)
- xATR = atr(nATRPeriod)
- nLoss = nATRMultip * xATR
- xATRTrailingStop = 0.0
- xATRTrailingStop :=iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss),
- iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss),
- iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))
- col=close < xATRTrailingStop[1] ? color.silver : color.black
- plot(ATRTsl ? xATRTrailingStop[1]: na, color=col, title="ATR Trailing Stop")
- vsr = input(false, title="Show Volume Based S&R", tooltip = "Shows Volume Based Support and Resistance on Stocks and Futures")
- ////////////Volume Based Support Resistance
- Vlength = input(20, minval=1, group = "Volume S/R Settings")
- Vchange = volume/volume[1] - 1
- stdev = stdev(Vchange, Vlength)
- difference = Vchange / stdev[1]
- Treshold = input(5)
- zero = 0
- signal = abs(difference)
- vstylee = plot.style_circles
- leveluphi = valuewhen(signal > Treshold,high[1],0)
- leveluplo = valuewhen(signal > Treshold,low[1],0)
- //plot(UpperTreshold, color=black)
- p1=plot(vsr and leveluphi ? leveluphi : na, title="S/R LevelHi",style=vstylee,color=color.blue)
- p2=plot(vsr and leveluplo ? leveluplo : na,title="S/R Levello",style=vstylee,color=color.blue)
- fill(p1,p2,color=color.new(color.black,50),title="S/R Background")
Advertisement
Add Comment
Please, Sign In to add comment