Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator('Ultimate Cypher A', overlay=true, max_bars_back=1000, max_lines_count=500, max_labels_count=500,max_boxes_count=500)
- import HeWhoMustNotBeNamed/eHarmonicpatternsExtended/3 as hp
- import HeWhoMustNotBeNamed/arrayutils/17 as pa
- import HeWhoMustNotBeNamed/mZigzag/5 as zigzag
- import HeWhoMustNotBeNamed/_matrix/2 as ma
- avoidOverlap = input.bool(false, 'Suppress Overlap', group='Generic')
- var themeColors =array.from(
- color.rgb(251, 244, 109),
- color.rgb(141, 186, 81),
- color.rgb(74, 159, 245),
- color.rgb(255, 153, 140),
- color.rgb(255, 149, 0),
- color.rgb(0, 234, 211),
- color.rgb(167, 153, 183),
- color.rgb(255, 210, 113),
- color.rgb(119, 217, 112),
- color.rgb(95, 129, 228),
- color.rgb(235, 146, 190),
- color.rgb(198, 139, 89),
- color.rgb(200, 149, 149),
- color.rgb(196, 182, 182),
- color.rgb(255, 190, 15),
- color.rgb(192, 226, 24),
- color.rgb(153, 140, 235),
- color.rgb(206, 31, 107),
- color.rgb(251, 54, 64),
- color.rgb(194, 255, 217),
- color.rgb(255, 219, 197),
- color.rgb(121, 180, 183)
- )
- depthhh=input.int(10, title='depth', group='Zigzag')
- showZigZag1 = input.bool(true, title='L1', group='Zigzag', inline='z1')
- zigzag1Length = input.int(5, step=5, minval=3, title='', group='Zigzag', inline='z1')
- showZigZag2 = input.bool(true, title='L2', group='Zigzag', inline='z1')
- zigzag2Length = input.int(8, step=5, minval=3, title='', group='Zigzag', inline='z1')
- showZigZag3 = input.bool(true, title='L3', group='Zigzag', inline='z2')
- zigzag3Length = input.int(13, step=5, minval=3, title='', group='Zigzag', inline='z2')
- showZigZag4 = input.bool(true, title='L4', group='Zigzag', inline='z2')
- zigzag4Length = input.int(21, step=5, minval=3, title='', group='Zigzag', inline='z2')
- showTAG=input(true, title='Show TAG', group='Display')
- showXABCD = input.bool(false, title='Show XABCD', group='Display', inline='showHide')
- showRatios = input.bool(true, title='Show Ratios', group='Display', inline='showHide')
- fillMajorTriangles = input.bool(true, title="Fill XAB/BCD", group="Display", inline="fill1")
- majorFillTransparency = input.int(90, step=5, title="", group="Display", inline="fill1")
- showPRZ=input(false,group='Miscellaneous')
- errorPercent = input.int(8, group="Miscellaneous")
- przType = input.string("XAD Range", "PRZ Type", options=["XAD Range", "BCD+XAD Range"], group='Miscellaneous')
- useCombinedPrz = (przType == "BCD+XAD Range")
- classic = input.bool(true, title="Classic Patterns", group="Category", inline="ca")
- anti = input.bool(true, title="Anti/Alternate Patterns", group="Category", inline="ca")
- nonStandard = input.bool(true, title="Nonstandard", group="Category", inline="ca")
- gartley = input.bool(true, title='Gartley ', group='Classic Patterns', inline="c1")
- bat = input.bool(true, title='Bat ', group='Classic Patterns', inline="c1")
- butterfly = input.bool(true, title='Butterfly ', group='Classic Patterns', inline="c1")
- crab = input.bool(true, title='Crab', group='Classic Patterns', inline="c1")
- deepCrab = input.bool(true, title='Deep Crab ', group='Classic Patterns', inline="c2")
- cypher = input.bool(true, title='Cypher ', group='Classic Patterns', inline="c2")
- shark = input.bool(true, title='Shark ', group='Classic Patterns', inline="c2")
- nenStar = input.bool(true, title='Nenstar', group='Classic Patterns', inline="c2")
- antiNenStar = input.bool(true, title='Anti Nenstar ', group='Anti Patterns', inline="a1")
- antiShark = input.bool(true, title='Anti Shark', group='Anti Patterns', inline="a1")
- antiCypher = input.bool(true, title='Anti Cypher ', group='Anti Patterns', inline="a1")
- antiCrab = input.bool(true, title='Anti Crab', group='Anti Patterns', inline="a1")
- antiButterfly = input.bool(true, title='Anti Butterfly', group='Anti Patterns', inline="a2")
- antiBat = input.bool(true, title='Anti Bat ', group='Anti Patterns', inline="a2")
- antiGartley = input.bool(true, title='Anti Gartley', group='Anti Patterns', inline="a2")
- navarro200 = input.bool(true, title='Navarro 200', group='Anti Patterns', inline="a2")
- fiveZero = input.bool(true, title='Five Zero', group='Non Standard', inline="a1")
- threeDrives = input.bool(true, title='Three Drives', group='Non Standard', inline="a1")
- whiteSwann = input.bool(true, title='White Swann', group='Non Standard', inline="a1")
- blackSwann = input.bool(true, title='Black Swann', group='Non Standard', inline="a1")
- seaPony = input.bool(true, title='Sea Pony', group='Non Standard', inline="a2")
- leonardo = input.bool(true, title='Leonardo', group='Non Standard', inline="a2")
- oneTwoOne = input.bool(true, title='121', group='Non Standard', inline="a2")
- snorm = input.bool(true, title='Snorm', group='Non Standard', inline="a2")
- totalPattern = input.bool(false, title='Total', group='Non Standard', inline="a2")
- NUMBER_OF_PATTERNS = 25
- var pivotBarMatrix = matrix.new<int>()
- enableGartley = classic and gartley
- enableBat = classic and bat
- enableButterfly = classic and butterfly
- enableCrab = classic and crab
- enableDeepCrab = classic and deepCrab
- enableCypher = classic and cypher
- enableShark = classic and shark
- enableNenStar = classic and nenStar
- enableAntiNenStar = anti and antiNenStar
- enableAntiShark = anti and antiShark
- enableAntiCypher = anti and antiCypher
- enableAntiCrab = anti and antiCrab
- enableAntiButterfly = anti and antiButterfly
- enableAntiBat = anti and antiBat
- enableAntiGartley = anti and antiGartley
- enableNavarro200 = anti and navarro200
- enableFiveZero = nonStandard and fiveZero
- enableThreeDrives = nonStandard and threeDrives
- enableWhiteSwann = nonStandard and whiteSwann
- enableBlackSwann = nonStandard and blackSwann
- enableSeaPony = nonStandard and seaPony
- enableLeonardo = nonStandard and leonardo
- enableOneTwoOne = nonStandard and oneTwoOne
- enableSnorm = nonStandard and snorm
- enableTotal = nonStandard and totalPattern
- var zigzagpivots1 = array.new_float(0)
- var zigzagpivotbars1 = array.new_int(0)
- var zigzagpivotdirs1 = array.new_int(0)
- var zigzagpivots2 = array.new_float(0)
- var zigzagpivotbars2 = array.new_int(0)
- var zigzagpivotdirs2 = array.new_int(0)
- var zigzagpivots3 = array.new_float(0)
- var zigzagpivotbars3 = array.new_int(0)
- var zigzagpivotdirs3 = array.new_int(0)
- var zigzagpivots4 = array.new_float(0)
- var zigzagpivotbars4 = array.new_int(0)
- var zigzagpivotdirs4 = array.new_int(0)
- var wmlines1 = array.new_line(8)
- var wmtype1 = array.new_int(2, 1)
- var wmLabels1 = array.new_bool(21, false)
- var wmLabel1 = array.new_label(1)
- var wmlines2 = array.new_line(8)
- var wmtype2 = array.new_int(2, 1)
- var wmLabels2 = array.new_bool(21, false)
- var wmLabel2 = array.new_label(1)
- var wmlines3 = array.new_line(8)
- var wmtype3 = array.new_int(2, 1)
- var wmLabels3 = array.new_bool(21, false)
- var wmLabel3 = array.new_label(1)
- var wmlines4 = array.new_line(8)
- var wmtype4 = array.new_int(2, 1)
- var wmLabels4 = array.new_bool(21, false)
- var wmLabel4 = array.new_label(1)
- flags = array.new_bool()
- array.push(flags, enableGartley)
- array.push(flags, enableCrab)
- array.push(flags, enableDeepCrab)
- array.push(flags, enableBat)
- array.push(flags, enableButterfly)
- array.push(flags, enableShark)
- array.push(flags, enableCypher)
- array.push(flags, enableNenStar)
- array.push(flags, enableAntiNenStar)
- array.push(flags, enableAntiShark)
- array.push(flags, enableAntiCypher)
- array.push(flags, enableAntiCrab)
- array.push(flags, enableAntiButterfly)
- array.push(flags, enableAntiBat)
- array.push(flags, enableAntiGartley)
- array.push(flags, enableNavarro200)
- array.push(flags, enableFiveZero)
- array.push(flags, enableThreeDrives)
- array.push(flags, enableWhiteSwann)
- array.push(flags, enableBlackSwann)
- array.push(flags, enableSeaPony)
- array.push(flags, enableLeonardo)
- array.push(flags, enableOneTwoOne)
- array.push(flags, enableSnorm)
- array.push(flags, enableTotal)
- maxPatternsReference = 10
- var aBarArray = array.new_int()
- var bBarArray = array.new_int()
- var cBarArray = array.new_int()
- var dBarArray = array.new_int()
- var xBarArray = array.new_int()
- get_prz_range(x, a, b, c, patterns, errorPercent, prc_entry=0, prc_stop=0)=>
- [boxStart, boxEnd] = if useCombinedPrz
- hp.get_prz_range(x, a, b, c, patterns, errorPercent, prc_entry, prc_stop)
- else
- hp.get_prz_range_xad(x, a, b, c, patterns, errorPercent, prc_entry, prc_stop)
- [boxStart, boxEnd]
- f_draw_entry_box(y1, y2, x1, linecolor, labelColor, labelText) =>
- x2 = x1 + 20
- y = (y1 + y2) / 2
- xloc = xloc.bar_index
- transp = 85
- entryBox = box.new(x1, y1, x2, y2, linecolor, 1, line.style_dotted, xloc=xloc, bgcolor=color.new(labelColor, transp), text=labelText,
- text_color=color.white, text_size=size.small)
- entryBox
- f_draw_pattern_line(y1, y2, x1, x2, lineColor, width, style) =>
- targetLine = line.new(y1=y1, y2=y2, x1=x1, x2=x2, color=lineColor, width=width, style=style)
- targetLine
- f_draw_pattern_label(y, x, txt, textcolor, style, yloc, size) =>
- targetLabel = label.new(y=y, x=x, text=txt, textcolor=textcolor, style=style, yloc=yloc, size=size)
- targetLabel
- draw_xabcd(x, a, b, c, d, xBar, aBar, bBar, cBar, dBar, dir, labelColor, patterns) =>
- hasPatterns = array.includes(patterns, true),
- isCypher = array.get(patterns, 6)
- if(hasPatterns)
- gap = ta.tr/10
- xLabel = showXABCD?f_draw_pattern_label(y=(dir>0?x-gap:x+gap), x=xBar, txt='X', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
- aLabel = showXABCD?f_draw_pattern_label(y=(dir>0?a+gap:a-gap), x=aBar, txt='A', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
- bLabel = showXABCD?f_draw_pattern_label(y=(dir>0?b-gap:b+gap), x=bBar, txt='B', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
- cLabel = showXABCD?f_draw_pattern_label(y=(dir>0?c+gap:c-gap), x=cBar, txt='C', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
- dLabel = showXABCD?f_draw_pattern_label(y=(dir>0?d-gap:d+gap), x=dBar, txt='D', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
- xabRatio = math.round(math.abs(a - b) / math.abs(x - a), 3)
- xabRatioBar = (xBar + bBar) / 2
- abcRatio = math.round(math.abs(b - c) / math.abs(a - b), 3)
- abcRatioBar = (aBar + cBar) / 2
- bcdRatio = math.round(math.abs(c - d) / math.abs(b - c), 3)
- bcdRatioBar = (bBar + dBar) / 2
- xadRatio = math.round(math.abs(a - d) / math.abs(x - a), 3)
- xadRatioBar = (xBar + dBar) / 2
- axcRatio = math.round(math.abs(x - c) / math.abs(x - a), 3)
- xcdRatio = math.round(math.abs(d - c) / math.abs(x - c), 3)
- xabRatioPrice = (x+b)/2
- abcRatioPrice = (a+c)/2
- bcdRatioPrice = (b+d)/2
- xadRatioPrice = (x+d)/2
- abcRatioLabelText = str.tostring(abcRatio) + '(ABC)' + (isCypher ? '\n' + str.tostring(axcRatio) + '(AXC)' : '')
- xadRatioLabelText = str.tostring(xadRatio) + '(XAD)' + (isCypher ? '\n' + str.tostring(xcdRatio) + '(XCD)' : '')
- xabLabel = showRatios and showXABCD?f_draw_pattern_label(y=xabRatioPrice, x=xabRatioBar, txt=str.tostring(xabRatio) + '(XAB)', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
- abcLabel = showRatios and showXABCD?f_draw_pattern_label(y=abcRatioPrice, x=abcRatioBar, txt=abcRatioLabelText, textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
- bcdLabel = showRatios and showXABCD?f_draw_pattern_label(y=bcdRatioPrice, x=bcdRatioBar, txt=str.tostring(bcdRatio) + '(BCD)', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
- xadLabel = showRatios and showXABCD?f_draw_pattern_label(y=xadRatioPrice, x=xadRatioBar, txt=xadRatioLabelText, textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
- xa = showXABCD?f_draw_pattern_line(y1=x, y2=a, x1=xBar, x2=aBar, lineColor=labelColor, width=1, style=line.style_solid):na
- ab = showXABCD?f_draw_pattern_line(y1=a, y2=b, x1=aBar, x2=bBar, lineColor=labelColor, width=1, style=line.style_solid):na
- bc = showXABCD?f_draw_pattern_line(y1=b, y2=c, x1=bBar, x2=cBar, lineColor=labelColor, width=1, style=line.style_solid):na
- cd = showXABCD?f_draw_pattern_line(y1=c, y2=d, x1=cBar, x2=dBar, lineColor=labelColor, width=1, style=line.style_solid):na
- xb = showXABCD?f_draw_pattern_line(y1=x, y2=b, x1=xBar, x2=bBar, lineColor=labelColor, width=1, style=line.style_dashed):na
- bd = showXABCD?f_draw_pattern_line(y1=b, y2=d, x1=bBar, x2=dBar, lineColor=labelColor, width=1, style=line.style_dashed):na
- ac = showXABCD?f_draw_pattern_line(y1=a, y2=c, x1=aBar, x2=cBar, lineColor=labelColor, width=1, style=line.style_dotted):na
- xd = showXABCD?f_draw_pattern_line(y1=x, y2=d, x1=xBar, x2=dBar, lineColor=labelColor, width=1, style=line.style_dotted):na
- if(fillMajorTriangles and hasPatterns)
- xaab = linefill.new(xa, ab, color.new(labelColor, majorFillTransparency))
- xbab = linefill.new(xb, ab, color.new(labelColor, majorFillTransparency))
- bccd = linefill.new(bc, cd, color.new(labelColor, majorFillTransparency))
- bdcd = linefill.new(bd, cd, color.new(labelColor, majorFillTransparency))
- [xa,ab,bc,cd,xb,bd,ac,xd,xLabel,aLabel,bLabel,cLabel,dLabel,xabLabel,abcLabel,bcdLabel,xadLabel]
- patternLabels = hp.getSupportedPatterns()
- find_pattern(zigzagpivots, zigzagpivotbars, startIndex, lastDir, x, a, b, c, d,
- xBar, aBar, bBar, cBar, dBar)=>
- existingPattern=false
- patterns = hp.isHarmonicPattern(x, a, b, c, d, flags, errorPercent = errorPercent)
- basicCondition = array.includes(patterns,true)
- for i=0 to matrix.rows(pivotBarMatrix) > 0? matrix.rows(pivotBarMatrix)-1 : na
- commonPivotsCount = (xBar == matrix.get(pivotBarMatrix, i, 0) ? 1 : 0) +
- (aBar == matrix.get(pivotBarMatrix, i, 1) ? 1 : 0) +
- (bBar == matrix.get(pivotBarMatrix, i, 2) ? 1 : 0) +
- (cBar == matrix.get(pivotBarMatrix, i, 3) ? 1 : 0) +
- (dBar == matrix.get(pivotBarMatrix, i, 4) ? 1 : 0)
- if ( commonPivotsCount >=3 ) or (avoidOverlap and xBar >= matrix.get(pivotBarMatrix, i, 0) and xBar <= matrix.get(pivotBarMatrix, i, 4))
- existingPattern := true
- break
- if(not existingPattern)
- zgColor = array.pop(themeColors)
- array.unshift(themeColors, zgColor)
- if(basicCondition)
- lbl = pa.getLabel(patterns, patternLabels)
- [xa,ab,bc,cd,xb,bd,ac,xd,xLabel,aLabel,bLabel,cLabel,dLabel,xabLabel,abcLabel,bcdLabel,xadLabel]=draw_xabcd(x, a, b, c, d, xBar, aBar, bBar, cBar, dBar, lastDir, zgColor, patterns)
- [dStart, dEnd] = get_prz_range(x, a, b, c, patterns, errorPercent)
- boxxx=showPRZ?f_draw_entry_box(dStart, dEnd, dBar+5, zgColor, zgColor, lbl):na
- dir=c-d>0?1:-1
- if(dir==1 and close<dEnd) or (dir==-1 and close>dStart)
- line.delete(xa)
- line.delete(ab)
- line.delete(bc)
- line.delete(cd)
- line.delete(xb)
- line.delete(bd)
- line.delete(ac)
- line.delete(xd)
- label.delete(xLabel)
- label.delete(aLabel)
- label.delete(bLabel)
- label.delete(cLabel)
- label.delete(dLabel)
- label.delete(xabLabel)
- label.delete(abcLabel)
- label.delete(bcdLabel)
- label.delete(xadLabel)
- box.delete(boxxx)
- if(showTAG)
- label.new(y=(c>d?d-ta.tr/5:d+ta.tr/5), x=dBar , color=c>d?color.new(color.green,50):color.new(color.red,50),style=c<d ? label.style_triangledown : label.style_triangleup, size=size.tiny)
- scan_patterns(startIndex, newPivot, zigzagpivots, zigzagpivotbars, zigzagpivotdirs, lastdBar)=>
- length = array.size(zigzagpivots)
- numberOfPivots=5
- newLastdBar = lastdBar
- if(length >= startIndex+numberOfPivots and newPivot)
- d = array.get(zigzagpivots, startIndex)
- dBar = array.get(zigzagpivotbars, startIndex)
- lastDir = array.get(zigzagpivotdirs, startIndex)
- if(dBar!=lastdBar)
- newLastdBar := dBar
- c = array.get(zigzagpivots, startIndex+1)
- cBar = array.get(zigzagpivotbars, startIndex+1)
- b = array.get(zigzagpivots, startIndex+2)
- bBar = array.get(zigzagpivotbars, startIndex+2)
- a = array.get(zigzagpivots, startIndex+3)
- aBar = array.get(zigzagpivotbars, startIndex+3)
- x = array.get(zigzagpivots, startIndex+4)
- xBar = array.get(zigzagpivotbars, startIndex+4)
- find_pattern(zigzagpivots, zigzagpivotbars, startIndex, lastDir, x, a, b, c, d,
- xBar, aBar, bBar, cBar, dBar)
- newLastdBar
- ohlc = array.from(high, low)
- indicatorHigh = array.new<float>()
- indicatorLow = array.new<float>()
- setup(showZigzag, zigzagLength, zigzagDepth)=>
- if showZigzag
- [valueMatrix, zigzagpivotdirs, zigzagpivotbars, newPivot, doublePivot] = zigzag.calculateplain(zigzagLength, ohlc, indicatorHigh, indicatorLow, numberOfPivots= zigzagDepth)
- var lastABar = 0
- if(newPivot)
- zigzagpivots = matrix.col(valueMatrix, 0)
- lastABar := scan_patterns(1, doublePivot, zigzagpivots, zigzagpivotbars, zigzagpivotdirs, lastABar)
- lastABar := scan_patterns(0, newPivot, zigzagpivots, zigzagpivotbars, zigzagpivotdirs, lastABar)
- setup(showZigZag1, zigzag1Length, depthhh)
- setup(showZigZag2, zigzag2Length, depthhh)
- setup(showZigZag3, zigzag3Length, depthhh)
- setup(showZigZag4, zigzag4Length, depthhh)
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- //////////////////TD
- TDNumbers = input(true,group='TD')
- TD = 0.0
- TS = 0.0
- TD := close > close[4] ? nz(TD[1]) + 1 : 0
- TS := close < close[4] ? nz(TS[1]) + 1 : 0
- TDUp = 0.0
- TDDn = 0.0
- TDUp := TD - ta.valuewhen(TD < TD[1], TD, 1)
- TDDn := TS - ta.valuewhen(TS < TS[1], TS, 1)
- plotshape(TDNumbers ? TDUp == 9 ? true : na : na, style=shape.cross, text='9', color=color.white, location=location.abovebar, size =size.small,textcolor=color.white,title='TD Up9')
- plotshape(TDNumbers ? TDUp == 13 ? true : na : na, style=shape.cross, text='13', color=color.white, location=location.abovebar, size =size.small,textcolor=color.white,title='TD Up13')
- plotshape(TDNumbers ? TDDn == 9 ? true : na : na, style=shape.cross, text='9', color=color.white, location=location.belowbar, size =size.small,textcolor=color.white,title='TD Dn9')
- plotshape(TDNumbers ? TDDn == 13 ? true : na : na, style=shape.cross, text='13', color=color.white, location=location.belowbar, size =size.small,textcolor=color.white,title='TD Dn13')
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- //vegas
- vegas=input.bool(true,group='vegas channel')
- EMA144=ta.ema(close,144)
- EMA169=ta.ema(close,169)
- EMA288=ta.ema(close,288)
- EMA338=ta.ema(close,338)
- plot(vegas?EMA144:na,color=#00bcd4,linewidth=3,title='EMA144')
- plot(vegas?EMA169:na,color=#426eea,linewidth=3,title='EMA169')
- plot(vegas?EMA288:na,color=#d250e9,linewidth=3,title='EMA288')
- plot(vegas?EMA338:na,color=#673ab7,linewidth=3,title='EMA338')
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- //atrStopLoss
- showATRStopLoss=input.bool(false,group='atrStopLoss')
- atrlength = input.int(title='atr length', defval=14, minval=1,group='atrStopLoss')
- lookbackForStopLoss = input.int(title='how far to look back for high/lows', defval=8, minval=1,group='atrStopLoss')
- atrstopmultiplier = input.float(title='atr x ?', defval=1.0, minval=0.1,group='atrStopLoss')
- //calculate data
- money=input(title='资金量', defval=10000,group='atrStopLoss')
- atr = ta.atr(atrlength)
- realatr = atr * atrstopmultiplier
- longstop = (ta.lowest(low, lookbackForStopLoss)) - realatr
- shortstop = (ta.highest(high, lookbackForStopLoss)) + realatr
- MK=high-low
- ll=MK<atr?longstop:MK>atr and MK<2*atr?longstop-realatr:MK>2*atr?longstop-2*realatr:na
- ss=MK<atr?shortstop:MK>atr and MK<2*atr?shortstop+realatr:MK>2*atr?shortstop+2*realatr:na
- plot(showATRStopLoss?ll:na,color=MK<atr?color.green:MK>atr and MK<2*atr?color.yellow:MK>2*atr?color.red:na,style=plot.style_stepline,title='atrStop')
- plot(showATRStopLoss?ss:na,color=MK<atr?color.green:MK>atr and MK<2*atr?color.yellow:MK>2*atr?color.red:na,style=plot.style_stepline,title='atrStop')
- var testTable = table.new(position = position.bottom_right, columns = 1, rows = 5, border_width = 1)
- lp=money*0.025/(close-ll)
- sp=money*0.025/(ss-close)
- Tl=0.0125*money/lp+close
- Ts=close-0.0125*money/sp
- if showATRStopLoss
- table.cell(table_id = testTable, column = 0, row = 0, text = "ATR " + str.tostring(math.round(atr, 1)),bgcolor = color.new(color.yellow,10))
- table.cell(table_id = testTable, column = 0, row = 1, text = str.tostring(math.round(Tl))+"mt" + str.tostring(math.round(lp, 3)),bgcolor = color.new(color.green,10),text_color=color.white)
- table.cell(table_id = testTable, column = 0, row = 2, text = str.tostring(math.round(ll))+"---"+str.tostring(math.round(close-ll)),bgcolor = color.new(color.green,10),text_color=color.white)
- table.cell(table_id = testTable, column = 0, row = 3, text = str.tostring(math.round(Ts))+"mt" + str.tostring(math.round(sp, 3)), bgcolor = color.new(color.red,10),text_color=color.white)
- table.cell(table_id = testTable, column = 0, row = 4, text = str.tostring(math.round(ss))+"---"+str.tostring(math.round(ss-close)), bgcolor = color.new(color.red,10),text_color=color.white)
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- //HTF LIQ
- var START_OFFSET = 0
- var END_OFFSET = 25
- var PURGED_COLOR = color.gray
- var PURGED_STYLE = line.style_dotted
- var g_indicator = "Liquidity"
- i_isDailyEnabled = input (true, "Daily", inline="Daily", group=g_indicator)
- i_dailyAboveLiquidityColor = input (color.new(#4caf50, 30), "", inline="Daily", group=g_indicator)
- i_dailyBelowLiquidityColor = input (color.new(#f23645, 30), "", inline="Daily", group=g_indicator)
- i_dailyWidth = input (3, "Width", inline="Daily", group=g_indicator)
- i_isWeeklyEnabled = input (true, "Weekly", inline="Weekly", group=g_indicator)
- i_weelyAboveLiquidityColor = input (color.new(#ffeb3b, 50), "", inline="Weekly", group=g_indicator)
- i_weelyBelowLiquidityColor = input (color.new(#ffeb3b, 50), "", inline="Weekly", group=g_indicator)
- i_weeklyWidth = input (10, "Width", inline="Weekly", group=g_indicator)
- i_isMonthlyEnabled = input (true, "Monthly", inline="Monthly", group=g_indicator)
- i_monthlyAboveLiquidityColor = input (color.new(#00bcd4, 50), "", inline="Monthly", group=g_indicator)
- i_monthlyBelowLiquidityColor = input (color.new(#00bcd4, 50), "", inline="Monthly", group=g_indicator)
- i_monthlyWidth = input (20, "Width", inline="Monthly", group=g_indicator)
- var highsArray = array.new_float()
- var lowsArray = array.new_float()
- var highLinesArray = array.new_line()
- var lowLinesArray = array.new_line()
- var float dayHigh = na
- var float dayLow = na
- [prevDayHigh, prevDayLow] = request.security(syminfo.tickerid, "D", [high[1], low[1]], lookahead=barmerge.lookahead_on)
- [prevWeekHigh, prevWeekLow] = request.security(syminfo.tickerid, "W", [high[1], low[1]], lookahead=barmerge.lookahead_on)
- [prevMonthHigh, prevMonthLow] = request.security(syminfo.tickerid, "M", [high[1], low[1]], lookahead=barmerge.lookahead_on)
- f_drawLine(float _y, color _c, int _w=1) => line.new(bar_index, _y, bar_index, _y, color=_c, width=_w)
- f_create(float _high, float _low, color _upperColor, color _lowerColor, int _linewidth) =>
- array.push(highsArray, _high)
- array.push(lowsArray, _low)
- array.push(highLinesArray, f_drawLine(_high, _upperColor, _linewidth))
- array.push(lowLinesArray, f_drawLine(_low, _lowerColor, _linewidth))
- f_update(array<line> _levels) =>
- for _line in _levels
- line.set_x1(_line, bar_index + START_OFFSET)
- line.set_x2(_line, bar_index + END_OFFSET)
- f_cleanUpperLevels(float _high, array<float> _highs, array<line> _levels) =>
- while array.min(_highs) < _high
- for [_index, _value] in _highs
- if _high > _value
- line.delete(array.remove(_levels, _index))
- array.remove(_highs, _index)
- f_cleanLowerLevels(float _low, array<float> _lows, array<line> _levels) =>
- while array.max(_lows) > _low
- for [_index, _value] in _lows
- if _low < _value
- line.delete(array.remove(_levels, _index))
- array.remove(_lows, _index)
- f_highlightUpperLevels(float _high, array<float> _highs, array<line> _levels) =>
- for [_index, _value] in _highs
- if _high > _value
- _line = array.get(_levels, _index)
- line.set_color(_line, PURGED_COLOR)
- line.set_style(_line, PURGED_STYLE)
- f_highlightLowerLevels(float _low, array<float> _lows, array<line> _levels) =>
- for [_index, _value] in _lows
- if _low < _value
- _line = array.get(_levels, _index)
- line.set_color(_line, PURGED_COLOR)
- line.set_style(_line, PURGED_STYLE)
- if i_isDailyEnabled and ta.change(time("D"))
- f_create(prevDayHigh, prevDayLow, i_dailyAboveLiquidityColor, i_dailyBelowLiquidityColor, i_dailyWidth)
- if i_isWeeklyEnabled and ta.change(time("W"))
- f_create(prevWeekHigh, prevWeekLow, i_weelyAboveLiquidityColor, i_weelyBelowLiquidityColor, i_weeklyWidth)
- if i_isMonthlyEnabled and ta.change(time("M"))
- f_create(prevMonthHigh, prevMonthLow, i_monthlyAboveLiquidityColor, i_monthlyBelowLiquidityColor, i_monthlyWidth)
- if barstate.islast
- f_update(highLinesArray)
- f_update(lowLinesArray)
- if ta.change(time("D"))
- dayHigh := high
- dayLow := low
- if high > dayHigh
- dayHigh := high
- if low < dayLow
- dayLow := low
- if barstate.islast
- f_highlightUpperLevels(dayHigh, highsArray, highLinesArray)
- f_highlightLowerLevels(dayLow, lowsArray, lowLinesArray)
- if ta.change(time("D"))
- f_cleanUpperLevels(prevDayHigh, highsArray, highLinesArray)
- f_cleanLowerLevels(prevDayLow, lowsArray, lowLinesArray)
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- plotOB = input.bool(defval=true, title='Plot OB', group='Order Blocks')
- obBullColor = input.color(defval=color.new(#4caf50, 30), title='Bullish OB Color', inline='Set Custom Color', group='Order Blocks')
- obBearColor = input.color(defval=color.new(#ec407a, 30), title='Bearish OB Color', inline='Set Custom Color', group='Order Blocks')
- obBoxBorder = input.string(defval=line.style_solid, title='OB Box Border Style', options=[line.style_dashed, line.style_dotted, line.style_solid], group='Order Blocks', tooltip='To disable border, set Border Width below to 0')
- obBorderTransparency = input.int(defval=80, title='OB Border Box Transparency', minval=0, maxval=100, group='Order Blocks')
- obMaxBoxSet = input.int(defval=10, title='Maximum OB Box Displayed', minval=1, maxval=100, group='Order Blocks', tooltip='Minimum = 1, Maximum = 100')
- filterMitOB = input.bool(defval=true, title='Custom Color Mitigated OB', group='Order Blocks')
- mitOBColor = input.color(defval=color.new(#9598a1, 50), title='Mitigated OB Color', group='Order Blocks', inline='Set Custom Color Mit OB', tooltip='Set Transparency to 0 to make mitigated OB disappear')
- plotFVG = input.bool(defval=true, title='Plot FVG', group='Fair Value Gaps', inline='FVG sets')
- plotStructureBreakingFVG = input.bool(defval=false, title='Plot Structure Breaking FVG', group='Fair Value Gaps', inline='FVG sets')
- fvgBullColor = input.color(defval=color.new(#ffeb3b, 85), title='Bullish FVG Color', inline='Set Custom Color', group='Fair Value Gaps')
- fvgBearColor = input.color(defval=color.new(#ffeb3b, 85), title='Bearish FVG Color', inline='Set Custom Color', group='Fair Value Gaps')
- fvgStructBreakingColor = input.color(defval=color.new(#ffeb3b, 50), title='Structure Breaking FVG Color', inline='Set Custom Color', group='Fair Value Gaps')
- fvgBoxBorder = input.string(defval=line.style_solid, title='FVG Box Border Style', options=[line.style_dashed, line.style_dotted, line.style_solid], group='Fair Value Gaps', tooltip='To disable border, set Border Width below to 0')
- fvgBorderTransparency = input.int(defval=80, title='FVG Border Box Transparency', minval=0, maxval=100, group='Fair Value Gaps')
- fvgMaxBoxSet = input.int(defval=10, title='Maximum FVG Box Displayed', minval=1, maxval=100, group='Fair Value Gaps', tooltip='Minimum = 1, Maximum = 100')
- filterMitFVG = input.bool(defval=true, title='Custom Color Mitigated FVG', group='Fair Value Gaps')
- mitFVGColor = input.color(defval=color.new(color.gray, 100), title='Mitigated FVG Color', group='Fair Value Gaps', inline='Set Custom Color Mit FVG', tooltip='Set Transparency to 0 to make mitigated FVG disappear')
- plotRJB = input.bool(defval=true, title='Plot RJB', group='Rejection Blocks', inline='RJB sets')
- rjbBullColor = input.color(defval=color.new(#00bcd4, 30), title='Bullish RJB Color', inline='Set Custom Color', group='Rejection Blocks')
- rjbBearColor = input.color(defval=color.new(#f23645, 30), title='Bearish RJB Color', inline='Set Custom Color', group='Rejection Blocks')
- rjbBoxBorder = input.string(defval=line.style_solid, title='RJB Box Border Style', options=[line.style_dashed, line.style_dotted, line.style_solid], group='Rejection Blocks', tooltip='To disable border, set Border Width below to 0')
- rjbBorderTransparency = input.int(defval=80, title='RJB Border Box Transparency', minval=0, maxval=100, group='Rejection Blocks')
- rjbMaxBoxSet = input.int(defval=10, title='Maximum RJB Box Displayed', minval=1, maxval=100, group='Rejection Blocks', tooltip='Minimum = 1, Maximum = 100')
- filterMitRJB = input.bool(defval=true, title='Custom Color Mitigated RJB', group='Rejection Blocks')
- mitRJBColor = input.color(defval=color.new(#512da8, 10), title='Mitigated RJB Color', group='Rejection Blocks', inline='Set Custom Color Mit RJB', tooltip='Set to 100 to make mitigated RJB disappear')
- plotPVT = input.bool(defval=false, title='Plot Pivots', group='Pivots')
- pivotLookup = input.int(defval=1, minval=1, maxval=5,title='Pivot Lookup', group='Pivots', tooltip='Minimum = 1, Maximum = 5')
- pvtTopColor = input.color(defval=color.new(color.silver, 0), title='Pivot Top Color', group='Pivots', inline='PVT Color')
- pvtBottomColor = input.color(defval=color.new(color.silver, 0), title='Pivot Bottom Color', group='Pivots', inline='PVT Color')
- plotBOS = input.bool(defval=false, title='Plot BoS', group='Crossovers', inline='BOS sets')
- useHighLowForBullishBoS = input.bool(defval=true, title='Use High/Low for Bullish BoS (for Bearish setup)', group='Crossovers')
- useHighLowForBearishBoS = input.bool(defval=true, title='Use High/Low for Bearish BoS (for Bullish setup)', group='Crossovers')
- bosBoxFlag = input.bool(title='BoS Box Length Manually', defval=false, group='Crossovers', tooltip='If activated the BoS Boxes will not extend unitl crossed by price. Instead will extend by the amount of bars choosen in the "Set BoS Box Length Manually" option')
- bosBoxLength = input.int(title='BoS Box Length Manually', defval=3, minval=1, maxval=5, group='Crossovers', inline='BoS Boxes', tooltip='If "Set BoS Box Length Manually" is marked, choose by how many bars. Minimum = 1, Maximum = 5')
- bosBullColor = input.color(defval=color.new(color.green, 90), title='Bullish BoS Color', inline='Set Custom Color', group='Crossovers')
- bosBearColor = input.color(defval=color.new(color.red, 90), title='Bearish BoS Color', inline='Set Custom Color', group='Crossovers')
- bosBoxBorder = input.string(defval=line.style_solid, title='BoS Box Border Style', options=[line.style_dashed, line.style_dotted, line.style_solid], group='Crossovers', tooltip='To disable border, set Border Width below to 0')
- bosBorderTransparency = input.int(defval=80, title='BoS Border Box Transparency', minval=0, maxval=100, group='Crossovers')
- bosMaxBoxSet = input.int(defval=10, title='Maximum BoS Box Displayed', minval=1, maxval=100, group='Crossovers', tooltip='Minimum = 1, Maximum = 100')
- plotHVB = input.bool(defval=false, title='Plot HVB', group='High Volume Bar', tooltip='A candle where the average volume is higher than last few bars.')
- hvbBullColor = input.color(defval=color.green, title='Bullish HVB Color', inline='Set Custom Color', group='High Volume Bar')
- hvbBearColor = input.color(defval=color.red, title='Bearish HVB Color', inline='Set Custom Color', group='High Volume Bar')
- hvbEMAPeriod = input.int(defval=12, minval=1, title='Volume EMA Period', group='High Volume Bar')
- hvbMultiplier = input.float(defval=1.5, title='Volume Multiplier', minval=1, maxval=100, group='High Volume Bar')
- plotPPDD = input.bool(defval=false, title="Plot PPDD OB's", group='Qualitative indicators', tooltip='Premium Premium Discount Discount (PPDD) is an OB formed after liquidity sweep. It will show up by default as a triangle (Bull ▲ / Bear ▼). Also PPDD1 (by deafult maked with a x-cross ⨯) which is a weak OB formed after liquidity sweep, that fails to completely engulf the high/low, but closes beyond the trapped candles open price.')
- ppddBullColor = input.color(defval=color.new(color.green, 0), title="Bullish PPDD OB's Color", group='Qualitative indicators', inline='PPDD Color')
- ppddBearColor = input.color(defval=color.new(color.red, 0), title="Bearish PPDD OB's Color", group='Qualitative indicators', inline='PPDD Color')
- plotOBFVG = input.bool(defval=false, title='Plot Stacked OB+FVG', group='Qualitative indicators', tooltip='Marks the candle (default with a diamond ◆) when an OB & FVG are stacked, showing momentum')
- obfvgBullColor = input.color(defval=color.new(color.green, 0), title='Bullish Stacked OB+FVG Color', group='Qualitative indicators', inline='OBFVG Color')
- obfvgBearColor = input.color(defval=color.new(color.red, 0), title='Bearish Stacked OB+FVG Color', group='Qualitative indicators', inline='OBFVG Color')
- plotLabelOB = input.bool(defval=true, title='Plot OB Label', inline='OB label', group='Label Options')
- obLabelColor = input.color(defval=color.new(#4dd0e1,0), title='Color', inline='OB label', group='Label Options')
- obLabelSize = input.string(defval=size.auto, title="Size", options=[size.huge, size.large, size.small, size.tiny, size.auto, size.normal], inline='OB label', group='Label Options')
- plotLabelFVG = input.bool(defval=true, title='Plot FVG Label', inline='FVG label', group='Label Options')
- fvgLabelColor = input.color(defval=color.new(#e1bee7,0), title='Color', inline='FVG label', group='Label Options')
- fvgLabelSize = input.string(defval=size.auto, title="Size", options=[size.huge, size.large, size.small, size.tiny, size.auto, size.normal], inline='FVG label', group='Label Options')
- plotLabelRJB = input.bool(defval=true, title='Plot RJB Label', inline='RJB label', group='Label Options')
- rjbLabelColor = input.color(defval=color.new(#ffffff,0), title='Color', inline='RJB label', group='Label Options')
- rjbLabelSize = input.string(defval=size.auto, title="Size", options=[size.huge, size.large, size.small, size.tiny, size.auto, size.normal], inline='RJB label', group='Label Options')
- plotLabelBOS = input.bool(defval=true, title='Plot BoS Label', inline='BOS label', group='Label Options')
- bosLabelColor = input.color(defval=color.new(#ffeb3b,0), title='Color', inline='BOS label', group='Label Options')
- bosLabelSize = input.string(defval=size.auto, title="Size", options=[size.huge, size.large, size.small, size.tiny, size.auto, size.normal], inline='BOS label', group='Label Options')
- //Box Types
- var int _ob = 1
- var int _fvg = 2
- var int _rjb = 3
- var int _bos = 4
- //Box Labels
- var string _obLabel = "OB"
- var string _fvgLabel = "FVG"
- var string _rjbLabel = "RJB"
- var string _bosLabel = "BoS"
- var string _plus = "+"
- var string _minus = "-"
- var string _empty = ""
- //Box Arrays
- var box[] _bearBoxesOB = array.new_box()
- var box[] _bullBoxesOB = array.new_box()
- var box[] _bearBoxesFVG = array.new_box()
- var box[] _bullBoxesFVG = array.new_box()
- var box[] _bearBoxesRJB = array.new_box()
- var box[] _bullBoxesRJB = array.new_box()
- var box[] _bearBoxesBOS = array.new_box()
- var box[] _bullBoxesBOS = array.new_box()
- //Functions
- isUp(index) =>
- close[index] > open[index]
- isDown(index) =>
- close[index] < open[index]
- isObUp(index) =>
- isDown(index + 1) and isUp(index) and close[index] > high[index + 1]
- isObDown(index) =>
- isUp(index + 1) and isDown(index) and close[index] < low[index + 1]
- isFvgUp(index) =>
- (low[index] > high[index + 2])
- isFvgDown(index) =>
- (high[index] < low[index + 2])
- //Function to Calculte Box Length
- _controlBox(_boxes, _high, _low, _type) =>
- if array.size(_boxes) > 0
- for i = array.size(_boxes) - 1 to 0 by 1
- _box = array.get(_boxes, i)
- _boxLow = box.get_bottom(_box)
- _boxHigh = box.get_top(_box)
- _boxRight = box.get_right(_box)
- if bosBoxFlag and _type == _bos
- if na or (bar_index + bosBoxLength - 1 == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
- box.set_right(_box, bar_index + bosBoxLength - 1)
- else if (filterMitOB and _type == _ob) or (filterMitFVG and _type == _fvg) or (filterMitRJB and _type == _rjb)
- if na or (bar_index == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
- box.set_right(_box, bar_index + 1)
- else
- if _type == _ob
- box.set_bgcolor(_box, mitOBColor)
- box.set_border_color(_box, mitOBColor)
- else if _type == _fvg
- // box.set_bgcolor(_box, mitFVGColor)
- // box.set_border_color(_box, mitFVGColor)
- box.delete(_box)
- else if _type == _rjb
- box.set_bgcolor(_box, mitRJBColor)
- box.set_border_color(_box, mitRJBColor)
- else
- if na or (bar_index == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
- box.set_right(_box, bar_index + 1)
- //////////////////// Pivots ////////////////////
- hih = ta.pivothigh(high, pivotLookup, pivotLookup)
- lol = ta.pivotlow(low , pivotLookup, pivotLookup)
- top = ta.valuewhen(hih, high[pivotLookup], 0)
- bottom = ta.valuewhen(lol, low [pivotLookup], 0)
- plot(top, offset=-pivotLookup, linewidth=1, color=(top != top[1] ? na : (plotPVT ? pvtTopColor : na)), title="Pivot Top")
- plot(bottom, offset=-pivotLookup, linewidth=1, color=(bottom != bottom[1] ? na : (plotPVT ? pvtBottomColor : na)), title="Pivot Bottom")
- //////////////////// Order Block //////////////////
- //Bullish OB Box Plotting
- if isObUp(1) and plotOB
- _bullboxOB = box.new(left=bar_index - 2, top=high[2], right=bar_index, bottom=math.min(low[2], low[1]), border_color=color.new(obBullColor, obBorderTransparency), border_style=obBoxBorder, border_width=1, bgcolor=obBullColor,
- text=plotLabelOB ? _obLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=obLabelSize, text_color=obLabelColor)
- if array.size(_bullBoxesOB) > obMaxBoxSet
- box.delete(array.shift(_bullBoxesOB))
- array.push(_bullBoxesOB, _bullboxOB)
- //Bearish OB Box Plotting
- if isObDown(1) and plotOB
- _bearboxOB = box.new(left=bar_index - 2, top=math.max(high[2], high[1]), right=bar_index, bottom=low[2], border_color=color.new(obBearColor, obBorderTransparency), border_style=obBoxBorder, border_width=1, bgcolor=obBearColor,
- text=plotLabelOB ? _obLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=obLabelSize, text_color=obLabelColor)
- if array.size(_bearBoxesOB) > obMaxBoxSet
- box.delete(array.shift(_bearBoxesOB))
- array.push(_bearBoxesOB, _bearboxOB)
- if plotOB
- _controlBox(_bearBoxesOB, high, low, _ob)
- _controlBox(_bullBoxesOB, high, low, _ob)
- //////////////////// Fair Value Gap //////////////////
- //Bullish FVG Box Plotting
- if isFvgUp(0)
- box _bullboxFVG = na
- if plotStructureBreakingFVG and (close[1] > top) and (low[1] < top) and (high[2] < top) and (low > top)
- _bullboxFVG := box.new(left=bar_index-2, top=low[0], right=bar_index, bottom=high[2], bgcolor=fvgStructBreakingColor, border_color=color.new(fvgStructBreakingColor, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
- text=plotLabelFVG ? _fvgLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor)
- else if plotFVG
- _bullboxFVG := box.new(left=bar_index-2, top=low[0], right=bar_index, bottom=high[2], bgcolor=fvgBullColor, border_color=color.new(fvgBullColor, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
- text=plotLabelFVG ? _fvgLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor)
- if array.size(_bullBoxesFVG) > fvgMaxBoxSet
- box.delete(array.shift(_bullBoxesFVG))
- array.push(_bullBoxesFVG, _bullboxFVG)
- //Bearish FVG Box Plotting
- if isFvgDown(0)
- box _bearboxFVG = na
- if plotStructureBreakingFVG and (close[1] < bottom) and (high[1] > bottom) and (low[2] > bottom) and (high < bottom)
- _bearboxFVG := box.new(left=bar_index-2, top=low[2], right=bar_index, bottom=high[0], bgcolor=fvgStructBreakingColor, border_color=color.new(fvgStructBreakingColor, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
- text=plotLabelFVG ? _fvgLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor)
- else if plotFVG
- _bearboxFVG := box.new(left=bar_index-2, top=low[2], right=bar_index, bottom=high[0], bgcolor=fvgBearColor, border_color=color.new(fvgBearColor, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
- text=plotLabelFVG ? _fvgLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor)
- if array.size(_bearBoxesFVG) > fvgMaxBoxSet
- box.delete(array.shift(_bearBoxesFVG))
- array.push(_bearBoxesFVG, _bearboxFVG)
- if plotFVG or plotStructureBreakingFVG
- _controlBox(_bearBoxesFVG, high, low, _fvg)
- _controlBox(_bullBoxesFVG, high, low, _fvg)
- //////////////////// Rejection Block //////////////////
- if plotRJB
- isDownRjbObCondition = isObDown(1)
- isDownRjb1 = isDownRjbObCondition and (high[1] < (close[2] + 0.2*(high[2]-close[2]))) // RJB is on trapped's wick and <50% of the wick was covered by signal
- isDownRjb2 = isDownRjbObCondition and (high[1] > high[2]) // RJB is on signal's wick
- if isDownRjb1 and plotRJB
- _bearboxRJB = box.new(left=bar_index-2, top=high[2], right=bar_index, bottom=close[2], bgcolor=rjbBearColor, border_color=color.new(rjbBearColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,
- text=plotLabelRJB ? _rjbLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)
- if array.size(_bearBoxesRJB) > rjbMaxBoxSet
- box.delete(array.shift(_bearBoxesRJB))
- array.push(_bearBoxesRJB, _bearboxRJB)
- if isDownRjb2 and plotRJB
- _bearboxRJB = box.new(left=bar_index-1, top=high[1], right=bar_index, bottom=open[1], bgcolor=rjbBearColor, border_color=color.new(rjbBearColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,
- text=plotLabelRJB ? _rjbLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)
- if array.size(_bearBoxesRJB) > rjbMaxBoxSet
- box.delete(array.shift(_bearBoxesRJB))
- array.push(_bearBoxesRJB, _bearboxRJB)
- //Bullish RJB Box Plotting
- if plotRJB
- isUpRjbObCondition = isObUp(1)
- isUpRjb1 = isUpRjbObCondition and (low[1] > (close[2] - 0.2*(close[2]-low[2]))) // RJB is on trapped's wick and <50% of the wick was covered by signal
- isUpRjb2 = isUpRjbObCondition and (low[1] < low[2]) // RJB is on signal's wick
- if isUpRjb1 and plotRJB
- _bullboxRJB = box.new(left=bar_index-2, top=close[2], right=bar_index, bottom=low[2], bgcolor=rjbBullColor, border_color=color.new(rjbBullColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,
- text=plotLabelRJB ? _rjbLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)
- if array.size(_bullBoxesRJB) > rjbMaxBoxSet
- box.delete(array.shift(_bullBoxesRJB))
- array.push(_bullBoxesRJB, _bullboxRJB)
- if isUpRjb2 and plotRJB
- _bullboxRJB = box.new(left=bar_index-1, top=open[1], right=bar_index, bottom=low[1], bgcolor=rjbBullColor, border_color=color.new(rjbBullColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,
- text=plotLabelRJB ? _rjbLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)
- if array.size(_bullBoxesRJB) > rjbMaxBoxSet
- box.delete(array.shift(_bullBoxesRJB))
- array.push(_bullBoxesRJB, _bullboxRJB)
- if plotRJB
- _controlBox(_bearBoxesRJB, high, low, _rjb)
- _controlBox(_bullBoxesRJB, high, low, _rjb)
- //////////////////// Crossovers a.k.a. Break of Structure ////////////////////
- //Bullish BOS Box Plotting
- if plotBOS
- if ta.crossover(useHighLowForBullishBoS ? high : close, top)
- _bullboxBOS = box.new(left=bar_index, top=top, right=bosBoxFlag ? bar_index+bosBoxLength : bar_index+1, bottom=bottom, bgcolor=bosBullColor, border_color=color.new(bosBullColor, bosBorderTransparency), border_style=bosBoxBorder, border_width=1,
- text=plotLabelBOS ? _bosLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=bosLabelSize, text_color=bosLabelColor)
- if array.size(_bullBoxesBOS) > bosMaxBoxSet
- box.delete(array.shift(_bullBoxesBOS))
- array.push(_bullBoxesBOS, _bullboxBOS)
- //Bearish BOS Box Plotting
- if plotBOS
- if ta.crossunder(useHighLowForBearishBoS ? low : close, bottom)
- _bearboxBOS = box.new(left=bar_index, top=top, right=bosBoxFlag ? bar_index+bosBoxLength : bar_index+1, bottom=bottom, bgcolor=bosBearColor, border_color=color.new(bosBearColor, bosBorderTransparency), border_style=bosBoxBorder, border_width=1,
- text=plotLabelBOS ? _bosLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=bosLabelSize, text_color=bosLabelColor)
- if array.size(_bearBoxesBOS) > bosMaxBoxSet
- box.delete(array.shift(_bearBoxesBOS))
- array.push(_bearBoxesBOS, _bearboxBOS)
- if plotBOS
- _controlBox(_bearBoxesBOS, high, low, _bos)
- _controlBox(_bullBoxesBOS, high, low, _bos)
- //////////////////// Premium Premium & Discount Discount //////////////////
- premiumPremium = plotPPDD and isObDown(0) and ((math.max(high, high[1]) > top and close < top) or (math.max(high, high[1]) > top[1] and close < top[1]))
- discountDiscount = plotPPDD and isObUp(0) and ((math.min(low, low[1]) < bottom and close > bottom) or (math.min(low, low[1]) < bottom[1] and close > bottom[1]))
- plotshape(premiumPremium, "Bearish PPDD OB", style=shape.triangledown , location=location.abovebar, color=ppddBearColor, size=size.tiny)
- plotshape(discountDiscount, "Bullish PPDD OB", style=shape.triangleup , location=location.belowbar, color=ppddBullColor, size=size.tiny)
- premiumPremium1 = plotPPDD and (isUp(1) and isDown(0) and close[0] < open[1]) and ((math.max(high, high[1]) > top and close < top) or (math.max(high, high[1]) > top[1] and close < top[1])) and not premiumPremium
- discountDiscount1 = plotPPDD and (isDown(1) and isUp(0) and close[0] > open[1]) and ((math.min(low, low[1]) < bottom and close > bottom) or (math.min(low, low[1]) < bottom[1] and close > bottom[1])) and not discountDiscount
- plotshape(premiumPremium1, "Bearish PPDD Weak OB", style=shape.xcross, location=location.abovebar, color=ppddBearColor, size=size.tiny)
- plotshape(discountDiscount1, "Bullish PPDD Weak OB", style=shape.xcross, location=location.belowbar, color=ppddBullColor, size=size.tiny)
- ////////////////// High Volume Bars //////////////////
- volEma = ta.ema(volume, hvbEMAPeriod)
- isHighVolume = volume > (hvbMultiplier * volEma)
- barcolor(plotHVB and isUp(0) and isHighVolume ? hvbBullColor : na, title="Bullish HVB")
- barcolor(plotHVB and isDown(0) and isHighVolume ? hvbBearColor : na, title="Bearish HVB")
- ///////////////// Stacked OB + FVG //////////////////
- plotshape(plotOBFVG and isFvgDown(0) and isObDown(1), "Bearish OB+FVG Stack", style=shape.diamond, location=location.abovebar, color=obfvgBearColor, size=size.tiny)
- plotshape(plotOBFVG and isFvgUp(0) and isObUp(1), "Bullish OB+FVG Stack", style=shape.diamond, location=location.belowbar, color=obfvgBullColor, size=size.tiny)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement