Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © LordKaan
- //@version=5
- indicator("Pullback BB-OB-MTF-BETA", overlay=true,max_bars_back=100)
- vTF0 = 'None'
- vTF1 = 'Discrete Steps (60min, 1D, 3D, 1W, 1M, 12M)'
- vTF2 = 'Multiple Of Current TF'
- vTF3 = 'Fixed TF'
- Tiny = 'Tiny'
- Small = 'Small'
- Normal = 'Normal'
- Large = 'Large'
- LE = true
- //Inputs
- length = 20
- src = close
- mult = 2
- //OB In
- lookback = 100
- plotBands = false
- plotOb = true
- plotCon = true
- //Calc Bands
- basis = ta.sma(src, length)
- dev = mult * ta.stdev(src, length)
- upper = basis + dev
- lower = basis - dev
- offset = 0
- reachDev = (mult + 0.1) * ta.stdev(src, length)
- upper2 = basis + reachDev
- lower2 = basis - reachDev
- //Order Blocks
- obHigh = ta.highest(upper, lookback)
- obLow = ta.lowest(lower, lookback)
- obHigh2 = ta.highest(upper2, lookback)
- obLow2 = ta.lowest(lower2, lookback)
- // size_ = input.string(Tiny, ' Label Size', options=[Tiny, Small, Normal, Large])
- HTF_1 = true
- vHtfType = input.string(vTF3, ' Higher Timeframe Selection', options=[vTF0, vTF3])
- vHtfType2 = 2
- vHtfType3 = input.timeframe('60', ' Fixed TF')
- vHtfRepaints = true
- vHtfSmooth = true
- smLength = 2
- vOffsetLabels = 4
- var vHtfOn = vHtfType != vTF0
- // SIZE = size.tiny
- // if size_ == 'Tiny'
- // SIZE := size.tiny
- // SIZE
- // else
- // if size_ == 'Small'
- // SIZE := size.small
- // SIZE
- // else
- // if size_ == 'Normal'
- // SIZE := size.normal
- // SIZE
- // else
- // if size_ == 'Large'
- // SIZE := size.large
- // SIZE
- // —————————— PineCoders MTF Selection Framework functions
- // ————— Converts current "timeframe.multiplier" plus the TF 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)
- _resInMinutes
- // ————— Returns resolution of _resolution period in minutes.
- f_tfResInMinutes(_res) =>
- // _res: resolution of any TF (in "timeframe.period" string format).
- request.security(syminfo.tickerid, _res, f_resInMinutes())
- // ————— Given current resolution, returns next step of HTF.
- f_resNextStep(_res) =>
- // _res: current TF in fractional minutes.
- _res <= 1 ? '60' : _res <= 60 ? '1D' : _res <= 360 ? '3D' : _res <= 1440 ? '1W' : _res <= 10080 ? '1M' : '12M'
- // ————— Returns a multiple of current resolution as a string in "timeframe.period" format usable with "security()".
- f_multipleOfRes(_res, _mult) =>
- // _res: current resolution in minutes, in the fractional format supplied by f_resInMinutes() companion function.
- // _mult: Multiple of current TF to be calculated.
- // Convert current float TF in minutes to target string TF in "timeframe.period" format.
- _targetResInMin = _res * math.max(_mult, 1)
- // Find best string to express the resolution.
- _targetResInMin <= 0.083 ? '5S' : _targetResInMin <= 0.251 ? '15S' : _targetResInMin <= 0.501 ? '30S' : _targetResInMin <= 1440 ? str.tostring(math.round(_targetResInMin)) : _targetResInMin <= 43800 ? str.tostring(math.round(math.min(_targetResInMin / 1440, 365))) + 'D' : str.tostring(math.round(math.min(_targetResInMin / 43800, 12))) + 'M'
- // // ————— Print a label at end of chart.
- // f_htfLabel(_txt, _y, _color, _offsetLabels) =>
- // _t = int(time + f_resInMinutes() * _offsetLabels * 60000)
- // // Create the label on the dataset's first bar.
- // var _lbl = label.new(_t, _y, _txt, xloc.bar_time, yloc.price, #00000000, label.style_none, color.gray, SIZE)
- // if barstate.islast
- // // Rather than delete and recreate the label on every realtime bar update,
- // // simply update the label's information; it's more efficient.
- // label.set_xy(_lbl, _t, _y)
- // label.set_text(_lbl, _txt)
- // label.set_textcolor(_lbl, _color)
- // }
- // ————— HTF calcs
- // Get current resolution in float minutes.
- var vResInMinutes = f_resInMinutes()
- // Get HTF from user-defined mode.
- var vHtf = vHtfType == vTF1 ? f_resNextStep(vResInMinutes) : vHtfType == vTF2 ? f_multipleOfRes(vResInMinutes, vHtfType2) : vHtfType3
- vHtfSmoothLen = math.max(2, smLength)
- BBHTF_1 = HTF_1 and not vHtfOn ? basis : vHtfRepaints ? request.security(syminfo.tickerid, vHtf, basis) : request.security(syminfo.tickerid, vHtf, basis[1], lookahead=barmerge.lookahead_on)
- BBHTF_1 := HTF_1 and vHtfOn and vHtfSmooth ? ta.ema(ta.ema(ta.ema(BBHTF_1, vHtfSmoothLen), vHtfSmoothLen), vHtfSmoothLen) : BBHTF_1
- upperHTF_1 = HTF_1 and not vHtfOn ? upper : vHtfRepaints ? request.security(syminfo.tickerid, vHtf, upper) : request.security(syminfo.tickerid, vHtf, upper[1], lookahead=barmerge.lookahead_on)
- upperHTF_1 := HTF_1 and vHtfOn and vHtfSmooth ? ta.ema(ta.ema(ta.ema(upperHTF_1, vHtfSmoothLen), vHtfSmoothLen), vHtfSmoothLen) : upperHTF_1
- lowerHTF_1 = HTF_1 and not vHtfOn ? lower : vHtfRepaints ? request.security(syminfo.tickerid, vHtf, lower) : request.security(syminfo.tickerid, vHtf, lower[1], lookahead=barmerge.lookahead_on)
- lowerHTF_1 := HTF_1 and vHtfOn and vHtfSmooth ? ta.ema(ta.ema(ta.ema(lowerHTF_1, vHtfSmoothLen), vHtfSmoothLen), vHtfSmoothLen) : lowerHTF_1
- obHighHTF_1 = HTF_1 and not vHtfOn ? obHigh : vHtfRepaints ? request.security(syminfo.tickerid, vHtf, obHigh ) : request.security(syminfo.tickerid, vHtf, obHigh [1], lookahead=barmerge.lookahead_on)
- obHighHTF_1 := HTF_1 and vHtfOn and vHtfSmooth ? ta.ema(ta.ema(ta.ema(obHighHTF_1, vHtfSmoothLen), vHtfSmoothLen), vHtfSmoothLen) : obHighHTF_1
- obLowHTF_1 = HTF_1 and not vHtfOn ? obLow : vHtfRepaints ? request.security(syminfo.tickerid, vHtf, obLow ) : request.security(syminfo.tickerid, vHtf, obLow [1], lookahead=barmerge.lookahead_on)
- obLowHTF_1 := HTF_1 and vHtfOn and vHtfSmooth ? ta.ema(ta.ema(ta.ema(obLowHTF_1, vHtfSmoothLen), vHtfSmoothLen), vHtfSmoothLen) : obLowHTF_1
- obHigh2HTF_1 = HTF_1 and not vHtfOn ? obHigh : vHtfRepaints ? request.security(syminfo.tickerid, vHtf, obHigh2 ) : request.security(syminfo.tickerid, vHtf, obHigh2 [1], lookahead=barmerge.lookahead_on)
- obHigh2HTF_1 := HTF_1 and vHtfOn and vHtfSmooth ? ta.ema(ta.ema(ta.ema(obHigh2HTF_1, vHtfSmoothLen), vHtfSmoothLen), vHtfSmoothLen) : obHigh2HTF_1
- obLow2HTF_1 = HTF_1 and not vHtfOn ? obLow2 : vHtfRepaints ? request.security(syminfo.tickerid, vHtf, obLow2 ) : request.security(syminfo.tickerid, vHtf, obLow2 [1], lookahead=barmerge.lookahead_on)
- obLow2HTF_1 := HTF_1 and vHtfOn and vHtfSmooth ? ta.ema(ta.ema(ta.ema(obLow2HTF_1, vHtfSmoothLen), vHtfSmoothLen), vHtfSmoothLen) : obLow2HTF_1
- // }
- // ———————————————————— Plots
- // {
- //Plots
- //Upper Order Block
- o1 = plot(plotOb ? plotCon ? obHighHTF_1==obHighHTF_1[1] ? obHighHTF_1 : na : obHighHTF_1 :na, title="Order Block High", color=#FF0000, style=plot.style_linebr)
- o2 = plot(plotOb ? plotCon ? obHighHTF_1==obHighHTF_1[1] ? obHigh2HTF_1 : na : obHigh2HTF_1 :na, title="Order Block High 2", color=#FF0000, style=plot.style_linebr)
- fill(o1,o2, color=color.new(#FF0000,80), title="Sell Fill")
- //Lower Order Block
- o3 = plot(plotOb ? plotCon ? obLowHTF_1==obLowHTF_1[1] ? obLowHTF_1 : na : obLowHTF_1 :na, title="Order Block Low", color=#00E600, style=plot.style_linebr)
- o4 = plot(plotOb ? plotCon ? obLowHTF_1==obLowHTF_1[1] ? obLow2HTF_1 : na : obLow2HTF_1 :na, title="Order Block Low 2", color=#00E600, style=plot.style_linebr)
- fill(o3,o4, color=color.new(#00E600,80), title="Buy Fill")
- //Plot bands
- //plot(plotBands ? basis : na, "Basis", color=#FF6D00, offset = offset)
- //p1 = plot(plotBands ? upper : na, "Upper", color=#2962FF, offset = offset)
- //p2 = plot(plotBands ? lower : na, "Lower", color=#2962FF, offset = offset)
- //Conditions
- upperob = plotOb ? plotCon ? obHighHTF_1==obHighHTF_1[1] ? obHighHTF_1 : na : obHighHTF_1 :na
- lowerob = plotOb ? plotCon ? obLowHTF_1==obLowHTF_1[1] ? obLowHTF_1 : na : obLowHTF_1 :na
- upperob2 = plotOb ? plotCon ? obHighHTF_1==obHighHTF_1[1] ? obHigh2HTF_1 : na : obHigh2HTF_1 :na
- lowerob2 = plotOb ? plotCon ? obLowHTF_1==obLowHTF_1[1] ? obLow2HTF_1 : na : obLow2HTF_1 :na
- gobear = high > upperob and close < upperob
- gobull = low < lowerob and close > lowerob
- plotshape(gobear, text='Be', style=shape.labeldown, color=color.new(color.white, 100), textcolor=color.new(color.red, 0), location=location.abovebar)
- plotshape(gobull, text='Bu', style=shape.labelup, color=color.new(color.white, 100), textcolor=color.new(color.lime, 0), location=location.belowbar)
- alertcondition(gobear,title="Potential Bearish", message="Potential bearish ")
- alertcondition(gobull,title="Potential Bullish", message="Potential bullish ")
- // // check any condition you needed to fire
- // checkForAlert()=>
- // alertMsg = ""
- // // check for potential rejection from bullish OB
- // if gobull
- // alertMsg += str.format("Potential Bullish rejection for {0}!\n", syminfo.tickerid,alert.freq_once_per_bar_close)
- // // ccheck for potential rejection from bearish OB
- // if gobear
- // alertMsg += str.format("Potential Bearish rejection for {0}!\n", syminfo.tickerid,alert.freq_once_per_bar_close)
- // // check for odd
- // //if bar_index % 2 == 0
- // // alertMsg += str.format("bar index is odd for {0}!\n", syminfo.ticker)
- // // any other checks needed
- // alertMsg
- // fireAlert(ticker, freq = alert.freq_once_per_bar_close)=>
- // msg = request.security(ticker, timeframe.period, checkForAlert())
- // if str.length(msg) > 0
- // alert(msg, freq)
- // Symbol1 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol2 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol3 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol4 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol5 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol6 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol7 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol8 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol9 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol10 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol11 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol12 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol13 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol14 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // Symbol15 = input.symbol("", title="Alert Symbols", group = "Select Symbols you want an alert from (Once Per Bar ONLY) -- Only need to create 1 'Any alert () function call'")
- // fireAlert(Symbol1)
- // fireAlert(Symbol2)
- // fireAlert(Symbol3)
- // fireAlert(Symbol4)
- // fireAlert(Symbol5)
- // fireAlert(Symbol6)
- // fireAlert(Symbol7)
- // fireAlert(Symbol8)
- // fireAlert(Symbol9)
- // fireAlert(Symbol10)
- // fireAlert(Symbol11)
- // fireAlert(Symbol12)
- // fireAlert(Symbol13)
- // fireAlert(Symbol14)
- // fireAlert(Symbol15)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement