Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //LAZARUSBURAK
- //@version=5
- indicator("[BB] LAZARUSBURAK", shorttitle="[BB] BB", overlay=true, max_lines_count=500, max_labels_count=500, max_bars_back=500)
- hw = input(8., 'Bw')
- srcw = input(close, 'Source')
- //----
- nw = bar_index
- var lnw = array.new_line(0)
- if barstate.isfirst
- for iw = 0 to 499 by 1
- array.push(lnw, line.new(na, na, na, na))
- //----
- float y2w = na
- float y1w = na
- float y1_dw = na
- //----
- line lw = na
- label lbw = na
- if barstate.islast
- for iw = 0 to math.min(499, nw - 1) by 1
- sumw = 0.
- sumww = 0.
- for jw = 0 to math.min(499, nw - 1) by 1
- ww = math.exp(-(math.pow(iw - jw, 2) / (hw * hw * 2)))
- sumw := sumw + srcw[jw] * ww
- sumww := sumww + ww
- sumww
- y2w := sumw / sumww
- dw = y2w - y1w
- if dw > 0 and y1_dw < 0
- label.new(nw - iw + 1, srcw[iw], '๐', color=#00000000, style=label.style_label_up, size=size.huge, textcolor=#39ff14, textalign=text.align_center)
- if dw < 0 and y1_dw > 0
- label.new(nw - iw + 1, srcw[iw], '๐', color=#00000000, style=label.style_label_down, size=size.huge, textcolor=#ff1100, textalign=text.align_center)
- y1w := y2w
- y1_dw := dw
- y1_dw
- length = input.int(20, minval=1)
- src = input(close, title='Source')
- mult = input.float(2.0, minval=0.001, maxval=50, title='StdDev')
- bcolorbars = input(true, title='Color bars')
- basis = ta.sma(src, length)
- dev = mult * ta.stdev(src, length)
- upper = basis + dev
- lower = basis - dev
- // Color Bars with the tendency
- bColor = close > basis
- b2Color = close < basis
- plotshape(bcolorbars ? bColor : na, location=location.top, color=#00FF00, size=size.tiny, transp=25)
- plotshape(bcolorbars ? b2Color : na, location=location.top, color=#d82020, size=size.tiny, transp=25)
- filterBW = input(false, title='filter Bill Williams Fractals')
- showll = input(true, title='Show levels')
- showff = input(false, title='Show fractals (repaint!)')
- showdd = input(true, title='Show dots (repaint!)')
- //Variables
- loss = 0.0
- maxloss = 0.0
- equity = 0.0
- //Fractals
- isRegularFractal(mode) =>
- ret = mode == 1 ? high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and high[1] > high[0] : mode == -1 ? low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0] : false
- ret
- isBWFractal(mode) =>
- ret = mode == 1 ? high[4] < high[2] and high[3] <= high[2] and high[2] >= high[1] and high[2] > high[0] : mode == -1 ? low[4] > low[2] and low[3] >= low[2] and low[2] <= low[1] and low[2] < low[0] : false
- ret
- filteredtopf = filterBW ? isRegularFractal(1) : isBWFractal(1)
- filteredbotf = filterBW ? isRegularFractal(-1) : isBWFractal(-1)
- //Triangles
- plotshape(filteredtopf and showff, title='Filtered Top Fractals', style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), offset=-2)
- plotshape(filteredbotf and showff, title='Filtered Bottom Fractals', style=shape.triangleup, location=location.belowbar, color=color.new(color.lime, 0), offset=-2)
- //Levels
- hh = 0.0
- ll = 0.0
- hh := filteredtopf ? high[2] : hh[1]
- ll := filteredbotf ? low[2] : ll[1]
- //Trend
- trend = 0
- trend := high >= hh[1] ? 1 : low <= ll[1] ? -1 : trend[1]
- //Lines
- hcol = showll and hh == hh[1] and close < hh ? color.lime : na
- lcol = showll and ll == ll[1] and close > ll ? color.red : na
- plot(hh, color=hcol)
- plot(ll, color=lcol)
- //Dots
- var line hline = na
- if hh != hh[1] and showdd
- hline := line.new(bar_index - 0, hh[0], bar_index - 2, hh[0], xloc=xloc.bar_index, extend=extend.none, style=line.style_dotted, color=color.lime, width=1)
- hline
- var line lline = na
- if ll != ll[1] and showdd
- lline := line.new(bar_index - 0, ll[0] - syminfo.mintick, bar_index - 2, ll[0] - syminfo.mintick, xloc=xloc.bar_index, extend=extend.none, style=line.style_dotted, color=color.red, width=1)
- lline
- color yellow50 = color.new(color.yellow, 50)
- ShowImbalance = input(defval=true, title='Show Imbalance')
- TopImbalance = low[2] <= open[1] and high[0] >= close[1]
- TopImbalancesize = low[2] - high[0]
- if ShowImbalance and TopImbalance and TopImbalancesize > 0
- BOX1 = box.new(left=bar_index[1], top=low[2], right=bar_index[0], bottom=high[0])
- box.set_bgcolor(BOX1, color=yellow50)
- box.set_border_color(BOX1, color=yellow50)
- // box.set_extend (BOX1,extend.right)
- BottomInbalance = high[2] >= open[1] and low[0] <= close[1]
- BottomInbalancesize = low[0] - high[2]
- if ShowImbalance and BottomInbalance and BottomInbalancesize > 0
- BOX2 = box.new(left=bar_index[1], top=low[0], right=bar_index[0], bottom=high[2])
- box.set_bgcolor(BOX2, color=yellow50)
- box.set_border_color(BOX2, color=yellow50)
- show_vp = input(true, title='--------------- Show Volume profile ------------')
- //MOD'S
- bool input_delta = input(title='Delta', defval=true)
- bool input_poc = false
- //FRAME: Y
- int input_depth = input.int(title='Depth [10; 1k]', defval=200, minval=10, maxval=1000)
- bool input_range = false
- float input_persent = 5
- bool input_log10 = false
- //FRAME: X
- int input_amp = input.int(title='Amp [10; 100]', defval=50, minval=10, maxval=100)
- int input_size = input.int(title='Dot size', defval=1, minval=1, maxval=3)
- //PALETTE
- color input_c_info = input(title='Color: Info', defval=color.new(#FFFFFF, 0)) //EM color White
- color input_c_frame = input(title='Color: Frame', defval=color.new(#617793, 0)) //EM color Palladium
- color input_c_total = input(title='Color: ฮฃ', defval=color.new(#b8c9ff, 0)) //EM color Palladium
- color input_c_plus = input(title='Color: ฮ +', defval=color.new(#d82020, 0)) //EM color Green
- color input_c_minus = input(title='Color: ฮ โ', defval=color.new(#00FF00, 0)) //EM color red
- far = input(50, 'far')
- //////////////////
- // //
- // DATA //
- // //
- //////////////////
- //// FRAME
- //ath & atl
- float FH = na
- float FL = na
- float rn = na
- //true depth
- int depth = input_depth
- //first bar time
- var int time_first = time
- //// ROWS DATA
- var R = array.new_float(50, 0) //Row (price)
- var TV = array.new_float(50, 0) //Total: Value
- var TA = array.new_int(50, 0) //Total: Amp
- var TP = array.new_bool(50, false) //Total: Peak
- float TM = 1 //Total: Max Value
- var DV = array.new_float(50, 0) //Delta: Value
- var DA = array.new_int(50, 0) //Delta: Amp
- var DP = array.new_bool(50, false) //Delta: Peak
- //// POC
- float POC = na
- float POC_DP = na
- float POC_DN = na
- //// INTERFACE
- //text
- string txt_top = input_range ? '+ ' + str.tostring(input_persent, '0.0') + ' %' : ' ' + (input_amp < 20 ? 'H โ L' : 'HIGH โ LOW')
- string txt_btm = 'โฎ ' + str.tostring(input_depth)
- //size
- var dot_size = input_size == 1 ? size.tiny : input_size == 2 ? size.small : size.normal
- //invisible
- var color c_opacity = color.new(color.white, 100)
- ////////////////////////
- // //
- // EXCEPTIONS //
- // //
- ////////////////////////
- bool exception_no_volume = nz(volume) == 0
- bool exception_excess_depth = na(close[input_depth])
- bool exception_bug_minute = timeframe.period == '1'
- //// EXCEPTION HANDLING
- //no volume
- if exception_no_volume
- txt_top := input_amp < 20 ? '๐ซ' : '๐ซ NO VOLUME'
- txt_top
- //depth correction
- if exception_excess_depth and barstate.islast
- for i = 2 to input_depth by 1
- if na(close[i])
- depth := i
- break
- txt_btm := 'โฎ ' + str.tostring(depth)
- txt_btm
- //////////////////////////
- // //
- // CALCULATIONS //
- // //
- //////////////////////////
- //// FRAME
- //ath & atl
- if input_range
- rn := hl2 * input_persent / 100
- FH := hl2 + rn
- FL := hl2 - rn
- FL
- else
- FH := ta.highest(high, depth)
- FL := ta.lowest(low, depth)
- FL
- //time_first bar time
- if barstate.isfirst
- time_first := time
- time_first
- //// FUNCTIONS
- //row axis
- float axis_step = (input_log10 ? math.log10(FH / FL) : FH - FL) / 50 //step (logarithmic or linear)
- Axis(i) => // i steps
- input_log10 ? math.pow(10, math.log10(FL) + i * axis_step) : FL + i * axis_step
- //drawing histogram
- Histogram(i) =>
- string T = input_delta and array.get(DP, i) or not input_delta and array.get(TP, i) ? 'โ ' : ' '
- if array.get(TV, i) > 0
- int D_ = array.get(DA, i)
- for j = array.get(TA, i) to 0 by 1
- T += (input_delta ? D_ > j ? 'โข' : 'ยท ' : 'โข')
- T
- else
- T := ' โง'
- T
- T
- //row color
- Color(m) =>
- input_delta and array.get(DA, m) != 0 ? array.get(DV, m) > 0 ? input_c_plus : input_c_minus : input_c_total
- //// MAIN
- if barstate.islast and not exception_no_volume and show_vp
- //rows conformity to prices
- for i = 0 to 49 by 1
- array.set(R, i, Axis(i + 0.5)) //offset row axis โ row-hight / 2
- //full depth
- for i = 0 to depth - 1 by 1
- int C = 0 //denominator
- TS = array.new_float(50, 0) //divisible volumes
- DS = array.new_float(50, 0) //divisible deltas
- //set TS & DS and denominator
- for j = 0 to 49 by 1
- float R_ = array.get(R, j)
- if high[i] > R_ and R_ > low[i]
- C += 1
- array.set(TS, j, nz(volume[i]))
- if input_delta
- array.set(DS, j, nz(volume[i]) * (close[i] > R_ ? 1 : -1))
- if C != 0
- //if High or Low out of range
- float K = 1 //cutoff factor [0; 1]
- if input_range and (high[i] > Axis(50) or low[i] < Axis(0))
- K := C / ((high[i] - low[i]) / (input_log10 ? math.pow(10, axis_step) : axis_step))
- K
- //rows value
- for j = 0 to 49 by 1
- array.set(TV, j, array.get(TV, j) + array.get(TS, j) * K / C)
- if input_delta
- array.set(DV, j, array.get(DV, j) + array.get(DS, j) * K / C)
- array.clear(TS)
- array.clear(DS)
- TM := array.max(TV)
- for i = 0 to 49 by 1
- //amplitude
- array.set(TA, i, math.floor(input_amp * array.get(TV, i) / TM))
- if not input_delta
- //peak 4 < X > 4
- float T_ = array.get(TV, i)
- bool p4 = i - 4 < 0 ? true : T_ > array.get(TV, i - 4)
- bool p3 = i - 3 < 0 ? true : T_ > array.get(TV, i - 3)
- bool p2 = i - 2 < 0 ? true : T_ > array.get(TV, i - 2)
- bool p1 = i - 1 < 0 ? true : T_ > array.get(TV, i - 1)
- bool n1 = i + 1 > 49 ? true : T_ > array.get(TV, i + 1)
- bool n2 = i + 2 > 49 ? true : T_ > array.get(TV, i + 2)
- bool n3 = i + 3 > 49 ? true : T_ > array.get(TV, i + 3)
- bool n4 = i + 4 > 49 ? true : T_ > array.get(TV, i + 4)
- array.set(TP, i, p4 and p3 and p2 and p1 and n1 and n2 and n3 and n4)
- else
- //amplitude
- array.set(DA, i, math.floor(array.get(TA, i) * math.abs(array.get(DV, i)) / array.get(TV, i)))
- //peak 4 < X > 4
- float D_ = math.abs(array.get(DV, i))
- bool p4 = i - 4 < 0 ? true : D_ > math.abs(array.get(DV, i - 4))
- bool p3 = i - 3 < 0 ? true : D_ > math.abs(array.get(DV, i - 3))
- bool p2 = i - 2 < 0 ? true : D_ > math.abs(array.get(DV, i - 2))
- bool p1 = i - 1 < 0 ? true : D_ > math.abs(array.get(DV, i - 1))
- bool n1 = i + 1 > 49 ? true : D_ > math.abs(array.get(DV, i + 1))
- bool n2 = i + 2 > 49 ? true : D_ > math.abs(array.get(DV, i + 2))
- bool n3 = i + 3 > 49 ? true : D_ > math.abs(array.get(DV, i + 3))
- bool n4 = i + 4 > 49 ? true : D_ > math.abs(array.get(DV, i + 4))
- array.set(DP, i, p4 and p3 and p2 and p1 and n1 and n2 and n3 and n4)
- //POC
- if input_poc
- float sum = 0
- float mass = 0
- for i = 0 to 49 by 1
- float V_ = array.get(TV, i)
- sum += V_
- mass += V_ * array.get(R, i)
- mass
- POC := nz(mass / sum, na)
- if input_delta and not exception_bug_minute
- float seller_sum = 0
- float seller_mass = 0
- float buyer_sum = 0
- float buyer_mass = 0
- for i = 0 to 49 by 1
- float R_ = array.get(R, i)
- float D_ = array.get(DV, i)
- seller_sum += (D_ < 0 ? D_ : 0)
- seller_mass += (D_ < 0 ? D_ * R_ : 0)
- buyer_sum += (D_ > 0 ? D_ : 0)
- buyer_mass += (D_ > 0 ? D_ * R_ : 0)
- buyer_mass
- POC_DN := nz(seller_mass / seller_sum, na)
- POC_DP := nz(buyer_mass / buyer_sum, na)
- POC_DP
- //////////////////////
- // //
- // BUILDING //
- // //
- //////////////////////
- //// POC
- var line line_POC_DN = line.new(bar_index, na, bar_index, na, style=line.style_dashed, color=input_c_minus)
- var line line_POC_DP = line.new(bar_index, na, bar_index, na, style=line.style_dashed, color=input_c_plus)
- var line line_POC = line.new(bar_index, na, bar_index, na, style=line.style_dashed, color=input_c_info)
- //// INTERFACE
- var label label_top = label.new(bar_index, FH, text=txt_top, style=label.style_label_lower_left, textcolor=input_c_info, color=c_opacity, size=size.normal)
- var label label_btm = label.new(bar_index, FL, text=txt_btm, style=label.style_label_upper_left, textcolor=input_c_info, color=c_opacity, size=size.normal)
- // FRAME
- var line line_FH = line.new(bar_index, FH, bar_index, FH, color=input_c_frame, style=line.style_dashed)
- var line line_FL = line.new(bar_index, FL, bar_index, FL, color=input_c_frame, style=line.style_dashed)
- var line line_FS = line.new(bar_index, FL, bar_index, FL, color=input_c_frame, style=line.style_dashed)
- //// HISTOGRAM
- int r1 = time_close
- float r2 = close
- string r3 = ''
- color r4 = input_c_total
- var r5 = xloc.bar_time
- var r6 = yloc.price
- color r7 = c_opacity
- var r8 = label.style_label_right
- var r9 = dot_size
- var label R01 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R02 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R03 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R04 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R05 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R06 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R07 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R08 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R09 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R10 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R11 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R12 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R13 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R14 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R15 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R16 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R17 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R18 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R19 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R20 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R21 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R22 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R23 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R24 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R25 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R26 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R27 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R28 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R29 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R30 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R31 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R32 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R33 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R34 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R35 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R36 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R37 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R38 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R39 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R40 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R41 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R42 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R43 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R44 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R45 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R46 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R47 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R48 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R49 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- var label R50 = label.new(r1, r2, text=r3, textcolor=r4, xloc=r5, yloc=r6, color=r7, style=r8, size=r9)
- //// SHIFT & REFRECH
- if barstate.islast and show_vp
- //Frame: limits
- tl = far * (time - time[1])
- int time_start = math.max(time[depth - 1], time_first)
- int time_finish = time_close + tl
- //// INTERFACE
- label.set_xloc(label_top, time_finish, xloc.bar_time)
- label.set_y(label_top, FH)
- label.set_xloc(label_btm, time_finish, xloc.bar_time)
- label.set_y(label_btm, FL)
- label.set_text(label_btm, txt_btm)
- //// POC
- line.set_xloc(line_POC, time_start, time_finish, xloc.bar_time)
- line.set_y1(line_POC, POC)
- line.set_y2(line_POC, POC)
- line.set_xloc(line_POC_DN, time_start, time_finish, xloc.bar_time)
- line.set_y1(line_POC_DN, POC_DN)
- line.set_y2(line_POC_DN, POC_DN)
- line.set_xloc(line_POC_DP, time_start, time_finish, xloc.bar_time)
- line.set_y1(line_POC_DP, POC_DP)
- line.set_y2(line_POC_DP, POC_DP)
- //// FRAME
- line.set_xloc(line_FH, time_start, time_finish, xloc.bar_time)
- line.set_y1(line_FH, FH)
- line.set_y2(line_FH, FH)
- line.set_xloc(line_FL, time_start, time_finish, xloc.bar_time)
- line.set_y1(line_FL, FL)
- line.set_y2(line_FL, FL)
- line.set_xloc(line_FS, time_start, time_start, xloc.bar_time)
- line.set_y1(line_FS, FH)
- line.set_y2(line_FS, FL)
- //// HISTOGRAM
- label.set_x(R01, time_finish)
- label.set_y(R01, array.get(R, 0))
- label.set_text(R01, Histogram(0))
- label.set_textcolor(R01, Color(0))
- label.set_x(R02, time_finish)
- label.set_y(R02, array.get(R, 1))
- label.set_text(R02, Histogram(1))
- label.set_textcolor(R02, Color(1))
- label.set_x(R03, time_finish)
- label.set_y(R03, array.get(R, 2))
- label.set_text(R03, Histogram(2))
- label.set_textcolor(R03, Color(2))
- label.set_x(R04, time_finish)
- label.set_y(R04, array.get(R, 3))
- label.set_text(R04, Histogram(3))
- label.set_textcolor(R04, Color(3))
- label.set_x(R05, time_finish)
- label.set_y(R05, array.get(R, 4))
- label.set_text(R05, Histogram(4))
- label.set_textcolor(R05, Color(4))
- label.set_x(R06, time_finish)
- label.set_y(R06, array.get(R, 5))
- label.set_text(R06, Histogram(5))
- label.set_textcolor(R06, Color(5))
- label.set_x(R07, time_finish)
- label.set_y(R07, array.get(R, 6))
- label.set_text(R07, Histogram(6))
- label.set_textcolor(R07, Color(6))
- label.set_x(R08, time_finish)
- label.set_y(R08, array.get(R, 7))
- label.set_text(R08, Histogram(7))
- label.set_textcolor(R08, Color(7))
- label.set_x(R09, time_finish)
- label.set_y(R09, array.get(R, 8))
- label.set_text(R09, Histogram(8))
- label.set_textcolor(R09, Color(8))
- label.set_x(R10, time_finish)
- label.set_y(R10, array.get(R, 9))
- label.set_text(R10, Histogram(9))
- label.set_textcolor(R10, Color(9))
- label.set_x(R11, time_finish)
- label.set_y(R11, array.get(R, 10))
- label.set_text(R11, Histogram(10))
- label.set_textcolor(R11, Color(10))
- label.set_x(R12, time_finish)
- label.set_y(R12, array.get(R, 11))
- label.set_text(R12, Histogram(11))
- label.set_textcolor(R12, Color(11))
- label.set_x(R13, time_finish)
- label.set_y(R13, array.get(R, 12))
- label.set_text(R13, Histogram(12))
- label.set_textcolor(R13, Color(12))
- label.set_x(R14, time_finish)
- label.set_y(R14, array.get(R, 13))
- label.set_text(R14, Histogram(13))
- label.set_textcolor(R14, Color(13))
- label.set_x(R15, time_finish)
- label.set_y(R15, array.get(R, 14))
- label.set_text(R15, Histogram(14))
- label.set_textcolor(R15, Color(14))
- label.set_x(R16, time_finish)
- label.set_y(R16, array.get(R, 15))
- label.set_text(R16, Histogram(15))
- label.set_textcolor(R16, Color(15))
- label.set_x(R17, time_finish)
- label.set_y(R17, array.get(R, 16))
- label.set_text(R17, Histogram(16))
- label.set_textcolor(R17, Color(16))
- label.set_x(R18, time_finish)
- label.set_y(R18, array.get(R, 17))
- label.set_text(R18, Histogram(17))
- label.set_textcolor(R18, Color(17))
- label.set_x(R19, time_finish)
- label.set_y(R19, array.get(R, 18))
- label.set_text(R19, Histogram(18))
- label.set_textcolor(R19, Color(18))
- label.set_x(R20, time_finish)
- label.set_y(R20, array.get(R, 19))
- label.set_text(R20, Histogram(19))
- label.set_textcolor(R20, Color(19))
- label.set_x(R21, time_finish)
- label.set_y(R21, array.get(R, 20))
- label.set_text(R21, Histogram(20))
- label.set_textcolor(R21, Color(20))
- label.set_x(R22, time_finish)
- label.set_y(R22, array.get(R, 21))
- label.set_text(R22, Histogram(21))
- label.set_textcolor(R22, Color(21))
- label.set_x(R23, time_finish)
- label.set_y(R23, array.get(R, 22))
- label.set_text(R23, Histogram(22))
- label.set_textcolor(R23, Color(22))
- label.set_x(R24, time_finish)
- label.set_y(R24, array.get(R, 23))
- label.set_text(R24, Histogram(23))
- label.set_textcolor(R24, Color(23))
- label.set_x(R25, time_finish)
- label.set_y(R25, array.get(R, 24))
- label.set_text(R25, Histogram(24))
- label.set_textcolor(R25, Color(24))
- label.set_x(R26, time_finish)
- label.set_y(R26, array.get(R, 25))
- label.set_text(R26, Histogram(25))
- label.set_textcolor(R26, Color(25))
- label.set_x(R27, time_finish)
- label.set_y(R27, array.get(R, 26))
- label.set_text(R27, Histogram(26))
- label.set_textcolor(R27, Color(26))
- label.set_x(R28, time_finish)
- label.set_y(R28, array.get(R, 27))
- label.set_text(R28, Histogram(27))
- label.set_textcolor(R28, Color(27))
- label.set_x(R29, time_finish)
- label.set_y(R29, array.get(R, 28))
- label.set_text(R29, Histogram(28))
- label.set_textcolor(R29, Color(28))
- label.set_x(R30, time_finish)
- label.set_y(R30, array.get(R, 29))
- label.set_text(R30, Histogram(29))
- label.set_textcolor(R30, Color(29))
- label.set_x(R31, time_finish)
- label.set_y(R31, array.get(R, 30))
- label.set_text(R31, Histogram(30))
- label.set_textcolor(R31, Color(30))
- label.set_x(R32, time_finish)
- label.set_y(R32, array.get(R, 31))
- label.set_text(R32, Histogram(31))
- label.set_textcolor(R32, Color(31))
- label.set_x(R33, time_finish)
- label.set_y(R33, array.get(R, 32))
- label.set_text(R33, Histogram(32))
- label.set_textcolor(R33, Color(32))
- label.set_x(R34, time_finish)
- label.set_y(R34, array.get(R, 33))
- label.set_text(R34, Histogram(33))
- label.set_textcolor(R34, Color(33))
- label.set_x(R35, time_finish)
- label.set_y(R35, array.get(R, 34))
- label.set_text(R35, Histogram(34))
- label.set_textcolor(R35, Color(34))
- label.set_x(R36, time_finish)
- label.set_y(R36, array.get(R, 35))
- label.set_text(R36, Histogram(35))
- label.set_textcolor(R36, Color(35))
- label.set_x(R37, time_finish)
- label.set_y(R37, array.get(R, 36))
- label.set_text(R37, Histogram(36))
- label.set_textcolor(R37, Color(36))
- label.set_x(R38, time_finish)
- label.set_y(R38, array.get(R, 37))
- label.set_text(R38, Histogram(37))
- label.set_textcolor(R38, Color(37))
- label.set_x(R39, time_finish)
- label.set_y(R39, array.get(R, 38))
- label.set_text(R39, Histogram(38))
- label.set_textcolor(R39, Color(38))
- label.set_x(R40, time_finish)
- label.set_y(R40, array.get(R, 39))
- label.set_text(R40, Histogram(39))
- label.set_textcolor(R40, Color(39))
- label.set_x(R41, time_finish)
- label.set_y(R41, array.get(R, 40))
- label.set_text(R41, Histogram(40))
- label.set_textcolor(R41, Color(40))
- label.set_x(R42, time_finish)
- label.set_y(R42, array.get(R, 41))
- label.set_text(R42, Histogram(41))
- label.set_textcolor(R42, Color(41))
- label.set_x(R43, time_finish)
- label.set_y(R43, array.get(R, 42))
- label.set_text(R43, Histogram(42))
- label.set_textcolor(R43, Color(42))
- label.set_x(R44, time_finish)
- label.set_y(R44, array.get(R, 43))
- label.set_text(R44, Histogram(43))
- label.set_textcolor(R44, Color(43))
- label.set_x(R45, time_finish)
- label.set_y(R45, array.get(R, 44))
- label.set_text(R45, Histogram(44))
- label.set_textcolor(R45, Color(44))
- label.set_x(R46, time_finish)
- label.set_y(R46, array.get(R, 45))
- label.set_text(R46, Histogram(45))
- label.set_textcolor(R46, Color(45))
- label.set_x(R47, time_finish)
- label.set_y(R47, array.get(R, 46))
- label.set_text(R47, Histogram(46))
- label.set_textcolor(R47, Color(46))
- label.set_x(R48, time_finish)
- label.set_y(R48, array.get(R, 47))
- label.set_text(R48, Histogram(47))
- label.set_textcolor(R48, Color(47))
- label.set_x(R49, time_finish)
- label.set_y(R49, array.get(R, 48))
- label.set_text(R49, Histogram(48))
- label.set_textcolor(R49, Color(48))
- label.set_x(R50, time_finish)
- label.set_y(R50, array.get(R, 49))
- label.set_text(R50, Histogram(49))
- label.set_textcolor(R50, Color(49))
- // INPUTS
- i_time = input.session ('0000-0001:1234567', "New York", tooltip="Different exchanges will have difference time zones so change accordingly.")
- i_vline = input.bool (false, "VLine", inline="in3")
- i_vcol = input.color (#00b9d0, "", inline="in3")
- i_txtcol = input.color (#0098ff, "โโText color", inline="in3")
- i_vstyle = input.string ("Solid", "Style", options=["Solid", "Dotted", "Dashed"])
- i_hline = input.bool (true, "HLine", inline="in1")
- i_linecol = input.color (#0064ff, "", inline="in1")
- i_linestyle = input.string ("Dotted", "โ", options=["Solid", "Dotted", "Dashed"], inline="in1")
- i_ex = input.string ("None", "Extend", options=["None", "+1 Day", "Right", "Both"] )
- // MISC
- nymid = time ("1", i_time)
- linestyle = i_linestyle == "Solid" ? line.style_solid : i_linestyle == "Dotted" ? line.style_dotted : line.style_dashed
- vstyle = i_vstyle == "Solid" ? line.style_solid : i_vstyle == "Dotted" ? line.style_dotted : line.style_dashed
- ex = i_ex == "None" ? extend.none : i_ex == "+1 Day" ? extend.none : i_ex == "Right" ? extend.right : extend.both
- htime = i_ex == "+1 Day" ? 172800000 : 86400000
- // CALC
- var openprice = 0.0
- if nymid
- if not nymid[1]
- openprice := open
- else
- openprice := math.max(open, openprice)
- // OBJECTS
- var label lb = na
- if openprice != openprice[1] and i_hline
- var line lne = na
- line.set_x2(lne, nymid)
- line.set_extend(lne, extend.none)
- lne := line.new(nymid, openprice, nymid + htime, openprice, xloc.bar_time, ex, i_linecol, linestyle, 2)
- lb := label.new(nymid + htime, openprice, "NY Midnight Open | " + str.tostring(math.round_to_mintick(openprice)), xloc.bar_time, yloc.price, na, label.style_none, i_txtcol)
- label.delete(lb[1])
- if i_vline
- line.new(nymid, high, nymid, low, xloc.bar_time, extend.both, i_vcol, vstyle, 1)
- // END
- includeSymbol1 = input.bool(true, 'Include Symbol 1?', group='Symbols')
- useCurrentChartAsSymbol1 = input.bool(true, 'Use current chart\'s symbol as Symbol 1', group='Symbols')
- symbol1 = input.string('', 'Symbol 1', group='Symbols')
- includeSymbol2 = input.bool(false, 'Include Symbol 2?', group='Symbols')
- symbol2 = input.string('', 'Symbol 2', group='Symbols')
- includeSymbol3 = input.bool(false, 'Include Symbol 3?', group='Symbols')
- symbol3 = input.string('', 'Symbol 3', group='Symbols')
- includeSymbol4 = input.bool(false, 'Include Symbol 4?', group='Symbols')
- symbol4 = input.string('', 'Symbol 4', group='Symbols')
- // Kill Switch for if no instruments were selected
- killSwitch = not includeSymbol1 and not includeSymbol2 and not includeSymbol3 and not includeSymbol4
- includeRsi = input.bool(true, 'Include RSI', group='RSI')
- rsiLength = input.int(7, 'RSI Length', group='RSI')
- rsiBullThreshold = input.int(50, 'RSI Bull Threshold', group='RSI')
- rsiBearThreshold = input.int(50, 'RSI Bear Threshold', group='RSI')
- includeStoch = input.bool(true, 'Include Stochastic', group='Stochastic')
- periodK = input.int(14, title='%K Length', minval=1, group='Stochastic')
- smoothK = input.int(1, title='%K Smoothing', minval=1, group='Stochastic')
- periodD = input.int(3, title='%D Smoothing', minval=1, group='Stochastic')
- useStochD = input.bool(false, 'Use Stochastic D instead of K', group='Stochastic')
- stochBullThreshold = input.int(50, 'Stochastic Bull Threshold', group='Stochastic')
- stochBearThreshold = input.int(50, 'Stochastic Bear Threshold', group='Stochastic')
- includeMacdHist = input.bool(true, 'Include MACD Histogram', group='MACD')
- macdFastLength = input.int(12, 'MACD Fast Length', group='MACD')
- macdSlowLength = input.int(26, 'MACD Slow Length', group='MACD')
- macdSignalLength = input.int(9, 'MACD Signal Length', group='MACD')
- // Kill Switch for if no indicators are selected
- confluenceKillSwitch = not includeMacdHist and not includeRsi and not includeStoch
- stochastic(periodK, smoothK, periodD) =>
- kss = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
- d = ta.sma(kss, periodD)
- output = useStochD ? d : kss
- output
- confluence() =>
- [_, _, histLine] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength)
- rsiLine = ta.rsi(close, rsiLength)
- stochLine = stochastic(periodK, smoothK, periodD)
- histBull = includeMacdHist ? histLine > 0 : true
- histBear = includeMacdHist ? histLine <= 0 : true
- rsiBull = includeRsi ? rsiLine > rsiBullThreshold : true
- rsiBear = includeRsi ? rsiLine < rsiBearThreshold : true
- stochBull = includeStoch ? stochLine > stochBullThreshold : true
- stochBear = includeStoch ? stochLine < stochBearThreshold : true
- signal = histBull and rsiBull and stochBull and not confluenceKillSwitch ? 1 : histBear and rsiBear and stochBear and not confluenceKillSwitch ? -1 : 0
- signal
- confluenceSymbol1 = useCurrentChartAsSymbol1 ? confluence() : request.security(symbol1, '', confluence())
- confluenceSymbol2 = request.security(symbol2, '', confluence())
- confluenceSymbol3 = request.security(symbol3, '', confluence())
- confluenceSymbol4 = request.security(symbol4, '', confluence())
- symbol1BullFilter = includeSymbol1 ? confluenceSymbol1 == 1 : true
- symbol1BearFilter = includeSymbol1 ? confluenceSymbol1 == -1 : true
- symbol2BullFilter = includeSymbol2 ? confluenceSymbol2 == 1 : true
- symbol2BearFilter = includeSymbol2 ? confluenceSymbol2 == -1 : true
- symbol3BullFilter = includeSymbol3 ? confluenceSymbol3 == 1 : true
- symbol3BearFilter = includeSymbol3 ? confluenceSymbol3 == -1 : true
- symbol4BullFilter = includeSymbol4 ? confluenceSymbol4 == 1 : true
- symbol4BearFilter = includeSymbol4 ? confluenceSymbol4 == -1 : true
- bullish = symbol1BullFilter and symbol2BullFilter and symbol3BullFilter and symbol4BullFilter and not killSwitch
- bearish = symbol1BearFilter and symbol2BearFilter and symbol3BearFilter and symbol4BearFilter and not killSwitch
- plotshape(symbol1BearFilter ? bearish : na, title='bearish', color=#d82020, location=location.bottom, size=size.tiny, transp=25)
- plotshape(symbol1BullFilter ? bullish : na, title='bullish', color=#00FF00, location=location.bottom, size=size.tiny, transp=25)
- firstLookback = input.int(title='Max lookback for bullish lowest low pivot point', defval=10, minval=1, maxval=100)
- lowerLowLookback = input.int(title='Max lookback bullish for divergence', defval=30, minval=5, maxval=100)
- bearFirstLookback = input.int(title='Max lookback for bearish highest high pivot point', defval=10, minval=1, maxval=100)
- bearLowerLowLookback = input.int(title='Max lookback bearish for divergence', defval=30, minval=5, maxval=100)
- leftBars = 2
- rightBars = 2
- //
- // BULLISH
- //
- pm = ta.pivotlow(low, leftBars, rightBars)
- [m, ms, mh] = ta.macd(close, 12, 26, 9)
- buy = 0
- p1m = 0
- p2m = 0
- q = 0
- for i = 1 to firstLookback by 1
- if q
- break
- if p1m == 0
- if pm[i] != 0
- confimationCandle = low[0] > high[i + rightBars]
- previousIsConfirmationCandle = low[1] > high[i + rightBars]
- if confimationCandle and not previousIsConfirmationCandle
- p1m := i + rightBars // We found the current low
- continue
- if p1m != 0
- for j = 1 + i to lowerLowLookback + i by 1
- if q
- break
- if p2m == 0
- if pm[j] != 0
- p2m := j + rightBars // We found the previous low
- continue
- if p2m != 0
- lowerLows = low[p1m] < low[p2m]
- if not lowerLows
- q := 1
- break
- if lowerLows
- macdDivergence = m[p1m] > m[p2m]
- lowCrossesSlope = 0
- if macdDivergence
- x1 = p2m
- x2 = p1m
- y1 = low[p2m]
- y2 = low[p1m]
- // The lower lows line should not be broken by price
- for x = p1m to p2m by 1
- y = (y2 - y1) / (x2 - x1) * (x - x1) + y1
- if low[x] < y
- lowCrossesSlope := 1
- break
- if lowCrossesSlope == 0 and macdDivergence
- line.new(x1=bar_index[p2m], y1=low[p2m], x2=bar_index[p1m], y2=low[p1m], width=6, color=color.green)
- buy := 1
- q := -1
- break
- else
- p2m := 0 // Try the next previous low
- continue
- //
- // BEARISH
- //
- hm = ta.pivothigh(high, leftBars, rightBars)
- sell = 0
- h1 = 0
- h2 = 0
- qBear = 0
- for i = 1 to firstLookback by 1
- if qBear
- break
- if h1 == 0
- if hm[i] != 0
- confimationCandle = high[0] < low[i + rightBars]
- previousIsConfirmationCandle = high[1] < low[i + rightBars]
- if confimationCandle and not previousIsConfirmationCandle
- h1 := i + rightBars // We found the current high
- continue
- if h1 != 0
- for j = 1 + i to lowerLowLookback + i by 1
- if qBear
- break
- if h2 == 0
- if hm[j] != 0
- h2 := j + rightBars // We found the previous high
- continue
- if h2 != 0
- higherHighs = high[h1] > high[h2]
- if not higherHighs
- qBear := 1
- break
- if higherHighs
- macdDivergence = m[h1 - rightBars] < m[h2 - rightBars]
- highCrossesSlope = 0
- if macdDivergence
- x1 = h2
- x2 = h1
- y1 = high[h2]
- y2 = high[h1]
- // The higher highs line should not be broken by price
- for x = h1 to h2 by 1
- y = (y2 - y1) / (x2 - x1) * (x - x1) + y1
- if high[x] > y
- highCrossesSlope := 1
- break
- if highCrossesSlope == 0 and macdDivergence
- line.new(x1=bar_index[h2], y1=high[h2], x2=bar_index[h1], y2=high[h1], width=6, color=color.red)
- sell := 1
- qBear := -1
- break
- else
- h2 := 0 // Try the next previous low
- continue
Advertisement
Add Comment
Please, Sign In to add comment