Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- //@author=LucF
- // Signs of The Times [LucF]
- // v0.5, 2019.12.15 03:54 — LucF
- // Calculates a signal based on individual bar states and proximity rules with very close neighbors.
- // - Two higher timeframes can be calculated in 3 different ways: pre-defined steps from current TF, multiples of current TF or fixed.
- // - Alerts can be created on any combination of confirmed and/or filtered markers.
- // - A signal plot providing entries for the PineCoders Backtesting & Trading Engine is included.
- // This indicator's page on TV:
- study("Signs of The Times (SOTT) [LucF]", "Signs of The Times", true)
- // ———————————————————— Colors
- myGreenRaw = color.new(#00FF00,0), myGreenMedium = color.new(#00FF00,40), myGreenSemiDark = color.new(#00FF00,62), myGreenDark = color.new(#00FF00,75), myGreenDarkDark = color.new(#00FF00,82), myGreenDarkDarkDark = color.new(#00FF00,91)
- myRedRaw = color.new(#FF0000,0), myRedMedium = color.new(#FF0000,30), myRedSemiDark = color.new(#FF0000,50), myRedDark = color.new(#FF0000,75), myRedDarkDark = color.new(#FF0000,80), myRedDarkDarkDark = color.new(#FF0000,87)
- MyGreenBackGround = color.new(#00FF00,93), MyRedBackGround = color.new(#FF0000,90)
- invisible = color.new(color.white,100), myBlack = color.new(color.black,0)
- // {
- // ———————————————————— Inputs
- f_01(_bool) => _bool ? 1 : 0
- TF1 = "1. Discrete Steps", TF2 = "2. Multiple of current TF", TF3 = "3. Fixed TF"
- HB1 = "Heaviest", HB2 = "Heavier", HB3 = "Normal", HB4 = "Subtler", HB5 = "Hidden"
- var cStep = 0.5
- var cMinVal = 0.0
- _2 = input(false, "═══════════ Display ══════════")
- instantSott = input(false, "Instant SOTT")
- showWeaknesses = input(true, "Highlight weaknesses")
- breadthBrightness = input(HB3, "SOTT Breadth Display", options = [HB1, HB2, HB3, HB4, HB5])
- htfBrightness = input(HB3, "HTF Cloud Display", options = [HB1, HB2, HB3, HB4, HB5])
- reduceLength = input(true, "Accelerate on drops")
- showBgReducedLength = input(false, "Show background on drops")
- _4 = input(false, "══════════ Parameters ════════")
- sottLength = input(20, "SOTT sum length", minval = 1)
- reduceLengthDivisor = input(4, "SOTT drop accelerated length divisor", minval = 1)
- sottAmplification = input(4., "Signal amplification", minval = 1.)
- htfType = input(TF2, "HTF Selection", options=[TF1, TF2, TF3])
- htfType2a = input(12, "...2. Multiple of Current TF for HTF1", minval = 1)
- htfType2b = input(24, "...2. Multiple of Current TF for HTF2", minval = 1)
- htfType3a = input("D", "...3. Fixed HTF1", type = input.resolution)
- htfType3b = input("W", "...3. Fixed HTF2", type = input.resolution)
- atoms = input(true, "══════ Atomic Components ═════")
- atom01 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "Up Bar")
- atom02 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "Volume Bump")
- atom03 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "Wicks < Body")
- atom04 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "tr > tr[1]")
- atom05 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "Up Bar and WickHi > WickLo")
- atom06 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "Close > Previous close")
- atom07 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "High > Previous high")
- atom08 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "Low > Previous low")
- moles = input(true, "═════ Molecular Components ════")
- mole01 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Double volume bumps")
- mole02 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Pivot")
- mole03 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Consecutive up bars")
- mole04 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Gaps")
- mole05 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Down then good up bar")
- mole06 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Two rising close")
- mole07 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Three rising closes")
- // }
- // ———————————————————— Functions
- // {
- // ————— Converts current timeframe into minutes of type float.
- f_resInMinutes() =>
- _resInMinutes = timeframe.multiplier * (
- timeframe.isseconds ? 1. / 60. :
- timeframe.isminutes ? 1. :
- timeframe.isdaily ? 1440. :
- timeframe.isweekly ? 10080. :
- timeframe.ismonthly ? 43800. : na)
- // ————— Returns a multiple of current TF as a string in period format usable with "security()".
- f_multipleOfRes(_mult) =>
- // Convert target timeframe to minutes.
- _targetResInMin = f_resInMinutes() * _mult
- // Find best way to express the TF.
- _targetResInMin <= 0.0417 ? "1S" :
- _targetResInMin <= 0.167 ? "5S" :
- _targetResInMin <= 0.376 ? "15S" :
- _targetResInMin <= 0.751 ? "30S" :
- _targetResInMin <= 1440 ? tostring(round(_targetResInMin)) :
- _targetResInMin <= 43800 ? tostring(round(min(_targetResInMin / 1440, 365))) + "D" :
- tostring(round(min(_targetResInMin / 43800, 12))) + "M"
- // ————— Returns resolution of _resolution period in minutes.
- f_tfResInMinutes(_resolution) =>
- // _resolution: resolution of other timeframe (in timeframe.period string format).
- _mult = security(syminfo.tickerid, _resolution, timeframe.multiplier)
- _res = security(syminfo.tickerid, _resolution, timeframe.isseconds ? 1 : timeframe.isintraday ? 2 : timeframe.isdaily ? 3 : timeframe.isweekly ? 4 : timeframe.ismonthly ? 5 : na)
- _return =
- _res == 1 ? _mult / 60 :
- _res == 2 ? _mult :
- _res == 3 ? _mult * 1440 :
- _res == 4 ? _mult * 10080 :
- _res == 5 ? _mult * 43800 : na
- // ————— Given current TF, returns next step1 and step2 of higher TF (HTF1 and HTF2).
- f_resNextStep1(_res) =>
- // _res: current TF in minutes.
- _step1 =
- _res <= 1 ? "60" :
- _res <= 360 ? "1D" :
- _res <= 1440 ? "1W" :
- _res <= 10080 ? "1M" : "12M"
- f_resNextStep2(_res) =>
- _step2 =
- _res <= 1 ? "1D" :
- _res <= 360 ? "1W" :
- _res <= 1440 ? "1M" : "12M"
- // ————— Print a label at end of chart.
- f_print(_txt) => t = time + (time - time[1]) * 3, var _lbl = label.new(t, high, _txt, xloc.bar_time, yloc.price, #00000000, label.style_none, color.gray, size.large), label.set_xy(_lbl, t, high + 3 * tr)
- // }
- // ———————————————————— Indicator calcs
- // {
- // ————— Resolution calcs.
- // Get user-defined HTF.
- var resMultiple1 = f_multipleOfRes(htfType2a)
- var resMultiple2 = f_multipleOfRes(htfType2b)
- var resStep1 = f_resNextStep1(f_resInMinutes())
- var resStep2 = f_resNextStep2(f_resInMinutes())
- var htf1 = htfType == TF1 ? resStep1 : htfType == TF2 ? resMultiple1 : htfType3a
- var htf2 = htfType == TF1 ? resStep2 : htfType == TF2 ? resMultiple2 : htfType3b
- // If current res is not lower than HTF, print warning label (background at the end of plots will also show in red).
- if barstate.islast
- // Only call f_tfResInMinutes() on last bar because it uses "security()" calls.
- currentResIsNotLower = f_resInMinutes() >= f_tfResInMinutes(htf1)
- if currentResIsNotLower
- f_print("Chart resolution\nmust be lower than " + htf1)
- // ————— Candle components and states.
- barUp = close > open
- barDn = close < open
- volUp = volume > volume[1]
- nonZeroValue = 10e-10
- noBody = close == open
- body = abs(close - open)
- wickLo = min(open, close) - low
- wickHi = high - max(open, close)
- nonZeroBody = open != close ? body : nonZeroValue
- nonZeroWickLo = min(open, close) != low ? wickLo : nonZeroValue
- nonZeroWickHi = max(open, close) != high ? wickHi : nonZeroValue
- fullHeight = high - low
- noMovement = high == low
- // ————— Helper functions.
- // Returns bull, bear or neutral value given conditions.
- f_bbn(_bullCond, _bearCond, _val) => _bullCond ? _val : _bearCond ? - _val : 0
- // True when source is higher than on previous bar.
- f_isUp(_src) => rising(_src, 1)
- // True when source is lower than on previous bar.
- f_isDn(_src) => falling(_src, 1)
- // —————————— Functions returning the weight (_w) if condition is bullish, the negative weight if it is bearish, 0 if neutral.
- // ————— Atoms.
- // Bar up/dn
- f_atom01(_w) => f_bbn(barUp, barDn, _w)
- // Volume bump
- f_atom02(_w) => volUp ? f_bbn(barUp, barDn, _w) : 0
- // Body > wicks
- f_atom03(_w) => wickHi + wickLo < body ? f_bbn(barUp, barDn, _w) : 0
- // True range increase
- f_atom04(_w) => tr > tr[1] ? f_bbn(barUp, barDn, _w) : 0
- //
- f_atom05(_w) => wickLo < body and wickHi < body ? barUp and wickHi > wickLo ? _w : barDn and wickLo > wickHi ? - _w : 0 : 0
- // Close > previous close
- f_atom06(_w) => f_bbn(f_isUp(close), f_isDn(close), _w)
- // High > previous high
- f_atom07(_w) => f_bbn(f_isUp(high), f_isDn(high), _w)
- // Low > previous low
- f_atom08(_w) => f_bbn(f_isUp(low), f_isDn(low), _w)
- // ————— Molecules.
- // Double volume bump
- f_mole01(_w) => volUp and barUp and volUp[1] and barUp[1] ? _w : volUp and barDn and volUp[1] and barDn[1] ? -_w : 0
- // Pivot
- f_mole02(_w) => f_bbn(pivotlow(close, 1, 1), pivothigh(close, 1, 1), _w)
- // Consecutive bars
- f_mole03(_w) => f_bbn(barUp and barUp[1], barDn and barDn[1], _w)
- // Gaps
- f_mole04(_w) => f_bbn(open > close[1], open < close[1], _w)
- // Down then good up bar
- f_mole05(_w) => f_bbn(barDn[1] and barUp and close > open[1], barUp[1] and barDn and close < open[1], _w)
- // Two rising closes
- f_mole06(_w) => f_bbn(f_isUp(close) and f_isUp(close[1]), f_isDn(close) and f_isDn(close[1]), _w)
- // Three rising closes
- f_mole07(_w) => f_bbn(f_isUp(close) and f_isUp(close[1]) and f_isUp(close[2]), f_isDn(close) and f_isDn(close[1]) and f_isDn(close[2]), _w)
- // ————— Signs Of The Times (SOTT) max/min range (+/- this value is the max range of the instant SOTT value).
- var maxNowValue =
- atom01 +
- atom02 +
- atom03 +
- atom04 +
- atom05 +
- atom06 +
- atom07 +
- atom08 +
- mole01 +
- mole02 +
- mole03 +
- mole04 +
- mole05 +
- mole06 +
- mole07 +
- 0
- // ————— SOTT instant value.
- sottNow =
- f_atom01(atom01) +
- f_atom02(atom02) +
- f_atom03(atom03) +
- f_atom04(atom04) +
- f_atom05(atom05) +
- f_atom06(atom06) +
- f_atom07(atom07) +
- f_atom08(atom08) +
- f_mole01(mole01) +
- f_mole02(mole02) +
- f_mole03(mole03) +
- f_mole04(mole04) +
- f_mole05(mole05) +
- f_mole06(mole06) +
- f_mole07(mole07) +
- 0
- // ————— Calc sum of SOTT and that value's proportion of max weight value, in %.
- var sottSumReducedLength = max(sottLength / reduceLengthDivisor, 1)
- sottPct = sottNow / maxNowValue
- sottSum = sum(sottNow, sottLength)
- sottSumReduced = sum(sottNow, sottSumReducedLength)
- sottSumDropping = sottSum > 0 and sottSumReduced <= 0
- sottSumRedPct = sottSumReduced / (sottSumReducedLength * maxNowValue)
- sottSumPct = sottSum / (sottLength * maxNowValue)
- sottForCloud = instantSott ? sottPct : reduceLength and sottSumDropping ? sottSumRedPct : sottSumPct
- // ————— Calc cloud from percentage of sott.
- cloudBase = close
- atrBase = atr(3)
- sottCloud = cloudBase + (sottForCloud * atrBase * sottAmplification)
- sottCloudMax = cloudBase + (atrBase * sottAmplification)
- sottCloudMin = cloudBase - (atrBase * sottAmplification)
- // ————— HTF values.
- sottCloudHtf1 = security(syminfo.tickerid, htf1, sottCloud[1], lookahead = barmerge.lookahead_on)
- sottCloudHtf2 = security(syminfo.tickerid, htf2, sottCloud[1], lookahead = barmerge.lookahead_on)
- // ————— Cloud states.
- sottCloudUp = sottCloud > cloudBase
- sottCloudDn = sottCloud < cloudBase
- sottCloudBull = sottCloudUp and sottCloudUp[1]
- sottCloudBear = sottCloudDn and sottCloudDn[1]
- sottCloudHtf1Up = sottCloudHtf1 > cloudBase
- sottCloudHtf1Dn = sottCloudHtf1 < cloudBase
- sottCloudHtf1Bull = sottCloudHtf1Up and sottCloudHtf1Up[1]
- sottCloudHtf1Bear = sottCloudHtf1Dn and sottCloudHtf1Dn[1]
- sottCloudHtf2Up = sottCloudHtf2 > cloudBase
- sottCloudHtf2Dn = sottCloudHtf2 < cloudBase
- sottCloudHtf2Bull = sottCloudHtf2Up and sottCloudHtf2Up[1]
- sottCloudHtf2Bear = sottCloudHtf2Dn and sottCloudHtf2Dn[1]
- // }
- // ———————————————————— Plots
- // {
- // ————— SOTT Cloud.
- // SOTT cloud colors.
- cWeak = #FF9900FF
- cCloudBull = #33CC00FF
- cCloudBullWeak = showWeaknesses ? cWeak : #339900FF
- cCloudBear = #990000FF
- cCloudBearWeak = showWeaknesses ? cWeak : #800000FF
- cCloudNeut = color.new(color.gray, 70)
- // SOTT Cloud.
- p_cloudBase = plot(cloudBase, "Cloud base", invisible)
- p_sottCloud = plot(sottCloud, "Cloud line", invisible)
- fill(p_cloudBase, p_sottCloud, sottCloudBull ? cCloudBull : sottCloudBear ? cCloudBear : sottCloudUp ? cCloudBullWeak : sottCloudDn ? cCloudBearWeak : cWeak, title = "SOTT cloud fill")
- // ————— Breadth cloud.
- var cBreadth = breadthBrightness == HB1 ? color.new(color.gray, 80) : breadthBrightness == HB2 ? color.new(color.gray, 85) : breadthBrightness == HB3 ? color.new(color.gray, 88) : color.new(color.gray, 92)
- p_cloudMax = plot(breadthBrightness != HB5 ? sottCloudBull ? sottCloudMax : sottCloud : na, "SOTT breadth cloud max", invisible)
- p_cloudMin = plot(breadthBrightness != HB5 ? sottCloudBull ? sottCloud : sottCloudMin : na, "SOTT breadth cloud min", invisible)
- fill(p_cloudMax, p_cloudMin, cBreadth, title = "SOTT breadth cloud fill")
- // ————— HTF clouds.
- topCloud = max(sottCloud, cloudBase)
- botCloud = min(sottCloud, cloudBase)
- var cCloudHtf1Bull = htfBrightness == HB1 ? color.new(color.maroon, 80) : htfBrightness == HB2 ? color.new(color.maroon, 87) : htfBrightness == HB3 ? color.new(color.maroon, 90) : color.new(color.maroon, 93)
- var cCloudHtf1Bear = htfBrightness == HB1 ? color.new(color.green, 83) : htfBrightness == HB2 ? color.new(color.green, 90) : htfBrightness == HB3 ? color.new(color.green, 93) : color.new(color.green, 96)
- var cCloudHtf2Bull = htfBrightness == HB1 ? color.new(color.maroon, 75) : htfBrightness == HB2 ? color.new(color.maroon, 82) : htfBrightness == HB3 ? color.new(color.maroon, 84) : color.new(color.maroon, 88)
- var cCloudHtf2Bear = htfBrightness == HB1 ? color.new(color.green, 80) : htfBrightness == HB2 ? color.new(color.green, 87) : htfBrightness == HB3 ? color.new(color.green, 90) : color.new(color.green, 93)
- p_cloudHtf1Base = plot(sottCloudHtf1Bull ? topCloud : botCloud, "Cloud HTF1 base", invisible)
- p_cloudHtf2Base = plot(sottCloudHtf2Bull ? topCloud : botCloud, "Cloud HTF2 base", invisible)
- p_cloudHtf1 = plot(htfBrightness != HB5 ? sottCloudHtf1 : na, "Cloud HTF1", invisible)
- p_cloudHtf2 = plot(htfBrightness != HB5 ? sottCloudHtf2 : na, "Cloud HTF2", invisible)
- fill(p_cloudHtf2Base, p_cloudHtf2, sottCloudHtf2Bull ? cCloudHtf2Bull : cCloudHtf2Bear, title = "Clouf HTF2 fill")
- fill(p_cloudHtf1Base, p_cloudHtf1, sottCloudHtf1Bull ? cCloudHtf1Bull : cCloudHtf1Bear, title = "Clouf HTF1 fill")
- // ————— Background.
- bgcolor(showBgReducedLength and sottSumDropping ? MyRedBackGround : na, title = "Background")
- // }
- // f_print(htf1 + "-" + htf2)
- // plotchar(sottSum, "sottSum", "", location.top)
- // plotchar(sottSumReduced, "sottSumReduced", "", location.top)
- // plotchar(sottSumDropping, "sottSumDropping", "", location.top)
- // plotchar(sottSumReducedLength, "sottSumReducedLength", "", location.top)
- // plotchar(sottNow, "sottNow", "", location.top)
- // plotchar(sottSum, "sottSum", "", location.top)
- // plotchar((sottLength * maxNowValue), "(sottLength * maxNowValue)", "", location.top)
- // plotchar(sottPct*100, "sottPct*100", "", location.top)
- // plotchar(atrBase, "atrBase", "", location.top)
- // plotchar(sottPct, "sottPct", "", location.top)
- // plotchar(sottNow, "sottNow", "", location.top)
- // plotchar(maxNowValue, "maxNowValue", "", location.top)
- // sottForCloudHtf1 = security(syminfo.tickerid, htf1, sottForCloud[1], lookahead = barmerge.lookahead_on)
- // sottForCloudHtf2 = security(syminfo.tickerid, htf2, sottForCloud[1], lookahead = barmerge.lookahead_on)
- // plotchar(sottCloudHtf1, "sottCloudHtf1", "", location.top)
- // plotchar(sottCloudHtf2, "sottCloudHtf2", "", location.top)
- // plotchar(sottForCloudHtf1, "sottForCloudHtf1", "", location.top)
- // plotchar(sottForCloudHtf2, "sottForCloudHtf2", "", location.top)
- // }
- // _2 = input(false, "═══════════ Display ══════════")
- // rsiType = input(RS4, "RSI", options = [RS1, RS2, RS3, RS4])
- // showRsi = rsiType != RS1
- // bbType = input(RS4, "...BBs", options = [RS1, RS2, RS3, RS4])
- // showBb = bbType != RS1
- // rsiTypeHtf = input(RS4, "Higher Timeframe (HTF) RSI", options = [RS1, RS2, RS3, RS4])
- // showRsiHtf = rsiTypeHtf != RS1
- // bbTypeHtf = input(RS4, "...BBs", options = [RS1, RS2, RS3, RS4])
- // showBbHtf = bbTypeHtf != RS1
- // deltaRsiType = input(RS4, "Delta RSIs", options = [RS1, RS2, RS3, RS4])
- // showDeltaRsi = deltaRsiType != RS1
- // bbTypeDelta = input(RS4, "...BBs", options = [RS1, RS2, RS3, RS4])
- // showBbDelta = bbTypeDelta != RS1
- // statusType = input(BG02, "Status", options = [BG01, BG02, BG03, BG04, BG05, BG06, BG07, BG08, BG09, BG10])
- // bgType = input(BG09, "Background", options = [BG01, BG02, BG03, BG04, BG05, BG06, BG07, BG08, BG09, BG10])
- // showFilter = input(false, "Show Filter State")
- // showMinMax = input(false, "Show Min/Max Historical RSI Levels")
- // showOsOb = input(false, "Show Overbought/Oversold Levels")
- // smoothHtf = input(true, "Smooth HTF plots")
- // _3 = input(false, " ")
- // _4 = input(false, "═══════════ Markers ══════════")
- // markerDirection = input(MD1, "Direction", options = [MD1, MD2, MD3])
- // longsOnly = markerDirection == MD2
- // shortsOnly = markerDirection == MD3
- // showMarker1 = input(false, "1. State Transition")
- // marker1Trans = input(BG01, "...Transition", options = [BG01, BG02, BG03, BG04, BG05, BG06, BG07, BG08, BG09, BG10])
- // marker1Confirm = input(BG01, "...Confirmed by", options = [BG01, BG02, BG03, BG04, BG05, BG06, BG07, BG08, BG09, BG10])
- // marker1Filter = input(false, "...Filtered")
- // showMarker2 = input(false, "2. Crosses")
- // marker2Signal = input(LN1, "...Signal", options = [LN1, LN2, LN3, LN4, LN5, LN6, LN7, LN8])
- // marker2Cross = input(LN1, "...Crosses", options = [LN1, LN2, LN3, LN4, LN5, LN6])
- // marker2Confirm = input(BG01, "...Confirmed by", options = [BG01, BG02, BG03, BG04, BG05, BG06, BG07, BG08, BG09, BG10])
- // marker2Filter = input(false, "...Filtered")
- // showMarker3 = input(false, "3. Pivots")
- // marker3Signal = input(LN1, "...Pivot Signal", options = [LN1, LN2, LN3, LN4, LN5, LN6])
- // marker3Confirm = input(BG01, "...Confirmed by", options = [BG01, BG02, BG03, BG04, BG05, BG06, BG07, BG08, BG09, BG10])
- // marker3Filter = input(false, "...Filtered")
- // _5 = input(false, " ")
- // _6 = input(false, "═══════════ Filters ══════════")
- // filter1 = input(false, "1. Bar direction = Trade direction")
- // filter2 = input(false, "2. Bar close higher/lower than previous")
- // filter3 = input(false, "3. Rising Volume")
- // filter4 = input(false, "4. Volume over MA")
- // filter5 = input(false, "5. Chandelier")
- // _7 = input(false, " ")
- // _8 = input(false, "══════════ Parameters ════════")
- // rsiSrc = input(hlc3, "RSI Source")
- // rsiLength = input(20, "RSI Length", minval = 2)
- // rsiLengthHtf = input(40, "HTF RSI Length", minval = 2)
- // obLevel = input(85, "Overbought Level", minval = 50)
- // osLevel = input(20, "Oversold Level", minval = 0)
- // bbLength = input(7, "BB Length", minval = 2)
- // bbMult = input(1.0, "BB Multiplier", minval = 0.0, step = 0.1)
- // bbClamp = input(1.0, "BB clamping to centerline (%)", minval = 0.0, step = 0.5) / 100.
- // htfType = input(TF1, "HTF Selection", options=[TF1, TF2, TF3])
- // htfType2 = input(24, "...2. Multiple of Current TF", minval = 1)
- // htfType3 = input("D", "...3. Fixed TF", type = input.resolution)
- // filter4Len = input(20, "Volume MA Length", minval=2)
- // filter5Len = input(20, "Chandelier Length", minval=2)
- // filter5Mult = input(3, "Chandelier ATR Multiple", minval=0, step=0.25)
- // marker3PivotL = input(4, "Marker 3 Pivot Left Bars", minval=1)
- // marker3PivotR = input(2, "Marker 3 Pivot Right Bars", minval=1)
- // _9 = input(false, " ")
- // }
- // ---------- Bearish Candles
- // // These patterns are identified at following candle so prints need to be offset.
- // atrBars = atr(7)
- // darkCloudCover = barDn[1] and barUp[2] and close[1]<open[2]+(body[2]/2) and close[1]>open[2] and high[1]>high[2] and high<high[1] and body[2]>atrBars*1.5
- // eveningStar = barDn and barDn[1] and barUp[2] and close[1]>=close[2] and close[1]>=open and body[2]>wickHi[2] and body[2]>wickLo[2] and close<open[2]+(body[2]/2)
- // shootingStar = fullHeight>3*nonZeroBody and high>high[1] and wickHi>wickLo and wickHi>atrBars*1.5
- // // These patterns don't require offsetting.
- // engulfingPattern = max(close[1],open[1])<max(close,open) and min(close[1],open[1])>min(close,open) and body>body[1] and barDn and barUp[1]
- // hangingMan = open[1]>open[2] and close[1]>close[2] and wickHi[1]<=body[1] and wickLo[1]>1.2*body[1] and rising(high[1],5) and close<min(open[1],close[1])
- // harami = min(open,close)>min(open[1],close[1]) and max(open,close)<max(open[1],close[1]) and (wickHi>body or wickLo>body) and body[1]>body*2
- // // ---------- Other Candles
- // doji = noMovement or (fullHeight>5*nonZeroBody and (wickLo>body or wickHi>body))
- // hammer = fullHeight>3*body and wickLo>3*nonZeroBody and body>2*wickHi
- // TweezerTolerance = 0.06
- // PinFactor = 1.25
- // UPL = false
- // UPH = false
- // UPL := pivotlow(close,2,2) and RedCandle[2] and GreenCandle //and GreenCandle[1]
- // UPH := pivothigh(close,2,2) and GreenCandle[2] and RedCandle //and RedCandle[1]
- // NoPHInBetween = barssince(UPL[1])<barssince(UPH[1])
- // NoPLInBetween = barssince(UPH[1])<barssince(UPL[1])
- // IncreasingVolume = volume>volume[1]
- // IncreasingVolume2 = IncreasingVolume and IncreasingVolume[1]
- // InsideBar = high<high[1] and low>low[1]
- // InsideBarUp = InsideBar and rising(R2,2) and GreenCandle
- // InsideBarDn = InsideBar and falling(R2,2) and RedCandle
- // ScalingUp = GreenCandle and WickLo+WickHi<Body and WickLo<WickHi and IncreasingVolume
- // ScalingDn = RedCandle and WickLo+WickHi<Body and WickLo>WickHi and IncreasingVolume
- // ScalingUp2 = ScalingUp and ScalingUp[1]
- // ScalingDn2 = ScalingDn and ScalingDn[1]
- // TweezerTop = NonZeroWickHi and NonZeroWickHi[1] and abs(high-high[1])<AbsFullHeight*TweezerTolerance and RedCandle and close<close[1]
- // TweezerBot = NonZeroWickLo and NonZeroWickLo[1] and abs(low-low[1])<AbsFullHeight*TweezerTolerance and GreenCandle and close>close[1]
- // PinTop = WickHi>ATR1*PinFactor and high>high[1] //and GreenCandle[1] and WickHi>2.5*(NonZeroBody+WickLo)
- // PinBot = WickLo>ATR1*PinFactor and low<low[1] //and GreenCandle[1] and WickHi>2.5*(NonZeroBody+WickLo)
- // }
- // // ———————————————————— Markers
- // // {
- // f_signal(_signal, _direction) =>
- // // Returns the value of a signal corresponding to LN? static.
- // // Dependencies: LN?, signals/levels.
- // _signal == LN1 ? myRsi :
- // _signal == LN2 ? myRsiHtf :
- // _signal == LN3 ? deltaRsi :
- // _signal == LN4 ? _direction > 0 ? bbLo : bbHi :
- // _signal == LN5 ? _direction > 0 ? bbLoHtf : bbHiHtf :
- // _signal == LN6 ? _direction > 0 ? bbLoDelta : bbHiDelta :
- // _signal == LN7 ? _direction > 0 ? osLevel : obLevel :
- // _signal == LN8 ? ctrLine : na
- // // ————— Conditions
- // C1U = f_bull(marker1Trans) and not f_bull(marker1Trans)[1] and (marker1Confirm == BG01 or f_bull(marker1Confirm)) and (not marker1Filter or filterLong)
- // C1D = f_bear(marker1Trans) and not f_bear(marker1Trans)[1] and (marker1Confirm == BG01 or f_bear(marker1Confirm)) and (not marker1Filter or filterShort)
- // C2U = crossover(f_signal(marker2Signal, 1), f_signal(marker2Cross, 1)) and (marker2Confirm == BG01 or f_bull(marker2Confirm)) and (not marker2Filter or filterLong)
- // C2D = crossunder(f_signal(marker2Signal, -1), f_signal(marker2Cross, -1)) and (marker2Confirm == BG01 or f_bear(marker2Confirm)) and (not marker2Filter or filterShort)
- // C3U = pivotlow(f_signal(marker3Signal, 1), marker3PivotL, marker3PivotR) > ctrLine and (marker3Confirm == BG01 or f_bull(marker3Confirm)) and (not marker3Filter or filterLong)
- // C3D = pivothigh(f_signal(marker3Signal, -1), marker3PivotL, marker3PivotR) < ctrLine and (marker3Confirm == BG01 or f_bear(marker3Confirm)) and (not marker3Filter or filterShort)
- // // ————— Assembly
- // A1U = showMarker1 and not shortsOnly and C1U
- // A1D = showMarker1 and not longsOnly and C1D
- // A2U = showMarker2 and not shortsOnly and C2U
- // A2D = showMarker2 and not longsOnly and C2D
- // A3U = showMarker3 and not shortsOnly and C3U
- // A3D = showMarker3 and not longsOnly and C3D
- // // ————— Plots
- // plotshape(A1U, "Marker 1 Up", shape.triangleup, location.bottom, myGreenRaw, size = size.tiny, text = "1")
- // plotshape(A1D, "Marker 1 Dn", shape.triangledown, location.top, myRedRaw, size = size.tiny, text = "1")
- // plotshape(A2U, "Marker 2 Up", shape.triangleup, location.bottom, myGreenRaw, size = size.tiny, text = "2")
- // plotshape(A2D, "Marker 2 Dn", shape.triangledown, location.top, myRedRaw, size = size.tiny, text = "2")
- // plotshape(A3U, "Marker 3 Up", shape.triangleup, location.bottom, myGreenRaw, size = size.tiny, text = "3")
- // plotshape(A3D, "Marker 3 Dn", shape.triangledown, location.top, myRedRaw, size = size.tiny, text = "3")
- // // }
- // // ———————————————————— Alert
- // alertcondition( A1U or A1D or A2U or A2D or A3U or A3D, "Visual RSI: Configured Markers", "Visual RSI Marker")
- // // ———————————————————— Signal line (entries only) for the PineCoders Backtesting & Trading Engine
- // // The Engine is here: https://www.tradingview.com/script/dYqL95JB-Backtesting-Trading-Engine-PineCoders/
- // plot(A1U or A2U or A3U ? 2 : A1D or A2D or A3D ? -2 : na, "BTE Signal for Entries", invisible)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement