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/
- // https://docs.google.com/drawings/d/16COpQpKyvTaH4LYwAmTfXl-ApHo5uuaMDYGcdng5WVk/edit
- // Β© AVAndronov
- //@version=5
- // INITIALISATION SETTINGS
- float INITIAL_CAPITAL = 1000000
- float DEFAULT_COMMISSION = 0.06
- int MAX_DRAWINGS = 500
- int PYRAMIDING = 0
- bool IS_OVERLAY = true
- int MAX_BARS_BACK = 5000
- // // Stable
- // // Dev
- //strategy("Magnum Opus ", overlay = IS_OVERLAY, max_bars_back = MAX_BARS_BACK, pyramiding = PYRAMIDING, initial_capital = INITIAL_CAPITAL,
- // currency = currency.NONE, max_labels_count = MAX_DRAWINGS, max_boxes_count = MAX_DRAWINGS, max_lines_count = MAX_DRAWINGS,
- // default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent,
- // commission_value = DEFAULT_COMMISSION, close_entries_rule="ANY")
- indicator("Magnum Opus Dev", overlay = IS_OVERLAY, max_bars_back = MAX_BARS_BACK, max_labels_count = MAX_DRAWINGS, max_boxes_count = MAX_DRAWINGS,
- max_lines_count = MAX_DRAWINGS)
- // Plot Bar Index so we can easilly find what bar to start / end on
- plotshape(bar_index, "bar_index", shape.flag, color = na)
- // --------------------------------------------------------------
- // 01 SETTINGS
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 01.02 SETTINGS | CONSTS
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 01.02.01 SETTINGS | CONSTS | LIBRARY SETTINGS
- // --------------------------------------------------------------
- bool SHOW_DEBUG_TEXT = true
- bool SHOW_DEBUG_LINES = true
- bool SHOW_DEBUG_BOXES = true
- // --------------------------------------------------------------
- // 01.02.02 SETTINGS | CONSTS | BOS STYLES
- // --------------------------------------------------------------
- // Used to need this to save plots, not anymore
- // --------------------------------------------------------------
- // 01.02 SETTINGS | INPUTS
- // --------------------------------------------------------------
- // DEBUG SETTINGS
- gd = "DEBUG"
- DBG_DebugEnabled = input.bool(true, "DEBUG ENABLED", group = gd, tooltip = "Master Switch.\n\nWithout it neither of the following options in this group will work")
- DBG_DisableTrim = input.bool(false, "Disable Array Trimming", group = gd)
- DBG_FirstLimitOn = input.bool(false, "First Bar", group = gd, inline="gdi1")
- DBG_FirstBarLimit = input.int(0, "", group = gd, inline="gdi1")
- DBG_LastLimitOn = input.bool(false, "Last Bar", group = gd, inline="gdi1")
- DBG_LastBarLimit = input.int(0, "", group = gd, inline="gdi1")
- DBG_FirstBar = (DBG_DebugEnabled and DBG_FirstLimitOn) ? DBG_FirstBarLimit : na
- DBG_LastBar = (DBG_DebugEnabled and DBG_LastLimitOn) ? DBG_LastBarLimit : na
- DBG_ShowPriceActionRecognitionEnabled = input.bool(false, "Show Price Leg Recognition:", group = gd, inline="gdi3")
- DBG_ShowPriceActionRecognitionCtf = input.bool(true, "CTF", group = gd, inline="gdi3")
- DBG_ShowPriceActionRecognitionHtf = input.bool(false, "HTF", group = gd, inline="gdi3")
- DBG_ShowPriceActionRecognitionSingleDirection = input.bool(true, " π π Only current direction", group = gd, inline="gdi5")
- DBG_ShowPriceActionRecognitionLines = input.bool(true, "High/Low", group = gd, inline="gdi5")
- DBG_ShowPriceActionRecognitionBoxes = input.bool(true, "Close/Reverse", group = gd, inline="gdi5")
- DBG_ShowPriceActionRecognitionBounds = input.bool(true, "Bounds", group = gd, inline="gdi5")
- DBG_VerboseBosCheckDoOutput = input.bool(false, "Show Price Leg Evaluation: ", group = gd, inline="gdi4")
- DBG_VerboseBosCheckOutputCtf = input.bool(true, "CTF", group = gd, inline="gdi4")
- DBG_VerboseBosCheckOutputHtf = input.bool(false, "HTF", group = gd, inline="gdi4")
- DBG_VerboseBosCheckOnlySuccess = input.bool(false, " π π Only successfull checks", group = gd, inline="gdi6")
- DBG_VerboseBosCheckDetailed = input.bool(true, "Detailed check results", group = gd, inline="gdi6")
- DBG_VerboseBosCheckCompact = input.bool(true, "Compact", group = gd, inline="gdi6")
- DBG_ShowHTFDebugPlots = input.bool(false, "Show Debug HTF Plots - Candle Values and Pivots", group = gd)
- DBG_ShowHLCDebugPlots = input.bool(false, "Show Debug CTF Highest/Lowest Close Plots", group = gd)
- DBG_DisableTrimEnabled = DBG_DisableTrim and DBG_DebugEnabled
- g4 = "Display Settings"
- showPPEnabled = input.bool(false, "Show HH/LL Points:", group = g4, inline="g4i5")
- showPPCtf = input.bool(true, "CTF ", group = g4, inline="g4i5")
- showPPHtf = input.bool(true, "HTF ", group = g4, inline="g4i5")
- showHhLlLevels = input.bool(false, "Show HH/LL Levels π π π π CTF", group = g4, inline="g4i2")
- showHhLlLevelsOrigin = input.bool(true, "To Origin", group = g4, inline="g4i2")
- showBosEnabled = input.bool(true, "Show BOS Levels:", group = g4, tooltip = "Show BOS levels, as calcualted by algorithm. \n\n"+
- "If Core is set to [None], then To Origin won't display regardless")
- bosStyleOption0 = "[Same]"
- bosStyleOption1 = "[None]"
- bosStyleOption2 = "Line x1"
- bosStyleOption3 = "Fill"
- bosStyleOption4 = "Line x2"
- bosStyleOption5 = "Line x1 + Fill"
- bosStyleOption6 = "[Full] Line x2 + Fill"
- showBosCtfMainText = input.string(bosStyleOption6, "CTF: Core", group = g4, inline="g4i6",
- options = [bosStyleOption1, bosStyleOption2, bosStyleOption3, bosStyleOption4, bosStyleOption5, bosStyleOption6])
- showBosCtfOriginText = input.string(bosStyleOption4, "to Origin", group = g4, inline="g4i6",
- options = [bosStyleOption0, bosStyleOption1, bosStyleOption2, bosStyleOption3, bosStyleOption4, bosStyleOption5, bosStyleOption6])
- _11 = "1/1"
- _21 = "2/1"
- _32 = "3/2"
- _42 = "4/2"
- _43 = "4/3"
- _44 = "4/4"
- showBosCtfWidth = input.string(_21, "Width", group = g4, inline="g4i6",
- options = [_11,_21,_32,_42,_43,_44])
- showBosHtfMainText = input.string(bosStyleOption6, "HTF: Core", group = g4, inline="g4i7",
- options = [bosStyleOption1, bosStyleOption2, bosStyleOption3, bosStyleOption4, bosStyleOption5, bosStyleOption6])
- showBosHtfOriginText = input.string(bosStyleOption4, "to Origin", group = g4, inline="g4i7",
- options = [bosStyleOption0, bosStyleOption1, bosStyleOption2, bosStyleOption3, bosStyleOption4, bosStyleOption5, bosStyleOption6])
- showBosHtfWidth = input.string(_11, "Width", group = g4, inline="g4i7",
- options = [_11, _21,_32,_42,_43,_44])
- [showBosCtfMainLine, showBosCtfAuxLine, showBosCtfFill] = switch showBosCtfMainText
- bosStyleOption1 => [false,false,false]
- bosStyleOption2 => [true,false,false]
- bosStyleOption3 => [false,false,true]
- bosStyleOption4 => [true,true,false]
- bosStyleOption5 => [true,false,true]
- bosStyleOption6 => [true,true,true]
- [showBosHtfMainLine, showBosHtfAuxLine, showBosHtfFill] = switch showBosHtfMainText
- bosStyleOption1 => [false,false,false]
- bosStyleOption2 => [true,false,false]
- bosStyleOption3 => [false,false,true]
- bosStyleOption4 => [true,true,false]
- bosStyleOption5 => [true,false,true]
- bosStyleOption6 => [true,true,true]
- [showBosCtfOriginMainLine, showBosCtfOriginAuxLine, showBosCtfOriginFill] = switch showBosCtfOriginText
- bosStyleOption0 => [showBosCtfMainLine, showBosCtfAuxLine, showBosCtfFill]
- bosStyleOption1 => [false,false,false]
- bosStyleOption2 => [true,false,false]
- bosStyleOption3 => [false,false,true]
- bosStyleOption4 => [true,true,false]
- bosStyleOption5 => [true,false,true]
- bosStyleOption6 => [true,true,true]
- [showBosHtfOriginMainLine, showBosHtfOriginAuxLine, showBosHtfOriginFill] = switch showBosHtfOriginText
- bosStyleOption0 => [showBosHtfMainLine, showBosHtfAuxLine, showBosHtfFill]
- bosStyleOption1 => [false,false,false]
- bosStyleOption2 => [true,false,false]
- bosStyleOption3 => [false,false,true]
- bosStyleOption4 => [true,true,false]
- bosStyleOption5 => [true,false,true]
- bosStyleOption6 => [true,true,true]
- showBosCtfOriginMainLine := showBosCtfOriginMainLine and showBosCtfMainText != bosStyleOption1
- showBosCtfOriginAuxLine := showBosCtfOriginAuxLine and showBosCtfMainText != bosStyleOption1
- showBosCtfOriginFill := showBosCtfOriginFill and showBosCtfMainText != bosStyleOption1
- showBosHtfOriginMainLine := showBosHtfOriginMainLine and showBosHtfMainText != bosStyleOption1
- showBosHtfOriginAuxLine := showBosHtfOriginAuxLine and showBosHtfMainText != bosStyleOption1
- showBosHtfOriginFill := showBosHtfOriginFill and showBosHtfMainText != bosStyleOption1
- showBosCtfWidthMain = showBosCtfWidth == _44 or showBosCtfWidth == _43 or showBosCtfWidth == _42 ? 4 :
- showBosCtfWidth == _32 ? 3 : showBosCtfWidth == _21 ? 2 : 1
- showBosCtfWidthAux = showBosCtfWidth == _44 ? 4 : showBosCtfWidth == _43 ? 3 :
- showBosCtfWidth == _42 or showBosCtfWidth == _32 ? 2 : 1
- showBosHtfWidthMain = showBosHtfWidth == _44 or showBosHtfWidth == _43 or showBosHtfWidth == _42 ? 4 :
- showBosHtfWidth == _32 ? 3 : showBosHtfWidth == _21 ? 2 : 1
- showBosHtfWidthAux = showBosHtfWidth == _44 ? 4 : showBosHtfWidth == _43 ? 3 :
- showBosHtfWidth == _42 or showBosHtfWidth == _32 ? 2 : 1
- showCBosEnabled = input.bool(true, " π π Show Classic BOS Levels:", group = g4,
- tooltip = "Show classic BOS levels, meaning, furthest end of correction before continuation.\n\n"+
- "If BOS levels are hidden or have Core set to [None], then Classic levels won't display.\n\n"+
- "If Classic BOS Core is set to [None], then To Origin won't display regardless.")
- showCBosCtfMainText = input.string(bosStyleOption6, "CTF: Core", group = g4, inline="g4i8",
- options = [bosStyleOption1, bosStyleOption2, bosStyleOption3, bosStyleOption4, bosStyleOption5, bosStyleOption6])
- showCBosCtfOriginText = input.string(bosStyleOption4, "to Origin", group = g4, inline="g4i8",
- options = [bosStyleOption0, bosStyleOption1, bosStyleOption2, bosStyleOption3, bosStyleOption4, bosStyleOption5, bosStyleOption6])
- showCBosCtfWidth = input.string(_21, "Width", group = g4, inline="g4i8",
- options = [_11,_21,_32,_42,_43,_44])
- showCBosHtfMainText = input.string(bosStyleOption6, "HTF: Core", group = g4, inline="g4i9",
- options = [bosStyleOption1, bosStyleOption2, bosStyleOption3, bosStyleOption4, bosStyleOption5, bosStyleOption6])
- showCBosHtfOriginText = input.string(bosStyleOption4, "to Origin", group = g4, inline="g4i9",
- options = [bosStyleOption0, bosStyleOption1, bosStyleOption2, bosStyleOption3, bosStyleOption4, bosStyleOption5, bosStyleOption6])
- showCBosHtfWidth = input.string(_11, "Width", group = g4, inline="g4i9",
- options = [_11, _21,_32,_42,_43,_44])
- showCBosHideCollision = input.bool(true, " π π Hide CTF Classic BOS if colliding with HTF BOS", group = g4)
- [showCBosCtfMainLine, showCBosCtfAuxLine, showCBosCtfFill] = switch showCBosCtfMainText
- bosStyleOption1 => [false,false,false]
- bosStyleOption2 => [true,false,false]
- bosStyleOption3 => [false,false,true]
- bosStyleOption4 => [true,true,false]
- bosStyleOption5 => [true,false,true]
- bosStyleOption6 => [true,true,true]
- [showCBosHtfMainLine, showCBosHtfAuxLine, showCBosHtfFill] = switch showCBosHtfMainText
- bosStyleOption1 => [false,false,false]
- bosStyleOption2 => [true,false,false]
- bosStyleOption3 => [false,false,true]
- bosStyleOption4 => [true,true,false]
- bosStyleOption5 => [true,false,true]
- bosStyleOption6 => [true,true,true]
- [showCBosCtfOriginMainLine, showCBosCtfOriginAuxLine, showCBosCtfOriginFill] = switch showCBosCtfOriginText
- bosStyleOption0 => [showCBosCtfMainLine, showCBosCtfAuxLine, showCBosCtfFill]
- bosStyleOption1 => [false,false,false]
- bosStyleOption2 => [true,false,false]
- bosStyleOption3 => [false,false,true]
- bosStyleOption4 => [true,true,false]
- bosStyleOption5 => [true,false,true]
- bosStyleOption6 => [true,true,true]
- [showCBosHtfOriginMainLine, showCBosHtfOriginAuxLine, showCBosHtfOriginFill] = switch showCBosHtfOriginText
- bosStyleOption0 => [showCBosHtfMainLine, showCBosHtfAuxLine, showCBosHtfFill]
- bosStyleOption1 => [false,false,false]
- bosStyleOption2 => [true,false,false]
- bosStyleOption3 => [false,false,true]
- bosStyleOption4 => [true,true,false]
- bosStyleOption5 => [true,false,true]
- bosStyleOption6 => [true,true,true]
- showCBosCtfMainLine := showCBosCtfMainLine and showBosCtfMainText != bosStyleOption1
- showCBosCtfAuxLine := showCBosCtfAuxLine and showBosCtfMainText != bosStyleOption1
- showCBosCtfFill := showCBosCtfFill and showBosCtfMainText != bosStyleOption1
- showCBosHtfMainLine := showCBosHtfMainLine and showBosHtfMainText != bosStyleOption1
- showCBosHtfAuxLine := showCBosHtfAuxLine and showBosHtfMainText != bosStyleOption1
- showCBosHtfFill := showCBosHtfFill and showBosHtfMainText != bosStyleOption1
- showCBosCtfOriginMainLine := showCBosCtfOriginMainLine and showCBosCtfMainText != bosStyleOption1 and showBosCtfMainText != bosStyleOption1
- showCBosCtfOriginAuxLine := showCBosCtfOriginAuxLine and showCBosCtfMainText != bosStyleOption1 and showBosCtfMainText != bosStyleOption1
- showCBosCtfOriginFill := showCBosCtfOriginFill and showCBosCtfMainText != bosStyleOption1 and showBosCtfMainText != bosStyleOption1
- showCBosHtfOriginMainLine := showCBosHtfOriginMainLine and showCBosHtfMainText != bosStyleOption1 and showBosHtfMainText != bosStyleOption1
- showCBosHtfOriginAuxLine := showCBosHtfOriginAuxLine and showCBosHtfMainText != bosStyleOption1 and showBosHtfMainText != bosStyleOption1
- showCBosHtfOriginFill := showCBosHtfOriginFill and showCBosHtfMainText != bosStyleOption1 and showBosHtfMainText != bosStyleOption1
- showCBosCtfWidthMain = showCBosCtfWidth == _44 or showCBosCtfWidth == _43 or showCBosCtfWidth == _42 ? 4 :
- showCBosCtfWidth == _32 ? 3 : showCBosCtfWidth == _21 ? 2 : 1
- showCBosCtfWidthAux = showCBosCtfWidth == _44 ? 4 : showCBosCtfWidth == _43 ? 3 :
- showCBosCtfWidth == _42 or showCBosCtfWidth == _32 ? 2 : 1
- showCBosHtfWidthMain = showCBosHtfWidth == _44 or showCBosHtfWidth == _43 or showCBosHtfWidth == _42 ? 4 :
- showCBosHtfWidth == _32 ? 3 : showCBosHtfWidth == _21 ? 2 : 1
- showCBosHtfWidthAux = showCBosHtfWidth == _44 ? 4 : showCBosHtfWidth == _43 ? 3 :
- showCBosHtfWidth == _42 or showCBosHtfWidth == _32 ? 2 : 1
- g11 = "Trend Display Settings"
- showTrendOptionNone = "None"
- showTrendOptionCtf = "Current"
- showTrendOptionHtf = "Higher"
- showTrendBGText = input.string(showTrendOptionNone, "Trend Display: Background", group = g11,
- options = [showTrendOptionNone, showTrendOptionCtf, showTrendOptionHtf])
- showTrendBG = showTrendBGText == showTrendOptionNone ? 0 : showTrendBGText == showTrendOptionCtf ? 1 : 2
- showTrendAboveText = input.string(showTrendOptionCtf, "Trend Display: Above", group = g11,
- options = [showTrendOptionNone, showTrendOptionCtf, showTrendOptionHtf])
- showTrendAbove = showTrendAboveText == showTrendOptionNone ? 0 : showTrendAboveText == showTrendOptionCtf ? 1 : 2
- showTrendBelowText = input.string(showTrendOptionHtf, "Trend Display: Below", group = g11,
- options = [showTrendOptionNone, showTrendOptionCtf, showTrendOptionHtf])
- showTrendBelow = showTrendBelowText == showTrendOptionNone ? 0 : showTrendBelowText == showTrendOptionCtf ? 1 : 2
- showTrendLabels = input.bool(false, "Show Trend Change Labels", group = g11, inline = "g11i1")
- showTrendLabelsCtf = input.bool(true, "CTF", group = g11, inline = "g11i1")
- showTrendLabelsHtf = input.bool(false, "HTF", group = g11, inline = "g11i1")
- g13 = "Trend and BOS Algo Settings"
- maxInitialCandlesToDetermineTrend = input.int(5, "Max candles to determine the initial trend", group = g13,
- tooltip = "After receiving starting bar, wait this many candles before forcing determination of the initial trend.\n\n"+
- "Within this limit, the algorithm tries to be smart and detect the first price leg (high-low-higher high, or low-high-lower low), but once enough bars elapse, "+
- "a simple choice will be made based on whether the starting bar's high or low was breached first. \n\nIf price stayed within the high and low of the first bar, then "+
- "the choice will be made based on whether the first bar was bearish or bullish, with a bias towards bullish (in rare cases when open = close)")
- initialTrendOption1 = "None"
- initialTrendOption2 = "Long"
- initialTrendOption3 = "Short"
- initialCtfTrend = input.string(initialTrendOption1, "Initial Trend CTF", group = g13, inline = "g13i2",
- options = [initialTrendOption1, initialTrendOption2, initialTrendOption3])
- initialHtfTrend = input.string(initialTrendOption1, "HTF", group = g13, inline = "g13i2",
- options = [initialTrendOption1, initialTrendOption2, initialTrendOption3], tooltip = "Force initial trend or let it be determined by the algorithm")
- var initialCtfTrendDirection = initialCtfTrend == initialTrendOption1 ? 0 : initialCtfTrend == initialTrendOption2 ? 2 : -2
- var initialHtfTrendDirection = initialHtfTrend == initialTrendOption1 ? 0 : initialHtfTrend == initialTrendOption2 ? 2 : -2
- calculateHtfTrendEnabled = input.bool(true, "Calculate HTF Trend & BOS, with HTF determined", group = g13, inline = "g13i1")
- chooseHtfMethodOptionSequential = "Sequentially: 5m/15m/30m/1H/4H/1D/1W/1M"
- chooseHtfMethodOptionSkip = "Skipping: 1m/5m/30m/4H/1D/1W/1M"
- chooseHtfMethodText = input.string(chooseHtfMethodOptionSkip, "", group = g13, inline = "g13i1",
- options = [chooseHtfMethodOptionSequential, chooseHtfMethodOptionSkip], tooltip ="The way HTF is chosen for calculating HTF trend.\n\n"+
- chooseHtfMethodOptionSequential+"\nNext higher timeframe is chosen, in order, so for anything up to 5m, the 5m TF is chosen, for anything up to 30m, "+
- "the 30m TF is chosen etc.\n\n"+
- chooseHtfMethodOptionSkip+"\nHigher timeframe is chosen skipping intermediary timeframes. So, for anything up to and including 1m, the 5m TF is chosen, "+
- "then for anything up to and including 5m, the 30m TF is chosen, for for anything up to and including 30m, the 4H TF is chosen, etc")
- var chooseHtfSkip = chooseHtfMethodText == chooseHtfMethodOptionSkip
- // This is used in code to query HTF used for calculations
- var chosenHtf =
- // DUPLICATE CODE
- // BECAUSE OF PINESCRIPT SHENANIGANS
- not calculateHtfTrendEnabled ? "1M" : chooseHtfSkip ?
- (timeframe.in_seconds() <= timeframe.in_seconds("1") ? "5" :
- timeframe.in_seconds() <= timeframe.in_seconds("5") ? "30" :
- timeframe.in_seconds() <= timeframe.in_seconds("30") ? "240" :
- timeframe.in_seconds() <= timeframe.in_seconds("240") ? "1D" :
- timeframe.in_seconds() <= timeframe.in_seconds("1D") ? "1W" :
- timeframe.in_seconds() <= timeframe.in_seconds("1W") ? "1M" : "1M")
- :
- (timeframe.in_seconds() < timeframe.in_seconds("1") ? "1" :
- timeframe.in_seconds() < timeframe.in_seconds("5") ? "5" :
- timeframe.in_seconds() < timeframe.in_seconds("15") ? "15" :
- timeframe.in_seconds() < timeframe.in_seconds("30") ? "30" :
- timeframe.in_seconds() < timeframe.in_seconds("60") ? "60" :
- timeframe.in_seconds() < timeframe.in_seconds("240") ? "240" :
- timeframe.in_seconds() < timeframe.in_seconds("1D") ? "1D" :
- timeframe.in_seconds() < timeframe.in_seconds("1W") ? "1W" :
- timeframe.in_seconds() < timeframe.in_seconds("1M") ? "1M" : "1M")
- // This is used in code to check whether we are calculating htf trend or not
- calculateHtfTrend = calculateHtfTrendEnabled and timeframe.in_seconds() < timeframe.in_seconds(chosenHtf)
- g3 = "HH LL Settings"
- ctfpivPLeft = input.int(2, "Pivot Point Period: Left", minval = 1, group = g3, inline="g3i1")
- ctfpivPer = input.int(0, "Right", minval = 0, group = g3, inline="g3i1")
- ctfcheckAdjacentPivotThreshold = input.float(1.0, "Pivot Point Adjacency Threshold (%)",minval = 0, step = 0.01, group = g3,
- tooltip = "If pivot period left is at least 2, and pivot point was not found because adjacent candle's wick is slightly off by this much percent, in price, "+
- "but open/close is within this much percent, and otherwise there is a clear pivot point there, consider it a pivot point.\n\n"+
- "0 = Only consider true fractal pivot points\n\n"+
- "Example: For a short pivot point with a left period of 2, low of this candle must be lower than 2 previous lows. In case \"1\" is set for this input, "+
- "a short pivot point will be accepted also if all of the following conditions are met: \n"+
- "a) this candle's low is lower than all lows except the last low\n"+
- "b) this candle's body low (close or open, whichever lowest) is lower or within 1% of the previous one\n"+
- "c) this candle's low is within 1% of the previous one")
- g9 = "BOS & HL Break Settings"
- ctfHLBreakThreshold = input.float(0.25, "High/Low Break Threshold (%)",minval = 0, step = 0.1, group = g9,
- tooltip = "Prior High / Low is considered broken only when price exceeds it by this much percent")
- ctfHLBreakATREnabled = input.bool(true, " π π Use ATR instead, Len.", group = g9, inline = "g9i1")
- ctfHLBreakATRLength = input.int(14, "",minval = 1, group = g9, inline = "g9i1")
- ctfHLBreakATRThreshold = input.float(12, "Thr. (%)",minval = 0, step = 0.1, group = g9, inline = "g9i1",
- tooltip = "Prior High / Low is considered broken when price exceeds it by ATR value mutliplied by this much percent")
- newBosConfirmOptionWithin = "At least within old BOS"
- newBosConfirmOptionPartiallyOutside = "Partially outside old BOS"
- newBosConfirmOptionBeyond = "Completely beyond old BOS"
- ctfnewBosConfirmConditionString = input.string(newBosConfirmOptionPartiallyOutside, "BOS Break is finalized when new BOS is", group = g9,
- options = [newBosConfirmOptionWithin, newBosConfirmOptionPartiallyOutside, newBosConfirmOptionBeyond],
- tooltip = "Trend changes when BOS is breached. But after the BOS is breached, new trend's BOS cannot be located "+
- "between the old extreme (high for an uptrend, low for a downtrend) and the old BOS, "+
- "as it would make no sense.\n\nTherefore, new BOS must be located at least beyond the closest boundary of the old BOS (top for a short BOS, bottom for a long BOS). "+
- "This setting controls how far must new BOS be located for it to be accepted and for trend break to be finalized.\n\n"+
- "\"At least within old BOS\":\nOnce the new BOS is beyond the closest boundary of an old BOS it's accepted as a new BOS and trend break is finalized. "+
- "For example, for a trend to change from long to short, it means that the new long BOS must be below old short BOS's top bound. "+
- "It may be within old BOS, it just has to clear the area between the high and the beginning of the old BOS\n\n"+
- "\"Beyond old BOS\":\nOnly once the new BOS is beyond the furthest boundary of an old BOS it's accepted as a new BOS and trend break is finalized. "+
- "For example, for a trend to change from long to short, it means that the new long BOS must be below old short BOS's bottom bound. "+
- "It has to be completely below the old BOS.")
- ctfnewBosConfirmConditionLevel = ctfnewBosConfirmConditionString == newBosConfirmOptionPartiallyOutside ? 2 :
- ctfnewBosConfirmConditionString == newBosConfirmOptionBeyond ? 1 : 0
- ctfnewBosThreshold = input.float(0.4, "BOS Condition Check Threshold (%)",minval = 0, step = 0.1, group = g9,
- tooltip = "Conditions that check below/above/beyond BOS must be met with an additional offset of this much percent, in absoulte price movement.\n\n"+
- "For example, for candle being beyond BOS, it must not just differ by 1 tick, but by this much percent. Same way, for new BOS to be beyond old BOS, "+
- "1 tick is not enough, it must be this much percent")
- g7 = "BOS Break Conditions - \"OR\" - At least one must be true"
- ctfbosBreakCandleThresholdOr = input.int(2 , "Candlesπ π π π π π π π π π π π π π π π π π π π π π π π", minval = 1, group = g7, inline="g7i1",
- tooltip = "This many candles must be completely beyond BOS to confirm a BOS break")
- ctfusebosBreakCandleThresholdOr = input.bool(true,"ON",group = g7, inline="g7i1")
- g8 = "BOS Break Conditions - \"AND\" - Every condition must be true"
- ctfbosBreakCandleThresholdAnd = input.int(2 , "Candlesπ π π π π π π π π π π π π π π π π π π π π π π π", minval = 1, group = g8, inline="g8i1",
- tooltip = "This many candles must be completely beyond BOS to confirm a BOS break")
- ctfusebosBreakCandleThresholdAnd = input.bool(false,"ON",group = g8, inline="g8i1")
- g10 = "BOS Change Settings"
- ctfbosConsiderNextEnabled = input.bool(true, "Consider further options within (%)", group = g10, inline="g10i1",
- tooltip = "When choosing a pivot point to become a new BOS, and current one passes all conditions, consider the next one if it is within this much "+
- "percent from the current one. \n\nFor example, in a downtrend, if price fell from 200 to 100, then rebounded to 154, then fell to 110, " +
- "then rebounded to 150, and then broke down past 100, we can choose 150 or 154 as the new long BOS. If this parameter's value is more than 10%, "+
- "even if 150 passes all our checks, we will consider 155 because 54 < 50 + 10%.")
- ctfbosConsiderNextDistanceThreshold = input.float(10.0, "", minval = 0, step = 0.1, group = g10, inline="g10i1")
- ctfbosConsiderNextConsumptionEnabled = input.bool(true, " π π Only if it would be consumed no more than (%)",group = g10, inline="g10i2",
- tooltip = "When considering next, only consider it if it would not be consumed by this much % by current point. \n\n" +
- "For example, in a downtrend, current checked Long BOS's high is at 100, and next high to be considered is at 110. " +
- "If this input is set to 50%, then next BOS's low, which is its origin candle's body high (open or close, whichever higher), should be no lower than 90, "+
- "otherwise it would be consumed more than 50%, because if, for example, it would be equal to 89, then (100 - 89) / (110 - 89) = 11 / 21 > 50%.")
- ctfbosConsiderNextConsumptionThreshold = input.float(60.0, "",minval = 0, step = 0.1, group = g10, inline="g10i2")
- ctfbosConsiderNextRecursive = input.bool(true, " π π Compare against last point recursively", group = g10,
- tooltip = "When finding a pivot point within the range of a prior pivot point that passed all conditions, continue checking relative to last pivot point's price. "+
- "Therefore, percentage range above is recursively applied to each new passing pivot point, "+
- "rather than just searching within that range of the first ever passing pivot point that was discovered. \n\nConsumtion is always checked against last passing point")
- ctfbosIgnoreManipulationsEnabled = input.bool(true, "Ignore manipulations with a close far from the wick",group = g10,
- tooltip = "When a high/low is broken by a candle wick which close is at least this far away from the wick (in % relative to candle length from high to low), "+
- "ignore the price legs within this many candles from the breakout candle.\n\nThe price leg that includes breakout candle itself is always ignored, and handled "+
- "by the next setting.\n\nIf second global break in a row happens, this setting is ignored.")
- ctfbosIgnoreManipulationsThreshold = input.float(40.0, " π π Wick threshold (%)",minval = 0, step = 0.1, group = g10, inline="g10i3")
- ctfbosIgnoreManipulationsValue = input.int(1, "Candles",minval = 1, group = g10, inline="g10i3")
- ctfbosIgnoreManipulationsAmount = ctfbosIgnoreManipulationsEnabled ? ctfbosIgnoreManipulationsValue : 0
- ctfbosSameCandleLegConsumptionDelay = input.int(1, "Breakout candle price leg consumption delay, Candles", minval = 1, group = g10,
- tooltip = "If there is a price leg that ends on a breakout candle, it will only be consumed after this many candles close above it")
- ctfbosSidewaysCandleInsideThreshold = input.float(60.0, "Sideways Inclusion Candle Thershold (%)",minval = 0, maxval = 100, step = 0.1, group = g10,
- tooltip = "Candle is considered part of sideways movement if this much poercent of it or its body (determined by next input) is inside the bounds.")
- ctfbosSidewaysCandleBodyThreshold = input.float(55.0, " π π Full Body Candle Thershold (%)",minval = 0, maxval = 100, step = 0.1, group = g10,
- tooltip = "Candles are considered full body if their body is this much of their entire length.\n\n" +
- "If candle is a full body candle, its body must be inside the bounds, and if not, whole candle must be inside the bounds.")
- g5 = "BOS Change Conditions - \"OR\" - At least one must be true"
- ctfbosFiboCorrectionWickRelativeThresholdOr = input.float(0.290, "Correction Wick (Relative Fibo) π π π π π π",minval = 0, maxval=1, step = 0.001, group = g5, inline="g5i1",
- tooltip = "Price must correct this much (low to high in a downtrend, high to low in an uptrend).\n\n"+
- "This move then is compared to fibo applied to whole movement (absolute low to BOS in a downtrend, absolute high to OS in an uptrend).\n\n"+
- "For this condition to pass, move must be at least as big as the value.\n\n"+
- "EXAMPLE:\n\nPrice breaks high, reaches 150, BOS is at 50. Price moved 100. If 0.382 is the condition value, "+
- "then a correction of at least 38.2 from 150 must happen for the low to be considered good enough to become new BOS. "+
- "Therfore, price must drop to at least 111.8 = 150 - 38.2.")
- ctfusebosFiboCorrectionWickRelativeThresholdOr = input.bool(true,"ON",group = g5, inline="g5i1")
- ctfbosFiboCorrectionCloseRelativeThresholdOr = input.float(0.235, "Correction Close (Relative Fibo)π π π π π π",minval = 0, maxval=1, step = 0.001, group = g5, inline="g5i7",
- tooltip = "Price must correct this much (low to high in a downtrend, high to low in an uptrend).\n\n"+
- "This move then is compared to fibo applied to whole movement (absolute low to BOS in a downtrend, absolute high to OS in an uptrend).\n\n"+
- "For this condition to pass, move must be at least as big as the value.\n\n"+
- "EXAMPLE:\n\nPrice breaks high, highest close reaches 150, BOS is at 50. Price moved 100. If 0.382 is the condition value, "+
- "then a correction of at least 38.2 from 150 must happen for the low to be considered good enough to become new BOS. "+
- "Therfore, price must drop to at least 111.8 = 150 - 38.2.")
- ctfusebosFiboCorrectionCloseRelativeThresholdOr = input.bool(true,"ON",group = g5, inline="g5i7")
- ctfbosFiboReverseRelativeThresholdOr = input.float(0.160, "Reverse Correction (Relative Fibo) π π π π",minval = 0, maxval=1, step = 0.001, group = g5, inline="g5i3",
- tooltip = "Price must correct this much from local inverse extreme (lowest high in a downtrend, highest low in an uptrend). "+
- "This move is then compared to fibo applied to whole movement (absolute low to BOS in a downtrend, absolute high to BOS in an uptrend).\n\n"+
- "For this condition to pass, move must be at least as big as the value.\n\n"+
- "EXAMPLE:\n\nPrice breaks high, reaches 150, while highest low of this whole movement was at 100. BOS is at 50. Price moved 100. If 0.382 is the condition value, "+
- "then a correction of at least 38.2 from 100 must happen for the low to be considered good enough to become new BOS. "+
- "Therefore, price must drop to at least 61.8 = 100 - 38.2.")
- ctfusebosFiboReverseRelativeThresholdOr = input.bool(true, "ON", group = g5, inline="g5i3")
- ctfbosCandleLengthThresholdOr = input.int(20, "Sideways Candlesπ π π π π π π π π π π π π π π π π", minval = 1, group = g5, inline="g5i5",
- tooltip = "Price must spend this many candles in a sideways price range before exiting for the level to become new BOS.\n\n"+
- "EXAMPLE:\n\nPrice breaks high, reaches 150, then drops to 100, then reaches 140, then drops to 130, then breaches 150. If 30 is the condition value, "+
- "then price must have spent at least 30 candles above 130 before breaching 150 in order for 130 to become new BOS.")
- ctfusebosCandleLengthThresholdOr = input.bool(true,"ON",group = g5, inline="g5i5")
- ctfbosAtrThresholdOr = input.float(5.00, "Correction Wick (ATR) π π π π π π π π π π π π π", minval = 0, step = 0.01, group = g5, inline="g5i6",
- tooltip = "Same as correction wick (fibo), but relative to price ATR. Meaning, correction from wick must be higher than this many times ATR at the time of condition check")
- ctfusebosAtrThresholdOr = input.bool(true,"ON",group = g5, inline="g5i6")
- g6 = "BOS Change Conditions - \"AND\" - Every condition must be true"
- ctfbosFiboCorrectionWickRelativeThresholdAnd = input.float(0.382, "Correction Wick (Relative Fibo) π π π π π π",minval = 0, maxval = 1, step = 0.001, group = g6, inline="g6i1")
- ctfusebosFiboCorrectionWickRelativeThresholdAnd = input.bool(false,"ON",group = g6, inline="g6i1")
- ctfbosFiboCorrectionCloseRelativeThresholdAnd = input.float(0.236, "Correction Close (Relative Fibo)π π π π π π",minval = 0, maxval = 1, step = 0.001, group = g6, inline="g6i7")
- ctfusebosFiboCorrectionCloseRelativeThresholdAnd = input.bool(false,"ON",group = g6, inline="g6i7")
- ctfbosFiboReverseRelativeThresholdAnd = input.float(0.048, "Reverse Correction (Relative Fibo) π π π π",minval = 0, maxval=1, step = 0.001, group = g6, inline="g6i3")
- ctfusebosFiboReverseRelativeThresholdAnd = input.bool(false,"ON",group = g6, inline="g6i3")
- ctfbosCandleLengthThresholdAnd = input.int(7, "Sideways Candlesπ π π π π π π π π π π π π π π π π",minval = 1, group = g6, inline="g6i5")
- ctfusebosCandleLengthThresholdAnd = input.bool(true,"ON",group = g6, inline="g6i5")
- ctfbosAtrThresholdAnd = input.float(5.00, "Correction Wick (ATR) π π π π π π π π π π π π π", minval = 0, step = 0.01, group = g6, inline="g6i6")
- ctfusebosAtrThresholdAnd = input.bool(false,"ON",group = g6, inline="g6i6")
- g12 = "Separate Higher Timeframe Settings"
- htfSettingsEnabled = input.bool(true, "ENABLE SEPARATE SETTINGS FOR HIGHER TIMEFRAMES", group = g12)
- htfThreshold = input.timeframe(title="Higher Timeframe starts from", defval="1W", group = g12)
- htfg3 = "[HTF] HH LL Settings"
- htfSettingsg3 = input.bool(true, "ENABLE SEPARATE SETTINGS FOR THIS GROUP", group = htfg3)
- htfpivPLeft = input.int(1, "Pivot Point Period: Left", minval = 0, group = htfg3, inline="htfg3i1")
- htfpivPer = input.int(0, "Right", minval = 0, group = htfg3, inline="htfg3i1")
- htfcheckAdjacentPivotThreshold = input.float(2.5, "Pivot Point Adjacency Threshold (%)",minval = 0, step = 0.01, group = htfg3)
- htfg9 = "[HTF] BOS Break Settings"
- htfSettingsg9 = input.bool(false, "ENABLE SEPARATE SETTINGS FOR THIS GROUP", group = htfg9)
- htfHLBreakThreshold = input.float(0.25, "High/Low Break Threshold (%)",minval = 0, step = 0.1, group = htfg9)
- htfHLBreakATREnabled = input.bool(true, " π π Use ATR instead, Len.", group = htfg9, inline = "htfg9i1")
- htfHLBreakATRLength = input.int(14, "",minval = 1, group = htfg9, inline = "htfg9i1")
- htfHLBreakATRThreshold = input.float(12, "Thr. (%)", minval = 0, step = 0.1, group = htfg9, inline = "htfg9i1")
- htfnewBosConfirmConditionString = input.string(newBosConfirmOptionWithin, "BOS Break is finalized when new BOS is", group = htfg9,
- options = [newBosConfirmOptionWithin, newBosConfirmOptionPartiallyOutside, newBosConfirmOptionBeyond])
- htfnewBosConfirmConditionLevel = htfnewBosConfirmConditionString == newBosConfirmOptionPartiallyOutside ? 2 :
- htfnewBosConfirmConditionString == newBosConfirmOptionBeyond ? 1 : 0
- htfnewBosThreshold = input.float(0.5, "BOS Condition Check Threshold (%)",minval = 0, step = 0.1, group = htfg9)
- htfg7 = "[HTF] BOS Break Conditions - \"OR\" - At least one true"
- htfSettingsg7 = input.bool(true, "ENABLE SEPARATE SETTINGS FOR THIS GROUP", group = htfg7)
- htfbosBreakCandleThresholdOr = input.int(1 , "Candlesπ π π π π π π π π π π π π π π π π π π π π π π π", minval = 1, group = htfg7, inline="htfg7i1")
- htfusebosBreakCandleThresholdOr = input.bool(true,"ON",group = htfg7, inline="htfg7i1")
- htfg8 = "[HTF] BOS Break Conditions - \"AND\" - Every condition true"
- htfSettingsg8 = input.bool(false, "ENABLE SEPARATE SETTINGS FOR THIS GROUP", group = htfg8)
- htfbosBreakCandleThresholdAnd = input.int(2 , "Candlesπ π π π π π π π π π π π π π π π π π π π π π π π", minval = 1, group = htfg8, inline="htfg8i1")
- htfusebosBreakCandleThresholdAnd = input.bool(false,"ON",group = htfg8, inline="htfg8i1")
- htfg10 = "[HTF] BOS Change Settings"
- htfSettingsg10 = input.bool(false, "ENABLE SEPARATE SETTINGS FOR THIS GROUP", group = htfg10)
- htfbosConsiderNextEnabled = input.bool(true, "Consider further options within (%)", group = htfg10, inline="htfg10i1")
- htfbosConsiderNextDistanceThreshold = input.float(10.0, "",minval = 0, step = 0.1, group = htfg10, inline="htfg10i1")
- htfbosConsiderNextConsumptionEnabled = input.bool(true, " π π Only if it would be consumed no more than (%)",group = htfg10, inline="htfg10i2")
- htfbosConsiderNextConsumptionThreshold = input.float(60.0, "",minval = 0, step = 0.1, group = htfg10, inline="htfg10i2")
- htfbosConsiderNextRecursive = input.bool(true, "Compare against last point recursively", group = htfg10)
- htfbosIgnoreManipulationsEnabled = input.bool(true, "Ignore manipulations with a close far from the wick",group = htfg10)
- htfbosIgnoreManipulationsThreshold = input.float(40.0, " π π Wick threshold (%)",minval = 0, step = 0.1, group = htfg10, inline="htfg10i3")
- htfbosIgnoreManipulationsValue = input.int(2, "Candles",minval = 1, group = htfg10, inline="htfg10i3")
- htfbosIgnoreManipulationsAmount = htfbosIgnoreManipulationsEnabled ? htfbosIgnoreManipulationsValue : 0
- htfbosSameCandleLegConsumptionDelay = input.int(1, "Breakout candle price leg consumption delay, Candles", minval = 1, group = htfg10)
- htfbosSidewaysCandleInsideThreshold = input.float(60.0, "Sideways Inclusion Candle Thershold (%)",minval = 0, maxval = 100, step = 0.1, group = htfg10)
- htfbosSidewaysCandleBodyThreshold = input.float(55.0, " π π Full Body Candle Thershold (%)",minval = 0, maxval = 100, step = 0.1, group = htfg10)
- htfg5 = "[HTF] BOS Change Conditions - \"OR\" - At least one true"
- htfSettingsg5 = input.bool(true, "ENABLE SEPARATE SETTINGS FOR THIS GROUP", group = htfg5)
- htfbosFiboCorrectionWickRelativeThresholdOr = input.float(0.300, "Correction Wick (Relative Fibo) π π π π π π", minval = 0, maxval=1, step = 0.001, group = htfg5, inline="hg5i1")
- htfusebosFiboCorrectionWickRelativeThresholdOr = input.bool(true,"ON",group = htfg5, inline="hg5i1")
- htfbosFiboCorrectionCloseRelativeThresholdOr = input.float(0.235, "Correction Close (Relative Fibo)π π π π π π",minval = 0, maxval=1, step = 0.001, group = htfg5, inline="hg5i7")
- htfusebosFiboCorrectionCloseRelativeThresholdOr = input.bool(true,"ON",group = htfg5, inline="hg5i7")
- htfbosFiboReverseRelativeThresholdOr = input.float(0.160, "Reverse Correction (Relative Fibo) π π π π",minval = 0, maxval=1, step = 0.001, group = htfg5, inline="htfg5i3")
- htfusebosFiboReverseRelativeThresholdOr = input.bool(true,"ON",group = htfg5, inline="htfg5i3")
- htfbosCandleLengthThresholdOr = input.int(8, "Sideways Candlesπ π π π π π π π π π π π π π π π π",minval = 1, group = htfg5, inline="htfg5i5")
- htfusebosCandleLengthThresholdOr = input.bool(true,"ON",group = htfg5, inline="htfg5i5")
- htfbosAtrThresholdOr = input.float(5.00, "Correction Wick (ATR) π π π π π π π π π π π π π", minval = 0, step = 0.01, group = htfg5, inline="htfg5i6",
- tooltip = "Same as correction wick (fibo), but relative to price ATR")
- htfusebosAtrThresholdOr = input.bool(true,"ON",group = htfg5, inline="htfg5i6")
- htfg6 = "[HTF] BOS Change Conditions - \"AND\" - Every condition true"
- htfSettingsg6 = input.bool(true, "ENABLE SEPARATE SETTINGS FOR THIS GROUP", group = htfg6)
- htfbosFiboCorrectionWickRelativeThresholdAnd = input.float(0.382, "Correction Wick (Relative Fibo) π π π π π π",minval = 0, maxval = 1, step = 0.001, group = htfg6, inline="hg6i1")
- htfusebosFiboCorrectionWickRelativeThresholdAnd = input.bool(false,"ON",group = htfg6, inline="hg6i1")
- htfbosFiboCorrectionCloseRelativeThresholdAnd = input.float(0.236, "Correction Close (Relative Fibo)π π π π π π",minval = 0, maxval = 1, step = 0.001, group = htfg6, inline="hg6i7")
- htfusebosFiboCorrectionCloseRelativeThresholdAnd = input.bool(false,"ON",group = htfg6, inline="hg6i7")
- htfbosFiboReverseRelativeThresholdAnd = input.float(0.146, "Reverse Correction (Relative Fibo) π π π π",minval = 0, maxval=1, step = 0.001, group = htfg6, inline="htfg6i3")
- htfusebosFiboReverseRelativeThresholdAnd = input.bool(false,"ON",group = htfg6, inline="htfg6i3")
- htfbosCandleLengthThresholdAnd = input.int(4, "Sideways Candlesπ π π π π π π π π π π π π π π π π",minval = 1, group = htfg6, inline="htfg6i5")
- htfusebosCandleLengthThresholdAnd = input.bool(true,"ON",group = htfg6, inline="htfg6i5")
- htfbosAtrThresholdAnd = input.float(5.00, "Correction Wick (ATR) π π π π π π π π π π π π π", minval = 0, step = 0.01, group = htfg6, inline="htfg6i6",
- tooltip = "Same as correction wick (fibo), but relative to price ATR")
- htfusebosAtrThresholdAnd = input.bool(false,"ON",group = htfg6, inline="htfg6i6")
- g14 = "CTF BOS Style"
- colorBosLongMain = input.color(#119988, "Long Main", group = g14, inline="g14i1")
- colorBosLongAux = input.color(#ffff44, "Auxiliary", group = g14, inline="g14i1")
- colorBosShortMain = input.color(#ff4433, "Short Main", group = g14, inline="g14i1")
- colorBosShortAux = input.color(#ff9900, "Auxiliary", group = g14, inline="g14i1")
- ctfBosT1 = input.int(90, "Transparency", 0, 100, group = g14, inline ="g14i3")
- ctfBosT3 = input.int(50, "", 0, 100, group = g14, inline ="g14i3")
- ctfBosT5 = input.int(15, "", 0, 100, group = g14, inline ="g14i3")
- ctfBosT2 = (ctfBosT1 + ctfBosT3) / 2
- ctfBosT4 = (ctfBosT5 + ctfBosT3) / 2
- g14c = "CTF Classic BOS Style"
- colorCBosLongMain = input.color(#666666, "Long Main", group = g14c, inline="g14i2")
- colorCBosLongAux = input.color(#bbbbbb, "Auxiliary", group = g14c, inline="g14i2")
- colorCBosShortMain = input.color(#777777, "Short Main", group = g14c, inline="g14i2")
- colorCBosShortAux = input.color(#888888, "Auxiliary", group = g14c, inline="g14i2")
- ctfCBosT = input.int(50, "Transparency multiplier (extra for classic BOS)", 0, 100, group = g14c)
- ctfCBosT1 = 100 - (100 - ctfBosT1) * (100 - ctfCBosT) / 100
- ctfCBosT2 = 100 - (100 - ctfBosT2) * (100 - ctfCBosT) / 100
- ctfCBosT3 = 100 - (100 - ctfBosT3) * (100 - ctfCBosT) / 100
- ctfCBosT4 = 100 - (100 - ctfBosT4) * (100 - ctfCBosT) / 100
- ctfCBosT5 = 100 - (100 - ctfBosT5) * (100 - ctfCBosT) / 100
- g15 = "HTF BOS Style"
- htfcolorBosLongMain = input.color(#5566ff, "Long Main", group = g15, inline="g15i1")
- htfcolorBosLongAux = input.color(#7777cc, "Auxiliary", group = g15, inline="g15i1")
- htfcolorBosShortMain = input.color(#ff33ff, "Short Main", group = g15, inline="g15i1")
- htfcolorBosShortAux = input.color(#ee66cc, "Auxiliary", group = g15, inline="g15i1")
- htfBosT1 = input.int(95, "Transparency", 0, 100, group = g15, inline ="g15i3")
- htfBosT3 = input.int(75, "", 0, 100, group = g15, inline ="g15i3")
- htfBosT5 = input.int(55, "", 0, 100, group = g15, inline ="g15i3")
- htfBosT2 = (htfBosT1 + htfBosT3) / 2
- htfBosT4 = (htfBosT5 + htfBosT3) / 2
- g15c = "HTF Classic BOS Style"
- htfcolorCBosLongMain = input.color(#999999, "Long Main", group = g15c, inline="g15i2")
- htfcolorCBosLongAux = input.color(#cccccc, "Auxiliary", group = g15c, inline="g15i2")
- htfcolorCBosShortMain = input.color(#888888, "Short Main", group = g15c, inline="g15i2")
- htfcolorCBosShortAux = input.color(#dddddd, "Auxiliary", group = g15c, inline="g15i2")
- htfCBosT = input.int(50, "Transparency multiplier (extra for classic BOS)", 0, 100, group = g15c)
- htfCBosT1 = 100 - (100 - htfBosT1) * (100 - htfCBosT) / 100
- htfCBosT2 = 100 - (100 - htfBosT2) * (100 - htfCBosT) / 100
- htfCBosT3 = 100 - (100 - htfBosT3) * (100 - htfCBosT) / 100
- htfCBosT4 = 100 - (100 - htfBosT4) * (100 - htfCBosT) / 100
- htfCBosT5 = 100 - (100 - htfBosT5) * (100 - htfCBosT) / 100
- g16 = "Trend Output Style"
- trendBgLongMain = input.color(color.new(color.lime, 90), "Background Long Main",group = g16, inline="g16i1")
- trendBgLongAux = input.color(color.new(#aaaa66, 90), "Auxiliary",group = g16, inline="g16i1")
- trendBgShortMain = input.color(color.new(color.red, 90), "Bacground Short Main",group = g16, inline="g16i2")
- trendBgShortAux = input.color(color.new(color.orange, 90), "Auxiliary",group = g16, inline="g16i2")
- trendEdgeLongMain = input.color(color.new(color.lime, 80), "Chart Edge Long Main",group = g16, inline="g16i3")
- trendEdgeLongAux = input.color(color.new(#aaaa66, 80), "Auxiliary",group = g16, inline="g16i3")
- trendEdgeShortMain = input.color(color.new(color.red, 80), "Chart Edge Short Main",group = g16, inline="g16i4")
- trendEdgeShortAux = input.color(color.new(color.orange, 80), "Auxiliary",group = g16, inline="g16i4")
- g1 = "Strategy: Entry/Exit Conditions"
- // Risk Management
- g2 = "Strategy: Risk Management"
- riskReward = input.float(3, "Risk : Rewardβ 1 :", group = g2, inline = "RM1", minval = 0, step = 0.1,
- tooltip = "Previous high or low (long/short dependant) is used to determine TP level. "+
- "'Risk : Reward' ratio is then used to calculate SL based of previous high/low level.\n\n"+
- "In short, the higher the R:R ratio, the smaller the SL since TP target is fixed by previous high/low price data.")
- accountRiskPercent = input.float(1, "Risk per Trade %", group = g2, inline = "RM1", minval = 0, step = 0.1,
- tooltip = "Percentage of portfolio you lose if trade hits SL.\n\nYou then stand to gain\n Portfolio Risk % * Risk : Reward\nif trade hits TP.")
- // Backtest & Date Range
- gsd = 'Strategy: Backtest Settings'
- doStrategyBackTest = input.bool(false, "Strategy Backtest", group = gsd, inline = "DR3")
- limitDateStrategyTest = input.bool(true, "Limit by date", group = gsd, inline = "DR3")
- flipper = input.bool(false, "Trade in Reverse", group = gsd, inline = "DR3")
- noEntryCandleStopLoss = input.bool(false, "No Entry Candle stops", group = gsd,
- tooltip = "Wether to set stops only after the entry candle. When backtesting, gloss on the entry candle can be ignored due to broker emulator, meaning, "+
- "it won't trigger on test while it would trigger on live trade. Using this setting, this behavior can be prevented, to achieve more accurate backtest results.")
- startYear = input.int (2020, "Start Date β", group = gsd, inline = 'DR1', minval = 1900, maxval = 2100)
- startMonth = input.int (1, "", group = gsd, inline = 'DR1',
- options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
- startDate = input.int (1, "", group = gsd, inline = 'DR1',
- options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31])
- endYear = input.int (2100, "End Dateββ ", group = gsd, inline = 'DR2', minval = 1900, maxval = 2100)
- endMonth = input.int (1, "", group = gsd, inline = 'DR2',
- options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
- endDate = input.int (1, "", group = gsd, inline = 'DR2',
- options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31])
- inDateRange = not limitDateStrategyTest
- or (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)
- and time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
- inStrategyRange = doStrategyBackTest and inDateRange
- // Drawing Settings
- showTpSlBoxes = input.bool(true, "Show TP / SL Boxes", group = "Strategy: Drawings", inline = "D1",
- tooltip = "Show or hide TP and SL position boxes.\n\nNote: TradingView limits the maximum number of boxes that can be displayed to 500 "+
- "so they may not appear for all price data under test.")
- showLabels = input.bool(false, "Show Trade Exit Labels", group = "Strategy: Drawings", inline = "D2",
- tooltip = "Useful labels to identify Profit/Loss and cumulative portfolio capital after each trade closes.\n\n"+
- "Also note that TradingView limits the max number of 'boxes' that can be displayed on a chart (max 500). "+
- "This means when you lookbackSideways far enough on the chart you will not see the TP/SL boxes. However you can check this option to identify where trades exited.")
- // --------------------------------------------------------------
- // 01.03 SETTINGS | DERIVED VALEUS AND ARRAYS
- // --------------------------------------------------------------
- useHtfSettingsForCtf = htfSettingsEnabled and timeframe.in_seconds() >= timeframe.in_seconds(htfThreshold)
- useHtfSettingsForHtf = htfSettingsEnabled and timeframe.in_seconds(chosenHtf) >= timeframe.in_seconds(htfThreshold)
- pivPLeft = useHtfSettingsForCtf and htfSettingsg3 ? htfpivPLeft : ctfpivPLeft
- pivPLeftM1 = math.max(0, pivPLeft - 1)
- pivPer = useHtfSettingsForCtf and htfSettingsg3 ? htfpivPer : ctfpivPer
- pivPerP1 = pivPer + 1
- checkAdjacentPivotThreshold = useHtfSettingsForCtf and htfSettingsg3 ? htfcheckAdjacentPivotThreshold : ctfcheckAdjacentPivotThreshold
- pivPLeftHtf = useHtfSettingsForHtf and htfSettingsg3 ? htfpivPLeft : ctfpivPLeft
- pivPerHtf = useHtfSettingsForHtf and htfSettingsg3 ? htfpivPer : ctfpivPer
- checkAdjacentPivotThresholdHtf = useHtfSettingsForHtf and htfSettingsg3 ? htfcheckAdjacentPivotThreshold : ctfcheckAdjacentPivotThreshold
- ctfSidewaysMultiplier = 1
- var htfSidewaysMultiplier = timeframe.in_seconds(chosenHtf) / timeframe.in_seconds()
- ctfOffset = pivPer
- var htfOffset = int(htfSidewaysMultiplier * (0.5 + pivPerHtf))
- // TF Independent Settings
- // ---- Debug Settings
- // 00 = maxInitialCandlesToDetermineTrend
- // 01 = DBG_DisableTrimEnabled
- // 02 = DBG_ShowPriceActionRecognitionLines
- // 03 = DBG_ShowPriceActionRecognitionBoxes
- // 04 = DBG_ShowPriceActionRecognitionBounds
- // 05 = DBG_ShowPriceActionRecognitionSingleDirection
- // 06 = DBG_VerboseBosCheckDoOutput
- // 07 = DBG_VerboseBosCheckOnlySuccess
- // 08 = DBG_VerboseBosCheckDetailed
- // 09 = DBG_VerboseBosCheckCompact
- var tfIndependentSettings = array.new<float>(09 + 1)
- array.set(tfIndependentSettings, 00, maxInitialCandlesToDetermineTrend)
- array.set(tfIndependentSettings, 01, DBG_DisableTrimEnabled ? 1 : 0)
- array.set(tfIndependentSettings, 02, DBG_ShowPriceActionRecognitionLines ? 1 : 0)
- array.set(tfIndependentSettings, 03, DBG_ShowPriceActionRecognitionBoxes ? 1 : 0)
- array.set(tfIndependentSettings, 04, DBG_ShowPriceActionRecognitionBounds ? 1 : 0)
- array.set(tfIndependentSettings, 05, DBG_ShowPriceActionRecognitionSingleDirection ? 1 : 0)
- array.set(tfIndependentSettings, 06, DBG_DebugEnabled and DBG_VerboseBosCheckDoOutput ? 1 : 0)
- array.set(tfIndependentSettings, 07, DBG_VerboseBosCheckOnlySuccess ? 1 : 0)
- array.set(tfIndependentSettings, 08, DBG_VerboseBosCheckDetailed ? 1 : 0)
- array.set(tfIndependentSettings, 09, DBG_VerboseBosCheckCompact ? 1 : 0)
- // TF Sensitive settings
- // ---- BOS & HL Break Settings
- // 30 = HLBreakThreshold
- // 31 = HLBreakATREnabled
- // 32 = HLBreakATRLength
- // 33 = HLBreakATRThreshold
- // 00 = newBosConfirmConditionLevel
- // 01 = newBosThreshold
- // ---- BOS Break Conditions
- // 02 = bosBreakCandleThresholdOr
- // 03 = usebosBreakCandleThresholdOr
- // 04 = bosBreakCandleThresholdAnd
- // 05 = usebosBreakCandleThresholdAnd
- // ---- BOS Change Settings
- // 06 = bosConsiderNextEnabled
- // 07 = bosConsiderNextDistanceThreshold
- // 08 = bosConsiderNextConsumptionEnabled
- // 09 = bosConsiderNextConsumptionThreshold
- // 10 = bosConsiderNextRecursive
- // 11 = bosIgnoreManipulationsThreshold
- // 12 = bosIgnoreManipulationsAmount
- // 13 = bosSameCandleLegConsumptionDelay
- // 34 = bosSidewaysCandleInsideThreshold
- // 35 = bosSidewaysCandleBodyThreshold
- // ---- BOS Change Conditions OR
- // 14 = bosFiboCorrectionWickRelativeThresholdOr
- // 15 = usebosFiboCorrectionWickRelativeThresholdOr
- // 16 = bosFiboCorrectionCloseRelativeThresholdOr
- // 17 = usebosFiboCorrectionCloseRelativeThresholdOr
- // 18 = bosFiboReverseRelativeThresholdOr
- // 19 = usebosFiboReverseRelativeThresholdOr
- // 20 = bosCandleLengthThresholdOr
- // 21 = usebosCandleLengthThresholdOr
- // 36 = bosAtrThresholdOr
- // 37 = usebosAtrThresholdOr
- // ---- BOS Change Conditions AND
- // 22 = bosFiboCorrectionWickRelativeThresholdAnd
- // 23 = usebosFiboCorrectionWickRelativeThresholdAnd
- // 24 = bosFiboCorrectionCloseRelativeThresholdAnd
- // 25 = usebosFiboCorrectionCloseRelativeThresholdAnd
- // 26 = bosFiboReverseRelativeThresholdAnd
- // 27 = usebosFiboReverseRelativeThresholdAnd
- // 28 = bosCandleLengthThresholdAnd
- // 29 = usebosCandleLengthThresholdAnd
- // 38 = bosAtrThresholdAnd
- // 39 = usebosAtrThresholdAnd
- // ---- Miscellaneous
- // 50 = ctfOffset / htfOffset
- // 51 = ctfSidewaysMultiplier / htfSidewaysMultiplier
- // ---- DEBUG
- // 60 = DBG_VerboseBosCheckOutputCtf / DBG_VerboseBosCheckOutputHtf
- // 61 = DBG_ShowPriceActionRecognitionCtf / DBG_ShowPriceActionRecognitionHtf
- var ctfSensitiveSettings = array.new<float>(61 + 1)
- var htfSensitiveSettings = array.new<float>(61 + 1)
- // CTF SETTINGS
- // Π‘TF ---- BOS & HL Break Settings
- array.set(ctfSensitiveSettings, 30, useHtfSettingsForCtf and htfSettingsg9 ? htfHLBreakThreshold : ctfHLBreakThreshold)
- array.set(ctfSensitiveSettings, 31, (useHtfSettingsForCtf and htfSettingsg9 ? htfHLBreakATREnabled : ctfHLBreakATREnabled) ? 1 : 0)
- array.set(ctfSensitiveSettings, 32, useHtfSettingsForCtf and htfSettingsg9 ? htfHLBreakATRLength : ctfHLBreakATRLength)
- array.set(ctfSensitiveSettings, 33, useHtfSettingsForCtf and htfSettingsg9 ? htfHLBreakATRThreshold : ctfHLBreakATRThreshold)
- array.set(ctfSensitiveSettings, 00, useHtfSettingsForCtf and htfSettingsg9 ? htfnewBosConfirmConditionLevel : ctfnewBosConfirmConditionLevel)
- array.set(ctfSensitiveSettings, 01, useHtfSettingsForCtf and htfSettingsg9 ? htfnewBosThreshold : ctfnewBosThreshold)
- // CTF ---- BOS Break Conditions
- array.set(ctfSensitiveSettings, 02, useHtfSettingsForCtf and htfSettingsg7 ? htfbosBreakCandleThresholdOr : ctfbosBreakCandleThresholdOr)
- array.set(ctfSensitiveSettings, 03, (useHtfSettingsForCtf and htfSettingsg7 ? htfusebosBreakCandleThresholdOr : ctfusebosBreakCandleThresholdOr) ? 1 : 0)
- array.set(ctfSensitiveSettings, 04, useHtfSettingsForCtf and htfSettingsg8 ? htfbosBreakCandleThresholdAnd : ctfbosBreakCandleThresholdAnd)
- array.set(ctfSensitiveSettings, 05, (useHtfSettingsForCtf and htfSettingsg8 ? htfusebosBreakCandleThresholdAnd : ctfusebosBreakCandleThresholdAnd) ? 1 : 0)
- // CTF ---- BOS Change Settings
- array.set(ctfSensitiveSettings, 06, (useHtfSettingsForCtf and htfSettingsg10 ? htfbosConsiderNextEnabled : ctfbosConsiderNextEnabled) ? 1 : 0)
- array.set(ctfSensitiveSettings, 07, useHtfSettingsForCtf and htfSettingsg10 ? htfbosConsiderNextDistanceThreshold : ctfbosConsiderNextDistanceThreshold)
- array.set(ctfSensitiveSettings, 08, (useHtfSettingsForCtf and htfSettingsg10 ? htfbosConsiderNextConsumptionEnabled : ctfbosConsiderNextConsumptionEnabled) ? 1 : 0)
- array.set(ctfSensitiveSettings, 09, useHtfSettingsForCtf and htfSettingsg10 ? htfbosConsiderNextConsumptionThreshold : ctfbosConsiderNextConsumptionThreshold)
- array.set(ctfSensitiveSettings, 10, (useHtfSettingsForCtf and htfSettingsg10 ? htfbosConsiderNextRecursive : ctfbosConsiderNextRecursive) ? 1 : 0)
- array.set(ctfSensitiveSettings, 11, useHtfSettingsForCtf and htfSettingsg10 ? htfbosIgnoreManipulationsThreshold : ctfbosIgnoreManipulationsThreshold)
- array.set(ctfSensitiveSettings, 12, useHtfSettingsForCtf and htfSettingsg10 ? htfbosIgnoreManipulationsAmount : ctfbosIgnoreManipulationsAmount)
- array.set(ctfSensitiveSettings, 13, useHtfSettingsForCtf and htfSettingsg10 ? htfbosSameCandleLegConsumptionDelay : ctfbosSameCandleLegConsumptionDelay)
- array.set(ctfSensitiveSettings, 34, useHtfSettingsForCtf and htfSettingsg10 ? htfbosSidewaysCandleInsideThreshold : ctfbosSidewaysCandleInsideThreshold)
- array.set(ctfSensitiveSettings, 35, useHtfSettingsForCtf and htfSettingsg10 ? htfbosSidewaysCandleBodyThreshold : ctfbosSidewaysCandleBodyThreshold)
- // CTF ---- BOS Change Conditions OR
- array.set(ctfSensitiveSettings, 14, useHtfSettingsForCtf and htfSettingsg5 ? htfbosFiboCorrectionWickRelativeThresholdOr : ctfbosFiboCorrectionWickRelativeThresholdOr)
- array.set(ctfSensitiveSettings, 15, (useHtfSettingsForCtf and htfSettingsg5 ? htfusebosFiboCorrectionWickRelativeThresholdOr : ctfusebosFiboCorrectionWickRelativeThresholdOr) ? 1 : 0)
- array.set(ctfSensitiveSettings, 16, useHtfSettingsForCtf and htfSettingsg5 ? htfbosFiboCorrectionCloseRelativeThresholdOr : ctfbosFiboCorrectionCloseRelativeThresholdOr)
- array.set(ctfSensitiveSettings, 17, (useHtfSettingsForCtf and htfSettingsg5 ? htfusebosFiboCorrectionCloseRelativeThresholdOr : ctfusebosFiboCorrectionCloseRelativeThresholdOr) ? 1 : 0)
- array.set(ctfSensitiveSettings, 18, useHtfSettingsForCtf and htfSettingsg5 ? htfbosFiboReverseRelativeThresholdOr : ctfbosFiboReverseRelativeThresholdOr)
- array.set(ctfSensitiveSettings, 19, (useHtfSettingsForCtf and htfSettingsg5 ? htfusebosFiboReverseRelativeThresholdOr : ctfusebosFiboReverseRelativeThresholdOr) ? 1 : 0)
- array.set(ctfSensitiveSettings, 20, useHtfSettingsForCtf and htfSettingsg5 ? htfbosCandleLengthThresholdOr : ctfbosCandleLengthThresholdOr)
- array.set(ctfSensitiveSettings, 21, (useHtfSettingsForCtf and htfSettingsg5 ? htfusebosCandleLengthThresholdOr : ctfusebosCandleLengthThresholdOr) ? 1 : 0)
- array.set(ctfSensitiveSettings, 36, useHtfSettingsForCtf and htfSettingsg5 ? htfbosAtrThresholdOr : ctfbosAtrThresholdOr)
- array.set(ctfSensitiveSettings, 37, (useHtfSettingsForCtf and htfSettingsg5 ? htfusebosAtrThresholdOr : ctfusebosAtrThresholdOr) ? 1 : 0)
- // CTF ---- BOS Change Conditions AND
- array.set(ctfSensitiveSettings, 22, useHtfSettingsForCtf and htfSettingsg6 ? htfbosFiboCorrectionWickRelativeThresholdAnd : ctfbosFiboCorrectionWickRelativeThresholdAnd)
- array.set(ctfSensitiveSettings, 23, (useHtfSettingsForCtf and htfSettingsg6 ? htfusebosFiboCorrectionWickRelativeThresholdAnd : ctfusebosFiboCorrectionWickRelativeThresholdAnd) ? 1 : 0)
- array.set(ctfSensitiveSettings, 24, useHtfSettingsForCtf and htfSettingsg6 ? htfbosFiboCorrectionCloseRelativeThresholdAnd : ctfbosFiboCorrectionCloseRelativeThresholdAnd)
- array.set(ctfSensitiveSettings, 25, (useHtfSettingsForCtf and htfSettingsg6 ? htfusebosFiboCorrectionCloseRelativeThresholdAnd : ctfusebosFiboCorrectionCloseRelativeThresholdAnd) ? 1 : 0)
- array.set(ctfSensitiveSettings, 26, useHtfSettingsForCtf and htfSettingsg6 ? htfbosFiboReverseRelativeThresholdAnd : ctfbosFiboReverseRelativeThresholdAnd)
- array.set(ctfSensitiveSettings, 27, (useHtfSettingsForCtf and htfSettingsg6 ? htfusebosFiboReverseRelativeThresholdAnd : ctfusebosFiboReverseRelativeThresholdAnd) ? 1 : 0)
- array.set(ctfSensitiveSettings, 28, useHtfSettingsForCtf and htfSettingsg6 ? htfbosCandleLengthThresholdAnd : ctfbosCandleLengthThresholdAnd)
- array.set(ctfSensitiveSettings, 29, (useHtfSettingsForCtf and htfSettingsg6 ? htfusebosCandleLengthThresholdAnd : ctfusebosCandleLengthThresholdAnd) ? 1 : 0)
- array.set(ctfSensitiveSettings, 38, useHtfSettingsForCtf and htfSettingsg5 ? htfbosAtrThresholdAnd : ctfbosAtrThresholdAnd)
- array.set(ctfSensitiveSettings, 39, (useHtfSettingsForCtf and htfSettingsg5 ? htfusebosAtrThresholdAnd : ctfusebosAtrThresholdAnd) ? 1 : 0)
- // CTF ---- Miscellaneous
- array.set(ctfSensitiveSettings, 50, ctfOffset)
- array.set(ctfSensitiveSettings, 51, ctfSidewaysMultiplier)
- // CTF ---- DEBUG
- array.set(ctfSensitiveSettings, 60, (DBG_VerboseBosCheckOutputCtf) ? 1 : 0)
- array.set(ctfSensitiveSettings, 61, (DBG_DebugEnabled and DBG_ShowPriceActionRecognitionEnabled and DBG_ShowPriceActionRecognitionCtf) ? 1 : 0)
- // HTF SETTINGS
- // HTF ---- BOS & HL Break Settings
- array.set(htfSensitiveSettings, 30, useHtfSettingsForHtf and htfSettingsg9 ? htfHLBreakThreshold : ctfHLBreakThreshold)
- array.set(htfSensitiveSettings, 31, (useHtfSettingsForHtf and htfSettingsg9 ? htfHLBreakATREnabled : ctfHLBreakATREnabled) ? 1 : 0)
- array.set(htfSensitiveSettings, 32, useHtfSettingsForHtf and htfSettingsg9 ? htfHLBreakATRLength : ctfHLBreakATRLength)
- array.set(htfSensitiveSettings, 33, useHtfSettingsForHtf and htfSettingsg9 ? htfHLBreakATRThreshold : ctfHLBreakATRThreshold)
- array.set(htfSensitiveSettings, 00, useHtfSettingsForHtf and htfSettingsg9 ? htfnewBosConfirmConditionLevel : ctfnewBosConfirmConditionLevel)
- array.set(htfSensitiveSettings, 01, useHtfSettingsForHtf and htfSettingsg9 ? htfnewBosThreshold : ctfnewBosThreshold)
- // HTF ---- BOS Break Conditions
- array.set(htfSensitiveSettings, 02, useHtfSettingsForHtf and htfSettingsg7 ? htfbosBreakCandleThresholdOr : ctfbosBreakCandleThresholdOr)
- array.set(htfSensitiveSettings, 03, (useHtfSettingsForHtf and htfSettingsg7 ? htfusebosBreakCandleThresholdOr : ctfusebosBreakCandleThresholdOr) ? 1 : 0)
- array.set(htfSensitiveSettings, 04, useHtfSettingsForHtf and htfSettingsg8 ? htfbosBreakCandleThresholdAnd : ctfbosBreakCandleThresholdAnd)
- array.set(htfSensitiveSettings, 05, (useHtfSettingsForHtf and htfSettingsg8 ? htfusebosBreakCandleThresholdAnd : ctfusebosBreakCandleThresholdAnd) ? 1 : 0)
- // HTF ---- BOS Change Settings
- array.set(htfSensitiveSettings, 06, (useHtfSettingsForHtf and htfSettingsg10 ? htfbosConsiderNextEnabled : ctfbosConsiderNextEnabled) ? 1 : 0)
- array.set(htfSensitiveSettings, 07, useHtfSettingsForHtf and htfSettingsg10 ? htfbosConsiderNextDistanceThreshold : ctfbosConsiderNextDistanceThreshold)
- array.set(htfSensitiveSettings, 08, (useHtfSettingsForHtf and htfSettingsg10 ? htfbosConsiderNextConsumptionEnabled : ctfbosConsiderNextConsumptionEnabled) ? 1 : 0)
- array.set(htfSensitiveSettings, 09, useHtfSettingsForHtf and htfSettingsg10 ? htfbosConsiderNextConsumptionThreshold : ctfbosConsiderNextConsumptionThreshold)
- array.set(htfSensitiveSettings, 10, (useHtfSettingsForHtf and htfSettingsg10 ? htfbosConsiderNextRecursive : ctfbosConsiderNextRecursive) ? 1 : 0)
- array.set(htfSensitiveSettings, 11, useHtfSettingsForHtf and htfSettingsg10 ? htfbosIgnoreManipulationsThreshold : ctfbosIgnoreManipulationsThreshold)
- array.set(htfSensitiveSettings, 12, useHtfSettingsForHtf and htfSettingsg10 ? htfbosIgnoreManipulationsAmount : ctfbosIgnoreManipulationsAmount)
- array.set(htfSensitiveSettings, 13, useHtfSettingsForHtf and htfSettingsg10 ? htfbosSameCandleLegConsumptionDelay : ctfbosSameCandleLegConsumptionDelay)
- array.set(htfSensitiveSettings, 34, useHtfSettingsForHtf and htfSettingsg10 ? htfbosSidewaysCandleInsideThreshold : ctfbosSidewaysCandleInsideThreshold)
- array.set(htfSensitiveSettings, 35, useHtfSettingsForHtf and htfSettingsg10 ? htfbosSidewaysCandleBodyThreshold : ctfbosSidewaysCandleBodyThreshold)
- // HTF ---- BOS Change Conditions OR
- array.set(htfSensitiveSettings, 14, useHtfSettingsForHtf and htfSettingsg5 ? htfbosFiboCorrectionWickRelativeThresholdOr : ctfbosFiboCorrectionWickRelativeThresholdOr)
- array.set(htfSensitiveSettings, 15, (useHtfSettingsForHtf and htfSettingsg5 ? htfusebosFiboCorrectionWickRelativeThresholdOr : ctfusebosFiboCorrectionWickRelativeThresholdOr) ? 1 : 0)
- array.set(htfSensitiveSettings, 16, useHtfSettingsForHtf and htfSettingsg5 ? htfbosFiboCorrectionCloseRelativeThresholdOr : ctfbosFiboCorrectionCloseRelativeThresholdOr)
- array.set(htfSensitiveSettings, 17, (useHtfSettingsForHtf and htfSettingsg5 ? htfusebosFiboCorrectionCloseRelativeThresholdOr : ctfusebosFiboCorrectionCloseRelativeThresholdOr) ? 1 : 0)
- array.set(htfSensitiveSettings, 18, useHtfSettingsForHtf and htfSettingsg5 ? htfbosFiboReverseRelativeThresholdOr : ctfbosFiboReverseRelativeThresholdOr)
- array.set(htfSensitiveSettings, 19, (useHtfSettingsForHtf and htfSettingsg5 ? htfusebosFiboReverseRelativeThresholdOr : ctfusebosFiboReverseRelativeThresholdOr) ? 1 : 0)
- array.set(htfSensitiveSettings, 20, useHtfSettingsForHtf and htfSettingsg5 ? htfbosCandleLengthThresholdOr : ctfbosCandleLengthThresholdOr)
- array.set(htfSensitiveSettings, 21, (useHtfSettingsForHtf and htfSettingsg5 ? htfusebosCandleLengthThresholdOr : ctfusebosCandleLengthThresholdOr) ? 1 : 0)
- // HTF ---- BOS Change Conditions AND
- array.set(htfSensitiveSettings, 22, useHtfSettingsForHtf and htfSettingsg6 ? htfbosFiboCorrectionWickRelativeThresholdAnd : ctfbosFiboCorrectionWickRelativeThresholdAnd)
- array.set(htfSensitiveSettings, 23, (useHtfSettingsForHtf and htfSettingsg6 ? htfusebosFiboCorrectionWickRelativeThresholdAnd : ctfusebosFiboCorrectionWickRelativeThresholdAnd) ? 1 : 0)
- array.set(htfSensitiveSettings, 24, useHtfSettingsForHtf and htfSettingsg6 ? htfbosFiboCorrectionCloseRelativeThresholdAnd : ctfbosFiboCorrectionCloseRelativeThresholdAnd)
- array.set(htfSensitiveSettings, 25, (useHtfSettingsForHtf and htfSettingsg6 ? htfusebosFiboCorrectionCloseRelativeThresholdAnd : ctfusebosFiboCorrectionCloseRelativeThresholdAnd) ? 1 : 0)
- array.set(htfSensitiveSettings, 26, useHtfSettingsForHtf and htfSettingsg6 ? htfbosFiboReverseRelativeThresholdAnd : ctfbosFiboReverseRelativeThresholdAnd)
- array.set(htfSensitiveSettings, 27, (useHtfSettingsForHtf and htfSettingsg6 ? htfusebosFiboReverseRelativeThresholdAnd : ctfusebosFiboReverseRelativeThresholdAnd) ? 1 : 0)
- array.set(htfSensitiveSettings, 28, useHtfSettingsForHtf and htfSettingsg6 ? htfbosCandleLengthThresholdAnd : ctfbosCandleLengthThresholdAnd)
- array.set(htfSensitiveSettings, 29, (useHtfSettingsForHtf and htfSettingsg6 ? htfusebosCandleLengthThresholdAnd : ctfusebosCandleLengthThresholdAnd) ? 1 : 0)
- // HTF ---- Miscellaneous
- array.set(htfSensitiveSettings, 50, htfOffset)
- array.set(htfSensitiveSettings, 51, htfSidewaysMultiplier)
- // HTF ---- DEBUG
- array.set(htfSensitiveSettings, 60, (DBG_VerboseBosCheckOutputHtf) ? 1 : 0)
- array.set(htfSensitiveSettings, 61, (DBG_DebugEnabled and DBG_ShowPriceActionRecognitionEnabled and DBG_ShowPriceActionRecognitionHtf) ? 1 : 0)
- // --------------------------------------------------------------
- // 02 PRICE DATA ACQUISITION
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 02.01 PRICE DATA ACQUISITION | CTF
- // --------------------------------------------------------------
- // CTF Arrays with price data
- var carHigh = array.new<float>(1,na)
- var carLow = array.new<float>(1,na)
- var carOpen = array.new<float>(1,na)
- var carClose = array.new<float>(1,na)
- var carMaxOC = array.new<float>(1,na)
- var carMinOC = array.new<float>(1,na)
- // Redundant for CTF but need it for algo being TF agnostic
- var cBarIndex = array.new<int>(0,0)
- // Pivot point value, if present at this bar (offset by pivPer)
- var carPivotH = array.new<float>(1,na)
- var carPivotL = array.new<float>(1,na)
- // CTF Values
- cHigh = high[pivPer]
- cLow = low[pivPer]
- cOpen = open[pivPer]
- cClose = close[pivPer]
- cMaxOC = math.max(cOpen, cClose)
- cMinOC = math.min(cOpen, cClose)
- var float cPivotH = na
- var float cPivotL = na
- // Get pivot points, Not as simple as it may seem!
- cPivotH := ta.pivothigh(pivPLeft, pivPer)
- cPivotL := ta.pivotlow(pivPLeft, pivPer)
- //Also look for adjacent spots since sometimes pivot point might be a bit off, but still valid
- adjPivotH = ta.pivothigh(pivPLeftM1, pivPerP1)
- adjPivotL = ta.pivotlow(pivPLeftM1, pivPerP1)
- if pivPLeft > 1 and checkAdjacentPivotThreshold > 0
- threshold = (cOpen + cHigh + cLow + cClose) / 4 * checkAdjacentPivotThreshold / 100
- // Conditions for adjacent pivot described above in the input section
- if not cPivotH[1] and not cPivotH and adjPivotH
- and array.get(carMaxOC, 0) - cMaxOC < threshold
- and adjPivotH - cHigh < threshold
- cPivotH := adjPivotH
- // Doctoring the data to take correct price value into account if this becomes BOS
- cHigh := cPivotH
- if not cPivotL[1] and not cPivotL and adjPivotL
- and cMinOC - array.get(carMinOC, 0) < threshold
- and cLow - adjPivotL < threshold
- cPivotL := adjPivotL
- cLow := cPivotL
- // Populate arrays with data
- array.unshift(carHigh, cHigh)
- array.unshift(carLow, cLow)
- array.unshift(carOpen, cOpen)
- array.unshift(carClose, cClose)
- array.unshift(carMaxOC, cMaxOC)
- array.unshift(carMinOC, cMinOC)
- array.push(cBarIndex, bar_index)
- array.unshift(carPivotH, cPivotH)
- array.unshift(carPivotL, cPivotL)
- // --------------------------------------------------------------
- // 02.02 PRICE DATA ACQUISITION | HTF
- // --------------------------------------------------------------
- // HTF Arrays with price data
- var harHigh = array.new<float>(1,na)
- var harLow = array.new<float>(1,na)
- var harOpen = array.new<float>(1,na)
- var harClose = array.new<float>(1,na)
- var harMaxOC = array.new<float>(1,na)
- var harMinOC = array.new<float>(1,na)
- // Converts HTF bars into CTF bars
- var harBarIndex = array.new<int>(0,0)
- // HTF Pivot data
- var harPivotH = array.new<float>(1,na)
- var harPivotL = array.new<float>(1,na)
- // ta.pivot fails on htf data when there's uncommon situation
- // like russian stocks hiatus, 24 Feb 2022 CTF 4H HTF 1D
- // so we have to make our own
- tavapivothigh(left, right, aHigh, hHigh, fHigh, offset = false) =>
- lfrom = offset ? 1 : 0
- lto = left == 0 ? na : left - 1
- rfrom = 0
- rto = right == 0 ? na : right - 1
- if array.size(aHigh) < left or offset and left <= 1
- na
- else
- pivot = offset ? array.get(aHigh, 0) : hHigh
- if offset and right > 0
- if hHigh >= pivot
- pivot := na
- lto := na
- rto := na
- for i = lfrom to lto
- if array.get(aHigh, i) >= pivot
- pivot := na
- rto := na
- break
- for i = rfrom to rto
- if array.get(fHigh, i) >= pivot
- pivot := na
- break
- pivot
- tavapivotlow(left, right, aLow, hLow, fLow, offset = false) =>
- lfrom = offset ? 1 : 0
- lto = left == 0 ? na : left - 1
- rfrom = 0
- rto = right == 0 ? na : right - 1
- if array.size(aLow) < left or offset and left <= 1
- na
- else
- pivot = offset ? array.get(aLow, 0) : hLow
- if offset and right > 0
- if hLow <= pivot
- pivot := na
- lto := na
- rto := na
- for i = lfrom to lto
- if array.get(aLow, i) <= pivot
- pivot := na
- rto := na
- break
- for i = rfrom to rto
- if array.get(fLow, i) <= pivot
- pivot := na
- break
- pivot
- // Must put this in a function because it's not allowed to be called in an "if" conditional
- getHTFSecurity() =>
- request.security(syminfo.tickerid,
- // DUPLICATE CODE
- // BECAUSE OF PINESCRIPT SHENANIGANS
- not calculateHtfTrendEnabled ? "1M" : chooseHtfSkip ?
- (timeframe.in_seconds() <= timeframe.in_seconds("1") ? "5" :
- timeframe.in_seconds() <= timeframe.in_seconds("5") ? "30" :
- timeframe.in_seconds() <= timeframe.in_seconds("30") ? "240" :
- timeframe.in_seconds() <= timeframe.in_seconds("240") ? "1D" :
- timeframe.in_seconds() <= timeframe.in_seconds("1D") ? "1W" :
- timeframe.in_seconds() <= timeframe.in_seconds("1W") ? "1M" : "1M")
- :
- (timeframe.in_seconds() < timeframe.in_seconds("1") ? "1" :
- timeframe.in_seconds() < timeframe.in_seconds("5") ? "5" :
- timeframe.in_seconds() < timeframe.in_seconds("15") ? "15" :
- timeframe.in_seconds() < timeframe.in_seconds("30") ? "30" :
- timeframe.in_seconds() < timeframe.in_seconds("60") ? "60" :
- timeframe.in_seconds() < timeframe.in_seconds("240") ? "240" :
- timeframe.in_seconds() < timeframe.in_seconds("1D") ? "1D" :
- timeframe.in_seconds() < timeframe.in_seconds("1W") ? "1W" :
- timeframe.in_seconds() < timeframe.in_seconds("1M") ? "1M" : "1M")
- // DUPLICATE CODE END
- , [open, high, low, close], gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_on)
- newHtfDataThisTick = false
- var htfBarIndex = -1
- if calculateHtfTrend
- [_o,_h,_l,_c] = getHTFSecurity()
- if _o
- newHtfDataThisTick := true
- htfBarIndex:= htfBarIndex + 1
- // Manually shift values back in time
- // Otherwise it fails in uncommon situations
- // like on russian stocks hiatus in 24 Feb 2022 CTF 4H HTF 1D
- // Because [] values on htf skips candles
- var fOpen = array.new<float>(1 + pivPerHtf, _o)
- var fHigh = array.new<float>(1 + pivPerHtf, _h)
- var fLow = array.new<float>(1 + pivPerHtf, _l)
- var fClose = array.new<float>(1 + pivPerHtf, _c)
- array.push(fOpen, _o)
- array.push(fHigh, _h)
- array.push(fLow, _l)
- array.push(fClose, _c)
- hOpen = array.shift(fOpen)
- hHigh = array.shift(fHigh)
- hLow = array.shift(fLow)
- hClose = array.shift(fClose)
- hMaxOC = math.max(hOpen, hClose)
- hMinOC = math.min(hOpen, hClose)
- // At this point we got an effect of value[1 + pivPerHtf] without data loss
- // ta.pivot also fails in such cases so we have to calculate those manually
- hPivotH = tavapivothigh(pivPLeftHtf, pivPerHtf, harHigh, hHigh, fHigh)
- hPivotL = tavapivotlow(pivPLeftHtf, pivPerHtf, harLow, hLow, fLow)
- hAdjPivotH = tavapivothigh(pivPLeftHtf, pivPerHtf, harHigh, hHigh, fHigh, true)
- hAdjPivotL = tavapivotlow(pivPLeftHtf, pivPerHtf, harLow, hLow, fLow, true)
- if pivPLeftHtf > 1 and checkAdjacentPivotThresholdHtf > 0
- threshold = (hOpen + hHigh + hLow + hClose) / 4 * checkAdjacentPivotThresholdHtf / 100
- if not hPivotH and hAdjPivotH
- and array.get(harMaxOC, 0) - hMaxOC < threshold
- and hAdjPivotH - hHigh < threshold
- hPivotH := hAdjPivotH
- hHigh := hPivotH
- if not hPivotL and hAdjPivotL
- and hMinOC - array.get(harMinOC, 0) < threshold
- and hLow - hAdjPivotL < threshold
- hPivotL := hAdjPivotL
- hLow := hPivotL
- // Now we can populate arrays with data just like CTF
- array.unshift(harOpen, hOpen)
- array.unshift(harHigh, hHigh)
- array.unshift(harLow, hLow)
- array.unshift(harClose, hClose)
- array.unshift(harMaxOC, hMaxOC)
- array.unshift(harMinOC, hMinOC)
- array.push(harBarIndex, bar_index)
- array.unshift(harPivotH, hPivotH)
- array.unshift(harPivotL, hPivotL)
- // --------------------------------------------------------------
- // 03 GLOBAL VARIABLES
- // --------------------------------------------------------------
- // Price Leg Arrays
- // ---- Float
- // 00 = LocalH
- // 01 = LocalL
- // 02 = Close
- // 03 = Reverse
- // ---- Int
- // 00 = LocalHB
- // 01 = LocalLB
- // 02 = SidewaysL
- // 03 = SidewaysR
- // 04 = SidewaysF
- plFlt = 4
- plInt = 5
- // CTF Arrays
- var carLFlt = array.new<float>(0)
- var carLInt = array.new<int>(0)
- var carSFlt = array.new<float>(0)
- var carSInt = array.new<int>(0)
- // HTF Arrays
- var harLFlt = array.new<float>(0)
- var harLInt = array.new<int>(0)
- var harSFlt = array.new<float>(0)
- var harSInt = array.new<int>(0)
- // Algorithm state
- // Trend, BOS testing/breaching, Executes
- // Algorithm Values / Bars
- // Prior & Global High/Low | Short & Long BOS Levels | Next Close & Reverse Values
- // CTF State
- var carStateInt = array.new<int>(2, 0)
- var carStateBool = array.new<bool>(2, false)
- var carValuesFlt = array.new<float>(20, na)
- var carValuesInt = array.new<int>(8, na)
- // HTF State
- var harStateInt = array.new<int>(2, 0)
- var harStateBool = array.new<bool>(2, false)
- var harValuesFlt = array.new<float>(20, na)
- var harValuesInt = array.new<int>(8, na)
- // --------------------------------------------------------------
- // 04 FUNCTIONS
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 04.01 FUNCTIONS: LIBRARY
- // --------------------------------------------------------------
- debugTextX(x, title, bool below = false, color bgcolor = #00065586) =>
- if SHOW_DEBUG_TEXT
- label.new(x, 0, str.tostring(title), yloc = below ? yloc.belowbar : yloc.abovebar, color = bgcolor, textcolor = color.white)
- debugText(title, bool below = false, color bgcolor = #00065586) =>
- if SHOW_DEBUG_TEXT
- label.new(bar_index, 0, str.tostring(title), yloc = below ? yloc.belowbar : yloc.abovebar, color = bgcolor, textcolor = color.white)
- debugLine(x1, y1, x2, y2, color, width) =>
- if SHOW_DEBUG_LINES
- line.new(x1, y1, x2, y2, color = color, width = width)
- debugBox(x1, y1, x2, y2, border_color, border_width, bg_color) =>
- if SHOW_DEBUG_BOXES
- box.new(x1, y1, x2, y2, border_color, border_width, bgcolor = bg_color)
- // --------------------------------------------------------------
- // 04.02 FUNCTIONS: VARIABLES
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 04.03 FUNCTIONS: OUTPUT
- // --------------------------------------------------------------
- printTpSlDrawing(left, right, entryPrice, slPrice, tpPrice, tpHit, slHit) =>
- if showTpSlBoxes
- colorProfitBright = color.new(color.green, 20)
- colorProfitDim = color.new(color.green, 80)
- colorNeutralBright = color.new(color.gray, 20)
- colorNeutralDim = color.new(color.gray, 80)
- colorLossBright = color.new(color.red, 20)
- colorLossDim = color.new(color.red, 80)
- offsetRight = right == left ? right + 1 : right
- line.new(x1 = left, y1 = tpPrice, x2 = offsetRight, y2 = tpPrice, color = colorProfitBright, width = 2)
- box.new(left, tpPrice, offsetRight, entryPrice, na, bgcolor = tpHit ? colorProfitDim : colorNeutralDim)
- line.new(x1 = left, y1 = entryPrice, x2 = offsetRight, y2 = entryPrice, color = colorNeutralBright, width = 2)
- box.new(left, entryPrice, offsetRight, slPrice, na, bgcolor = slHit ? colorLossDim : colorNeutralDim)
- line.new(x1 = left, y1 = slPrice, x2 = offsetRight, y2 = slPrice, color = colorLossBright, width = 2)
- printTpSlDrawingActive(left,right,entryPrice,slPrice,tpPrice) =>
- printTpSlDrawing(left,right,entryPrice,slPrice,tpPrice,false,false)
- printLabel(globalTrendDirection, bar, title, above, strong) =>
- longColor = globalTrendDirection == 1 ? (strong?color.green:color.yellow) : (strong ? color.red : color.orange)
- shortColor = globalTrendDirection == -1 ? (strong?color.red:color.orange) : (strong ? color.green : color.yellow)
- label.new(bar, 0, title, yloc = above ? yloc.abovebar:yloc.belowbar, style = above ? label.style_label_down : label.style_label_up, color = above ? longColor : shortColor)
- printPriceLeg(tfSensitiveSettings, tfIndependentSettings, aBarIndex, x1, y1, x2, y2, y3, y4, sl, sr, long, highlighted, faded = false) =>
- offset = int(array.get(tfSensitiveSettings, 50))
- swMult = int(array.get(tfSensitiveSettings, 51))
- mainColor = color.new(long ? (faded ? color.green : color.lime) : (faded ? color.purple : color.fuchsia), highlighted ? 0 : 30)
- boundColor = color.new(long ? (faded ? color.green : color.lime) : (faded ? color.purple : color.fuchsia), highlighted ? 50 : 70)
- int newX1 = array.get(aBarIndex, x1) - offset
- int newX2 = array.get(aBarIndex, x2) - offset
- color bgColor = na
- if array.get(tfIndependentSettings, 02)
- debugLine(newX1, y1, newX2, y2, mainColor, highlighted ? 3 : faded ? 1 : 2)
- if array.get(tfIndependentSettings, 03)
- debugBox(math.max(newX1, newX2) - sl * swMult, y3, math.max(newX1,newX2) + sr * swMult - 1 , y4, mainColor, 1, bgColor)
- if array.get(tfIndependentSettings, 04)
- debugBox(math.max(newX1, newX2) - sl * swMult, y1, math.max(newX1,newX2) + sr * swMult - 1 , y2, boundColor, 1, bgColor)
- // --------------------------------------------------------------
- // 04.04 FUNCTIONS: ARRAYS
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 04.04.01 FUNCTIONS: ARRAYS | Price Leg Data
- // --------------------------------------------------------------
- arRemove(array<float> aFlt, array<int> aInt, int id) =>
- array.remove(aFlt, id * plFlt)
- array.remove(aInt, id * plInt)
- array.remove(aFlt, id * plFlt)
- array.remove(aInt, id * plInt)
- array.remove(aFlt, id * plFlt)
- array.remove(aFlt, id * plFlt)
- array.remove(aInt, id * plInt)
- array.remove(aInt, id * plInt)
- array.remove(aInt, id * plInt)
- arPop(array<float> aFlt, array<int> aInt) =>
- // Popping in forward order because we pushed in reverse order
- [array.pop(aFlt),
- array.pop(aInt),
- array.pop(aFlt),
- array.pop(aInt),
- array.pop(aFlt),
- array.pop(aFlt),
- array.pop(aInt),
- array.pop(aInt),
- array.pop(aInt)]
- arPush(array<float> aFlt, array<int> aInt, float a_h = na, int a_hb = na, float a_l = na, int a_lb = na, float a_c = na, float a_r = na, int a_sl = na, int a_sr = na, int a_sf = na) =>
- // Pushing in reverse order, so we could pop in normal order
- array.push(aInt, a_sf)
- array.push(aInt, a_sr)
- array.push(aInt, a_sl)
- array.push(aFlt, a_r)
- array.push(aFlt, a_c)
- array.push(aInt, a_lb)
- array.push(aFlt, a_l)
- array.push(aInt, a_hb)
- array.push(aFlt, a_h)
- arClear(array<float> aFlt, array<int> aInt, long, tfSensitiveSettings, tfIndependentSettings, aBarIndex, debugOutput) =>
- if debugOutput
- if array.get(tfSensitiveSettings, 61)
- while array.size(aFlt) > 0
- [curH, curHB, curL, curLB, curC, curR, curSL, curSR, curSF] = arPop(aFlt, aInt)
- if (curH and curL)
- printPriceLeg(tfSensitiveSettings, tfIndependentSettings, aBarIndex, curHB, curH, curLB, curL, curC, curR, curSL, curSR, long, false, true)
- array.clear(aFlt)
- array.clear(aInt)
- arInit(array<float> aLFlt, array<int> aLInt, array<float> aSFlt, array<int> aSInt, array<float> tfSensitiveSettings = na, array<float> tfIndependentSettings = na, array<int> aBarIndex = na, debugOutput = false) =>
- arClear(aLFlt, aLInt, true, tfSensitiveSettings, tfIndependentSettings, aBarIndex, debugOutput)
- arClear(aSFlt, aSInt, false, tfSensitiveSettings, tfIndependentSettings, aBarIndex, debugOutput)
- arPush(aLFlt, aLInt)
- arPush(aSFlt, aSInt)
- arGetFlt(int parameter, array<float> aFlt, int id) => array.get(aFlt, id * plFlt + plFlt - parameter - 1)
- arGetInt(int parameter, array<int> aInt, int id) => array.get(aInt, id * plInt + plInt - parameter - 1)
- arSetFlt(int parameter, array<float> aFlt, int id, float value) => array.set(aFlt, id * plFlt + plFlt - parameter - 1, value)
- arSetInt(int parameter, array<int> aInt, int id, int value) => array.set(aInt, id * plInt + plInt - parameter - 1, value)
- arSizeFlt(array<float> aFlt) => array.size(aFlt) / plFlt
- arSizeInt(array<int> aInt) => array.size(aInt) / plInt
- // Split all entries later than splitBar into other array
- // First entry with "na" in LocalH will alwaays get split
- arSplit(array<float> aFlt, array<int> aInt, array<float> sFlt, array<int> sInt, bool long = false, int splitBar = na) =>
- while array.size(aFlt) > 0
- if not na(splitBar)
- aSize = arSizeFlt(aFlt)
- if arGetInt(long ? 01 : 00, aInt, aSize - 1) <= splitBar
- and not na(arGetFlt(00, aFlt, aSize - 1))
- and not na(arGetFlt(01, aFlt, aSize - 1))
- break
- array.push(sFlt, array.pop(aFlt))
- array.push(sFlt, array.pop(aFlt))
- array.push(sFlt, array.pop(aFlt))
- array.push(sFlt, array.pop(aFlt))
- array.push(sInt, array.pop(aInt))
- array.push(sInt, array.pop(aInt))
- array.push(sInt, array.pop(aInt))
- array.push(sInt, array.pop(aInt))
- array.push(sInt, array.pop(aInt))
- // Get last price bar before the bar specified
- arGetLastBar(array<int> aInt, int i) =>
- if i - 1 < 0 or i > arSizeInt(aInt)
- na
- else
- math.max(arGetInt( 00, aInt,i - 1), arGetInt(01, aInt, i - 1))
- // --------------------------------------------------------------
- // 04.04.02 FUNCTIONS: ARRAYS | Current Data
- // --------------------------------------------------------------
- arStateGet(aStateInt, aStateBool) =>
- [array.get(aStateInt, 0),
- array.get(aStateBool, 0),
- array.get(aStateBool, 1),
- array.get(aStateInt, 1)]
- arStateSet(aStateInt, aStateBool, int gTD, bool bT, bool bB, int bBC) =>
- array.set(aStateInt, 0, gTD)
- array.set(aStateBool, 0, bT)
- array.set(aStateBool, 1, bB)
- array.set(aStateInt, 1, bBC)
- arValuesGet(aValuesFlt, aValuesInt) =>
- [array.get(aValuesFlt, 0),
- array.get(aValuesInt, 0),
- array.get(aValuesFlt, 1),
- array.get(aValuesInt, 1),
- array.get(aValuesFlt, 2),
- array.get(aValuesInt, 2),
- array.get(aValuesFlt, 3),
- array.get(aValuesInt, 3),
- array.get(aValuesFlt, 4),
- array.get(aValuesFlt, 5),
- array.get(aValuesFlt, 6),
- array.get(aValuesFlt, 7),
- array.get(aValuesFlt, 8),
- array.get(aValuesFlt, 9),
- array.get(aValuesFlt, 10),
- array.get(aValuesFlt, 11),
- array.get(aValuesFlt, 12),
- array.get(aValuesFlt, 13),
- array.get(aValuesInt, 4),
- array.get(aValuesFlt, 14),
- array.get(aValuesFlt, 15),
- array.get(aValuesInt, 5),
- array.get(aValuesFlt, 16),
- array.get(aValuesFlt, 17),
- array.get(aValuesInt, 6),
- array.get(aValuesFlt, 18),
- array.get(aValuesFlt, 19),
- array.get(aValuesInt, 7)]
- arValuesSet(aValuesFlt, aValuesInt, float pH, int pHB, float pL, int pLB, float gH, int gHB, float gL, int gLB,
- float gHC, float gLC, float nHC, float nLC,
- float varLClose, float varLReverse, float varSClose, float varSReverse,
- float bosLH, float bosLL, int bosLB, float bosSH, float bosSL, int bosSB,
- float cbosLH, float cbosLL, int cbosLB, float cbosSH, float cbosSL, int cbosSB) =>
- array.set(aValuesFlt, 0, pH)
- array.set(aValuesInt, 0, pHB)
- array.set(aValuesFlt, 1, pL)
- array.set(aValuesInt, 1, pLB)
- array.set(aValuesFlt, 2, gH)
- array.set(aValuesInt, 2, gHB)
- array.set(aValuesFlt, 3, gL)
- array.set(aValuesInt, 3, gLB)
- array.set(aValuesFlt, 4, gHC)
- array.set(aValuesFlt, 5, gLC)
- array.set(aValuesFlt, 6, nHC)
- array.set(aValuesFlt, 7, nLC)
- array.set(aValuesFlt, 8, varLClose)
- array.set(aValuesFlt, 9, varLReverse)
- array.set(aValuesFlt, 10, varSClose)
- array.set(aValuesFlt, 11, varSReverse)
- array.set(aValuesFlt, 12, bosLH)
- array.set(aValuesFlt, 13, bosLL)
- array.set(aValuesInt, 4, bosLB)
- array.set(aValuesFlt, 14, bosSH)
- array.set(aValuesFlt, 15, bosSL)
- array.set(aValuesInt, 5, bosSB)
- array.set(aValuesFlt, 16, cbosLH)
- array.set(aValuesFlt, 17, cbosLL)
- array.set(aValuesInt, 6, cbosLB)
- array.set(aValuesFlt, 18, cbosSH)
- array.set(aValuesFlt, 19, cbosSL)
- array.set(aValuesInt, 7, cbosSB)
- // --------------------------------------------------------------
- // 04.05 FUNCTIONS: INDICATOR LOGIC
- // --------------------------------------------------------------
- var failWR = array.new<float>(0)
- var failCR = array.new<float>(0)
- var failRR = array.new<float>(0)
- var failSW = array.new<float>(0)
- var failWA = array.new<float>(0)
- var succWR = array.new<float>(0)
- var succCR = array.new<float>(0)
- var succRR = array.new<float>(0)
- var succSW = array.new<float>(0)
- var succWA = array.new<float>(0)
- checkConditionGlobalChange(tfSensitiveSettings, tfIndependentSettings, array<int> aBarIndex, localB, globalH, globalL, localH, localL, localClose, localReverse, localSidewaysL, localSidewaysR, atr, long) =>
- usebosFiboCorrectionWickRelativeThresholdOr = array.get(tfSensitiveSettings, 15)
- usebosFiboCorrectionCloseRelativeThresholdOr = array.get(tfSensitiveSettings, 17)
- usebosFiboReverseRelativeThresholdOr = array.get(tfSensitiveSettings, 19)
- usebosCandleLengthThresholdOr = array.get(tfSensitiveSettings, 21)
- usebosAtrThresholdOr = array.get(tfSensitiveSettings, 37)
- // Condition 1/2: Relative Correction Threshold Reached
- // Price corrected at least this much %, when compared to distance between global high and low, measured to wick or to body
- // LONG: localClose is highest close, SHORT: localClose is lowest close
- localH2 = long ? localClose : localH
- localL2 = long ? localL : localClose
- wickRelative = (localH - localL) / (globalH - globalL)
- correctionWickRelativeThresholdReachedOr = wickRelative >= array.get(tfSensitiveSettings, 14)
- correctionWickRelativeThresholdReachedAnd = wickRelative >= array.get(tfSensitiveSettings, 22)
- closeRelative = (localH2 - localL2) / (globalH - globalL)
- correctionCloseRelativeThresholdReachedOr = closeRelative >= array.get(tfSensitiveSettings, 16)
- correctionCloseRelativeThresholdReachedAnd = closeRelative >= array.get(tfSensitiveSettings, 24)
- // Condition 3: Reverse Threshold Relative Reached
- // Price corrected from reverse low at least this much %, when compared to distance between global high and low
- // LONG: localReverse is highest low, SHORT: localReverse is lowest high
- localH3 = long ? localReverse : localH
- localL3 = long ? localL : localReverse
- reverseRelative = (localH3 - localL3) / (globalH - globalL)
- reverseRelativeThresholdReachedOr = reverseRelative >= array.get(tfSensitiveSettings, 18)
- reverseRelativeThresholdReachedAnd = reverseRelative >= array.get(tfSensitiveSettings, 26)
- // Condition 4: Price has spent in a sideways movement at least this much
- sideways = math.max(0, localSidewaysL + localSidewaysR - 1)
- sidewaysThresholdReachedOr = sideways >= array.get(tfSensitiveSettings, 20)
- sidewaysThresholdReachedAnd = sideways >= array.get(tfSensitiveSettings, 28)
- // Condition 5: Price has corrected from wick this much relative to its ATR
- wickAbsolute = (localH - localL) / atr
- atrThresholdReachedOr = wickAbsolute >= array.get(tfSensitiveSettings, 36)
- atrThresholdReachedAnd = wickAbsolute >= array.get(tfSensitiveSettings, 38)
- // Conditions combined
- orUsed = usebosFiboCorrectionWickRelativeThresholdOr
- or usebosFiboCorrectionCloseRelativeThresholdOr
- or usebosFiboReverseRelativeThresholdOr
- or usebosCandleLengthThresholdOr
- or usebosAtrThresholdOr
- orConditions = not orUsed
- or correctionWickRelativeThresholdReachedOr and usebosFiboCorrectionWickRelativeThresholdOr
- or correctionCloseRelativeThresholdReachedOr and usebosFiboCorrectionCloseRelativeThresholdOr
- or reverseRelativeThresholdReachedOr and usebosFiboReverseRelativeThresholdOr
- or sidewaysThresholdReachedOr and usebosCandleLengthThresholdOr
- or atrThresholdReachedOr and usebosAtrThresholdOr
- andConditions = (correctionWickRelativeThresholdReachedAnd or not array.get(tfSensitiveSettings, 23))
- and (correctionCloseRelativeThresholdReachedAnd or not array.get(tfSensitiveSettings, 25))
- and (reverseRelativeThresholdReachedAnd or not array.get(tfSensitiveSettings, 27))
- and (sidewaysThresholdReachedAnd or not array.get(tfSensitiveSettings, 29))
- and (atrThresholdReachedAnd or not array.get(tfSensitiveSettings, 39))
- globalChange = orConditions and andConditions
- detailedResults = array.get(tfIndependentSettings, 08)
- if array.get(tfIndependentSettings, 06) and (globalChange or not array.get(tfIndependentSettings, 07))
- and array.get(tfSensitiveSettings, 60)
- offset = int(array.get(tfSensitiveSettings, 50))
- x = array.get(aBarIndex, localB) - offset
- debugTextX(x,
- array.get(tfIndependentSettings, 09) ?
- (globalChange ? "PASS" : "FAIL") + "\n" +
- "" + (correctionWickRelativeThresholdReachedOr ? "V" : "-") +
- (correctionWickRelativeThresholdReachedAnd ? "V" : "-") + (detailedResults ? " " + str.tostring(math.round(wickRelative, 3)) : "") + "\n" +
- "" + (correctionCloseRelativeThresholdReachedOr ? "V" : "-") +
- (correctionCloseRelativeThresholdReachedAnd ? "V" : "-") + (detailedResults ? " " + str.tostring(math.round(closeRelative, 3)) : "") + "\n" +
- "" + (reverseRelativeThresholdReachedOr ? "V" : "-") +
- (reverseRelativeThresholdReachedAnd ? "V" : "-") + (detailedResults ? " " + str.tostring(math.round(reverseRelative, 3)) : "") + "\n" +
- "" + (sidewaysThresholdReachedOr ? "V" : "-") +
- (sidewaysThresholdReachedAnd ? "V" : "-") + (detailedResults ? " " + str.tostring(sideways) : "")+ "\n"+
- "" + (atrThresholdReachedOr ? "V" : "-") +
- (atrThresholdReachedAnd ? "V" : "-") + (detailedResults ? " " + str.tostring(math.round(wickAbsolute, 3)) : "")
- :
- "GHL " + str.tostring(globalH, format.mintick) + " - " + str.tostring(globalL, format.mintick) + "\n" +
- "ATR " + str.tostring(atr, format.mintick) + " - " + str.tostring(atr / (localH + localL) * 2 * 100,"#.##") + "%\n\n" +
- "HL " + str.tostring(localH, format.mintick) + " - " + str.tostring(localL, format.mintick) + "\n" +
- "CR " + str.tostring(localClose, format.mintick) + " - " + str.tostring(localReverse, format.mintick) + "\n" +
- "SW " + str.tostring(localSidewaysL) + " + " + str.tostring(localSidewaysR) + " = " + str.tostring(sideways) + "\n\n" +
- (globalChange ? "PASS" : "FAIL") + "\n" +
- "WR " + str.tostring(correctionWickRelativeThresholdReachedOr) + " - " +
- str.tostring(correctionWickRelativeThresholdReachedAnd) + (detailedResults ? " " + str.tostring(math.round(wickRelative, 3)) : "") + "\n" +
- "CR " + str.tostring(correctionCloseRelativeThresholdReachedOr) + " - " +
- str.tostring(correctionCloseRelativeThresholdReachedAnd) + (detailedResults ? " " + str.tostring(math.round(closeRelative, 3)) : "") + "\n" +
- "RR " + str.tostring(reverseRelativeThresholdReachedOr) + " - " +
- str.tostring(reverseRelativeThresholdReachedAnd) + (detailedResults ? " " + str.tostring(math.round(reverseRelative, 3)) : "") + "\n" +
- "SW " + str.tostring(sidewaysThresholdReachedOr) + " - " +
- str.tostring(sidewaysThresholdReachedAnd) + (detailedResults ? " " + str.tostring(sideways) : "")+ "\n"+
- "WA " + str.tostring(atrThresholdReachedOr) + " - " +
- str.tostring(atrThresholdReachedAnd) + (detailedResults ? " " + str.tostring(math.round(wickAbsolute, 3)) : ""),
- bgcolor = globalChange ? #00065586 : #55002f86)
- array.push(correctionWickRelativeThresholdReachedOr ? succWR : failWR, wickRelative)
- array.push(correctionCloseRelativeThresholdReachedOr ? succCR : failCR, closeRelative)
- array.push(reverseRelativeThresholdReachedOr ? succRR : failRR, reverseRelative)
- array.push(sidewaysThresholdReachedAnd ? succSW : failSW, sideways)
- array.push(atrThresholdReachedAnd ? succWA : failWA, wickAbsolute)
- globalChange
- checkConditionBosBreak(tfSensitiveSettings, bosBreachCandles) =>
- usebosBreakCandleThresholdOr = array.get(tfSensitiveSettings, 03)
- bosBreakCandleThresholdReachedOr = bosBreachCandles >= array.get(tfSensitiveSettings, 02)
- bosBreakCandleThresholdReachedAnd = bosBreachCandles >= array.get(tfSensitiveSettings, 04)
- orUsed = usebosBreakCandleThresholdOr
- or false //In case we make more conditions in the future
- orConditions = not orUsed
- or bosBreakCandleThresholdReachedOr and usebosBreakCandleThresholdOr
- andConditions = (bosBreakCandleThresholdReachedAnd or not array.get(tfSensitiveSettings, 05))
- and true //In case we make more conditions in the future
- bosBreakCondition = orConditions and andConditions
- bosBreakCondition
- checkConditionNewBosBeyondOld(tfSensitiveSettings, int globalTrendDirection, float highLow, float openClose, float bosLH, float bosLL, float bosSH, float bosSL) =>
- newBosThreshold = array.get(tfSensitiveSettings, 01)
- newBosConfirmConditionLevel = array.get(tfSensitiveSettings, 00)
- if newBosConfirmConditionLevel == 2
- (globalTrendDirection == 1 and openClose > bosLH * (100 + newBosThreshold) / 100)
- or (globalTrendDirection == -1 and openClose * (100 + newBosThreshold) / 100 < bosSL)
- else
- (globalTrendDirection == 1 and highLow > (newBosConfirmConditionLevel ? bosLH : bosLL) * (100 + newBosThreshold) / 100)
- or (globalTrendDirection == -1 and highLow * (100 + newBosThreshold) / 100 < (newBosConfirmConditionLevel ? bosSL : bosSH))
- checkConditionManipulationLong(tfSensitiveSettings, tHigh, tLow, tClose, barIndex, globalHB) =>
- array.get(tfSensitiveSettings, 12) and (tHigh - tClose) / (tHigh - tLow) >= array.get(tfSensitiveSettings, 11) / 100 and globalHB < barIndex - 1
- checkConditionManipulationShort(tfSensitiveSettings, tHigh, tLow, tClose, barIndex, globalLB) =>
- array.get(tfSensitiveSettings, 12) and (tClose - tLow) / (tHigh - tLow) >= array.get(tfSensitiveSettings, 11) / 100 and globalLB < barIndex - 1
- findGlobalLow(float globalL, int globalLB, float currentL, int barIndex, array<float> aFlt, array<int> aInt, bool checkNa = false, int ignoreAmount = 0) =>
- g_l = globalL
- g_lb = globalLB
- if na(g_l) or g_l > currentL
- g_l := currentL
- g_lb := barIndex
- aSize = arSizeFlt(aFlt)
- if aSize > ignoreAmount
- for i = ignoreAmount to aSize - 1
- if checkNa
- if na(arGetFlt(00, aFlt, i))
- continue
- lastLocalL = arGetFlt(01, aFlt, i)
- if na(g_l) or g_l > lastLocalL
- g_l := lastLocalL
- g_lb := arGetInt(01, aInt, i)
- [g_l, g_lb]
- findGlobalHigh(float globalH, int globalHB, float currentH, int barIndex, array<float> aFlt, array<int> aInt, bool checkNa = false, int ignoreAmount = 0) =>
- g_h = globalH
- g_hb = globalHB
- if na(g_h) or g_h < currentH
- g_h := currentH
- g_hb := barIndex
- aSize = arSizeFlt(aFlt)
- if aSize > ignoreAmount
- for i = ignoreAmount to aSize - 1
- if checkNa
- if na(arGetFlt(01, aFlt, i))
- continue
- lastLocalH = arGetFlt(00, aFlt, i)
- if na(g_h) or g_h < lastLocalH
- g_h := lastLocalH
- g_hb := arGetInt(00, aInt, i)
- [g_h, g_hb]
- // --------------------------------------------------------------
- // 05 GET RISK SIZE
- // --------------------------------------------------------------
- // // Entry size will be = risk_size/close
- // var start_price = 0.0
- // var float risk_size = na
- // if doStrategyBackTest and barstate.isfirst
- // strategy.entry( "Get order size", strategy.long)
- // start_price := close
- // if doStrategyBackTest and ta.barssince(barstate.isfirst) >= 1 and strategy.position_entry_name == "Get order size"
- // risk_size := strategy.position_size * start_price
- // strategy.close("Get order size",comment="Got order size")
- // --------------------------------------------------------------
- // 06 MAIN CODE
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 06.01 BEGIN TREND & BOS DETERMINATION ALGORITHM
- // --------------------------------------------------------------
- algoTrendAndBosTick(int barIndex, array<int> aBarIndex, array<float> aHigh, array<float> aLow, array<float> aOpen, array<float> aClose, array<float> aMaxOC, array<float> aMinOC, array<float> aPivotH, array<float> aPivotL, array<float> aLFlt, array<int> aLInt, array<float> aSFlt, array<int> aSInt, array<float> tfSensitiveSettings, array<float> tfIndependentSettings, array<int> aStateInt, array<bool> aStateBool, array<float> aValuesFlt, array<int> aValuesInt, bool finalize) =>
- // CONSTS
- // Theese are used to feed annoying "must define na type" user function bug by TradingView
- float _fna = na
- int _ina = na
- // ARRAYS
- // Temporary "Split" arrays, to temporary hold split members
- var sFlt = array.new<float>(0)
- var sInt = array.new<int>(0)
- // VARIABLES
- // Variables for trend acquisition
- var float acqLocalH = na
- var int acqLocalHB = na
- var float acqLocalL = na
- var int acqLocalLB = na
- var int firstCandleState = na
- // Algo internal states
- executeGlobalTrendChange = false
- executeBosLevelSearch = false
- executeBosLevelUpdate = false
- // ATR
- var float atr = na
- // Classic BOS Bar
- int classicB = na
- [globalTrendDirection, bosTesting, bosBreached, bosBreachCandles] = arStateGet(aStateInt, aStateBool)
- [priorH, priorHB, priorL, priorLB, globalH, globalHB, globalL, globalLB,
- globalHC, globalLC, curNextHC, curNextLC,
- curLNextClose, curLNextReverse, curSNextClose, curSNextReverse,
- bosLH, bosLL, bosLB, bosSH, bosSL, bosSB,
- cbosLH, cbosLL, cbosLB, cbosSH, cbosSL, cbosSB] = arValuesGet(aValuesFlt, aValuesInt)
- tHigh = array.get(aHigh, 0)
- tLow = array.get(aLow, 0)
- tOpen = array.get(aOpen, 0)
- tClose = array.get(aClose, 0)
- tMaxOC = array.get(aMaxOC, 0)
- tMinOC = array.get(aMinOC, 0)
- tPivotH = array.get(aPivotH, 0)
- tPivotL = array.get(aPivotL, 0)
- // Reset algo state
- bosTesting := false
- prevBreachCandles = bosBreachCandles
- bosBreachCandles := 0
- // Globally used settings
- bosIgnoreManipulationsAmount = int(array.get(tfSensitiveSettings, 12))
- useAtrBreakThreshold = array.get(tfSensitiveSettings, 31)
- bosSameCandleLegConsumptionDelay = int(array.get(tfSensitiveSettings, 13))
- bosConsiderNextEnabled = array.get(tfSensitiveSettings, 06)
- bosConsiderNextRecursive = array.get(tfSensitiveSettings, 10)
- bosConsiderNextConsumptionThreshold = array.get(tfSensitiveSettings, 09)
- bosConsiderNextDistanceThreshold = array.get(tfSensitiveSettings, 07)
- bosConsiderNextConsumptionEnabled = array.get(tfSensitiveSettings, 08)
- // --------------------------------------------------------------
- // 06.01.01 TREND & BOS | Initial Calculations
- // --------------------------------------------------------------
- // ATR
- atrLength = array.get(tfSensitiveSettings, 32)
- if na(atr)
- atr := tHigh - tLow
- else
- prevClose = array.get(aClose, 1)
- curAtr = math.max(tHigh - tLow, math.abs(tHigh - prevClose), math.abs(tLow - prevClose))
- atr := (atr * (atrLength - 1) + curAtr ) / atrLength
- // --------------------------------------------------------------
- // 06.01.02 TREND & BOS | Init & Acquire Trend
- // --------------------------------------------------------------
- // Initial trend forced Long
- if globalTrendDirection == 2
- priorH := tHigh
- priorHB := barIndex
- priorL := tLow
- priorLB := barIndex
- globalH := priorH
- globalHB := priorHB
- globalL := priorL
- globalLB := priorLB
- globalTrendDirection := -1
- arInit(aLFlt, aLInt, aSFlt, aSInt)
- executeGlobalTrendChange := true
- executeBosLevelUpdate := true
- // Initial trend forced Short
- else if globalTrendDirection == -2
- priorH := tHigh
- priorHB := barIndex
- priorL := tLow
- priorLB := barIndex
- globalH := priorH
- globalHB := priorHB
- globalL := priorL
- globalLB := priorLB
- globalTrendDirection := 1
- arInit(aLFlt, aLInt, aSFlt, aSInt)
- executeGlobalTrendChange := true
- executeBosLevelUpdate := true
- // Initial trend acquisition
- else if globalTrendDirection == 0
- MAX_INITIAL_CANDLES = array.get(tfIndependentSettings, 00)
- globalHC := na(globalHC) or tMaxOC > globalHC ? tMaxOC : globalHC
- globalLC := na(globalLC) or tMinOC < globalLC ? tMinOC : globalLC
- // Step 1 : Record first available high/low once acquired, and rewrite them as long as both are pierced in same candle
- if na(priorH) or (na(globalH) and tHigh > priorH and tLow < priorL)
- priorH := tHigh
- priorHB := barIndex
- priorL := tLow
- priorLB := barIndex
- firstCandleState := tClose >= tOpen ? 1 : -1
- // Step 2 : Record first price leg once price exceeds first available values
- else if na(globalH) or barIndex - priorHB > MAX_INITIAL_CANDLES
- // If price breached prior up (and only up)
- // First leg is up
- if tHigh > priorH
- globalH := tHigh
- globalHB := barIndex
- globalL := priorL
- globalLB := priorLB
- // If price breached prior down (and only down)
- // First leg is down
- else if tLow < priorL
- globalL := tLow
- globalLB := barIndex
- globalH := priorH
- globalHB := priorHB
- // Determine trend regardless if waited enough
- if barIndex - priorHB > MAX_INITIAL_CANDLES
- if na(globalH)
- globalL := priorL
- globalLB := priorLB
- globalH := priorH
- globalHB := priorHB
- globalTrendDirection := -firstCandleState
- arInit(aLFlt, aLInt, aSFlt, aSInt)
- executeGlobalTrendChange := true
- executeBosLevelUpdate := true
- // Step 3 : Record locals and determine trend when possible
- else
- // Record new local high as long as we don't have both pivots in a downtrend
- if tPivotH and (na(acqLocalH) or tPivotH > acqLocalH) and (na(tPivotL) or globalLB < globalHB)
- acqLocalH := tPivotH
- acqLocalHB := barIndex
- // Record new local low as we don't have both pivots in an uptrend
- if tPivotL and (na(acqLocalL) or tPivotL < acqLocalL) and (na(tPivotH) or globalHB < globalLB)
- acqLocalL := tPivotL
- acqLocalLB := barIndex
- // If breached global high or waited enough
- if tHigh > globalH or barIndex - globalLB > MAX_INITIAL_CANDLES
- // If with local low or first leg is down or enough candles passed
- // We got a long trend!
- if acqLocalL or globalHB < globalLB or barIndex - globalLB > MAX_INITIAL_CANDLES
- globalL := na(acqLocalL) ? globalL : acqLocalL
- globalLB := na(acqLocalL) ? globalLB : acqLocalLB
- globalTrendDirection := -1
- arInit(aLFlt, aLInt, aSFlt, aSInt)
- executeGlobalTrendChange := true
- executeBosLevelUpdate := true
- // Update global high for now
- if tHigh > globalH
- globalH := tHigh
- globalHB := barIndex
- // Breached global Low or waited enough
- else if tLow < globalL or barIndex - globalHB > MAX_INITIAL_CANDLES
- // If with local high or first leg is up
- // We got a short trend!
- if acqLocalH or globalLB < globalHB or barIndex - globalHB > MAX_INITIAL_CANDLES
- globalH := na(acqLocalH) ? globalH : acqLocalH
- globalHB := na(acqLocalH) ? globalHB : acqLocalHB
- globalTrendDirection := 1
- arInit(aLFlt, aLInt, aSFlt, aSInt)
- executeGlobalTrendChange := true
- executeBosLevelUpdate := true
- // Update global low for now
- if tLow < globalL
- globalL := tLow
- globalLB := barIndex
- // --------------------------------------------------------------
- // 06.01.03 TREND & BOS | Accumulated values
- // --------------------------------------------------------------
- if globalTrendDirection != 0
- curNextHC := na(curNextHC) or curNextHC < tMaxOC ? tMaxOC : curNextHC
- curNextLC := na(curNextLC) or curNextLC > tMinOC ? tMinOC : curNextLC
- curLNextClose := na(curLNextClose) or curLNextClose < tMaxOC ? tMaxOC : curLNextClose
- curLNextReverse := na(curLNextReverse) or curLNextReverse < tLow ? tLow : curLNextReverse
- curSNextClose := na(curSNextClose) or curSNextClose > tMinOC ? tMinOC : curSNextClose
- curSNextReverse := na(curSNextReverse) or curSNextReverse > tHigh ? tHigh : curSNextReverse
- if globalTrendDirection == 1
- globalHC := curNextHC
- if globalTrendDirection == -1
- globalLC := curNextLC
- // --------------------------------------------------------------
- // 06.01.04 TREND & BOS | Long Breaching
- // --------------------------------------------------------------
- if globalTrendDirection == 1
- // If in bos breach mode
- // Determine if resumed prior trend
- if bosBreached
- // If breached priorL
- // Then resumed prior trend
- if tLow < priorL - (useAtrBreakThreshold ? atr * array.get(tfSensitiveSettings, 33) : priorL * array.get(tfSensitiveSettings, 30)) / 100
- // When resuming prior short trend, global low should be like if this were a short trend leg
- // When in short trend, we breach global low
- // Here, we breach prior low, but in terms of price action, we have a certain low we fell from downwards
- // That should be our global low for purpose of bos search
- [curL, curLB] = findGlobalLow(_fna, _ina, _fna, barIndex, aSFlt, aSInt, true, 1)
- globalL := na(curL) ? priorL : curL
- globalLB := na(curL) ? priorLB : curLB
- bosBreached := false
- executeBosLevelSearch := true
- executeGlobalTrendChange := true
- executeBosLevelUpdate := true
- // If not in bos breach mode
- else
- // Determine if testing bos
- bosTesting := (tLow < bosSH or array.get(aLow, 1) < bosSH)
- // Determine if breaching bos - when enough candles are observed confirm bos breach
- if tHigh < bosSL * (100 - array.get(tfSensitiveSettings, 01)) / 100
- bosBreachCandles := prevBreachCandles + 1
- // BOS Break!
- if checkConditionBosBreak(tfSensitiveSettings, bosBreachCandles)
- priorH := globalH
- priorHB := globalHB
- bosBreached := true
- executeBosLevelSearch := true
- executeGlobalTrendChange := true
- // --------------------------------------------------------------
- // 06.01.05 TREND & BOS | SHORT Breaching
- // --------------------------------------------------------------
- else if globalTrendDirection == -1
- // If in bos breach mode
- // Determine if resumed prior trend
- if bosBreached
- // If breached priorH
- // Then resumed prior trend
- if tHigh > priorH + (useAtrBreakThreshold ? atr * array.get(tfSensitiveSettings, 33) : priorH * array.get(tfSensitiveSettings, 30)) / 100
- // When resuming prior long trend, global high should be like if this were a long trend leg
- // When in long trend, we breach global high
- // Here, we breach prior high, but in terms of price action, we have a certain high we pumped from upwards
- // That should be our global high for purpose of bos search
- [curH, curHB] = findGlobalHigh(_fna, _ina, _fna, barIndex, aLFlt, aLInt, true, 1)
- globalH := na(curH) ? priorH : curH
- globalHB := na(curH) ? priorHB : curHB
- bosBreached := false
- executeBosLevelSearch := true
- executeGlobalTrendChange := true
- executeBosLevelUpdate := true
- // If not in bos breach mode
- else
- // Determine if testing bos
- bosTesting := tHigh > bosLL or array.get(aHigh, 1) > bosLL
- // Determine if breaching bos - when enough candles are observed confirm bos breach
- if tLow > bosLH * (100 + array.get(tfSensitiveSettings, 01)) / 100
- bosBreachCandles := prevBreachCandles + 1
- // BOS Break!
- if checkConditionBosBreak(tfSensitiveSettings, bosBreachCandles)
- priorL := globalL
- priorLB := globalLB
- bosBreached := true
- executeBosLevelSearch := true
- executeGlobalTrendChange := true
- // --------------------------------------------------------------
- // 06.01.06 TREND & BOS | New HH / LL
- // --------------------------------------------------------------
- if globalTrendDirection != 0
- if globalTrendDirection == 1 and not executeGlobalTrendChange
- // If broke global high
- // Record new high, update BOS if possible
- if tHigh > globalH + (useAtrBreakThreshold ? atr * array.get(tfSensitiveSettings, 33) : globalH * array.get(tfSensitiveSettings, 30)) / 100
- executeBosLevelSearch := true
- else if globalTrendDirection == -1 and not executeGlobalTrendChange
- // If broke global low
- // Record new low, update BOS if possible
- if tLow < globalL - (useAtrBreakThreshold ? atr * array.get(tfSensitiveSettings, 33) : globalL * array.get(tfSensitiveSettings, 30)) / 100
- executeBosLevelSearch := true
- nextTrend = globalTrendDirection == 0 ? 0 : executeGlobalTrendChange ? -globalTrendDirection : globalTrendDirection
- // --------------------------------------------------------------
- // 06.01.07 TREND & BOS | Price Legs
- // --------------------------------------------------------------
- // Possible BOS breaching means we are uncertain where the trend will go
- // So we record price legs both ways always, the only exception is initial state with no trend
- // --------------------------------------------------------------
- // 06.01.07.01 TREND & BOS | Price Legs | Long New Candle Data
- // --------------------------------------------------------------
- if globalTrendDirection != 0
- [curLLocalH, curLLocalHB, curLLocalL, curLLocalLB, curLClose, curLReverse, curLSidewaysL, curLSidewaysR, curLSidewaysF] = arPop(aLFlt, aLInt)
- // If encountered pivot low
- // If it's a lower or first local low
- // Record it and all its data
- // Otherwise it's ignored
- if tPivotL and (curLLocalH or tPivotH) and (na(curLLocalL) or tPivotL < curLLocalL)
- // A special case of high and low in one candle
- if tPivotH and na(curLLocalH)
- curLLocalH := tPivotH
- curLLocalHB := barIndex
- curLLocalL := tPivotL
- curLLocalLB := barIndex
- curLSidewaysL := na
- // Reverse close low that has been calculated so far is now included and consumed
- curLClose := na(curLClose) ? curLNextClose : math.max(curLClose, curLNextClose)
- curLNextClose := na
- curLReverse := na(curLReverse) ? curLNextReverse : math.max(curLReverse, curLNextReverse)
- curLNextReverse := na
- // If encountered a pivot high
- if tPivotH
- // If we have a local price leg (both high and low)
- if curLLocalL
- // Pack last price leg into array, begin a new one
- arPush(aLFlt, aLInt, curLLocalH, curLLocalHB, curLLocalL, curLLocalLB, curLClose, curLReverse, curLSidewaysL, curLSidewaysR, curLSidewaysF)
- curLLocalH := na
- curLLocalL := na
- curLClose := na
- curLReverse := na
- curLSidewaysL := na
- if na(curLLocalH) or tPivotH > curLLocalH
- curLLocalH := tPivotH
- curLLocalHB := barIndex
- arPush(aLFlt, aLInt, curLLocalH, curLLocalHB, curLLocalL, curLLocalLB, curLClose, curLReverse, curLSidewaysL, curLSidewaysR, curLSidewaysF)
- // --------------------------------------------------------------
- // 06.01.07.02 TREND & BOS | Price Legs | Short New Candle Data
- // --------------------------------------------------------------
- if globalTrendDirection != 0
- [curSLocalH, curSLocalHB, curSLocalL, curSLocalLB, curSClose, curSReverse, curSSidewaysL, curSSidewaysR, curSSidewaysF] = arPop(aSFlt, aSInt)
- // If encountered pivot high
- // If it's a higher or first local high
- // Record it and all its data
- // Otherwise it's ignored
- if tPivotH and (tPivotL or curSLocalL) and (na(curSLocalH) or tPivotH > curSLocalH)
- // A special case of high and low in one candle
- if tPivotL and na(curSLocalL)
- curSLocalL := tPivotL
- curSLocalLB := barIndex
- curSLocalH := tPivotH
- curSLocalHB := barIndex
- curSSidewaysL := na
- // Reverse high and close that has been calculated so far is now included and consumed
- curSClose := na(curSClose) ? curSNextClose : math.min(curSClose, curSNextClose)
- curSNextClose := na
- curSReverse := na(curSReverse) ? curSNextReverse : math.min(curSReverse, curSNextReverse)
- curSNextReverse := na
- // If encountered a pivot low
- if tPivotL
- // If we have a local price leg (both high and low)
- if curSLocalH
- // Pack last price leg into array, begin a new one
- arPush(aSFlt, aSInt, curSLocalH, curSLocalHB, curSLocalL, curSLocalLB, curSClose, curSReverse, curSSidewaysL, curSSidewaysR, curSSidewaysF)
- curSLocalH := na
- curSLocalL := na
- curSClose := na
- curSReverse := na
- curSSidewaysL := na
- if na(curSLocalL) or tPivotL < curSLocalL
- curSLocalL := tPivotL
- curSLocalLB := barIndex
- arPush(aSFlt, aSInt, curSLocalH, curSLocalHB, curSLocalL, curSLocalLB, curSClose, curSReverse, curSSidewaysL, curSSidewaysR, curSSidewaysF)
- // --------------------------------------------------------------
- // 06.01.07.03 TREND & BOS | Price Legs | Long Merge
- // --------------------------------------------------------------
- if globalTrendDirection != 0
- // Extra offset is nullified in case this candle is breaching BOS and isn't a manipulation
- // In this case we are merging right before a bos level search to include candles that would otherwise be excluded
- // Otherwise we don't merge bars within this offset, so they don't overwrite previous legs that could be used
- splitOffset = 1 + (executeBosLevelSearch
- and ((not checkConditionManipulationLong(tfSensitiveSettings, tHigh, tLow, tClose, barIndex, globalHB) and nextTrend == 1)
- or (not checkConditionManipulationShort(tfSensitiveSettings, tHigh, tLow, tClose, barIndex, globalLB) and nextTrend == -1)) ? 0 :
- bosIgnoreManipulationsAmount)
- // Combine all price legs that get overwritten by price legs after the offset (in case of manipulation)
- i = arSizeFlt(aLFlt)
- // Go on while there are at least two legs left to compare
- while i >= 2
- i := i - 1
- if splitOffset and arGetInt(01, aLInt, i) > barIndex - splitOffset
- continue
- // Attempt merger of current leg with the previous one
- prevL = arGetFlt(01, aLFlt, i - 1)
- curL = arGetFlt(01, aLFlt, i)
- // Only legs with a lower low should be kept alive
- if na(curL) or prevL < curL
- continue
- // Take its reverse low and close if higher
- arSetFlt(02, aLFlt, i, math.max(arGetFlt(02, aLFlt, i), arGetFlt(02, aLFlt, i - 1)))
- arSetFlt(03, aLFlt, i, math.max(arGetFlt(03, aLFlt, i), arGetFlt(03, aLFlt, i - 1)))
- // Take its local high if it's higher
- prevH = arGetFlt(00, aLFlt, i - 1)
- if prevH > arGetFlt(00, aLFlt, i)
- arSetFlt(00, aLFlt, i, prevH)
- arSetInt(00, aLInt, i, arGetInt(00, aLInt, i - 1))
- arSetInt(02, aLInt, i, _ina)
- // Remove consumed leg
- arRemove(aLFlt, aLInt, i - 1)
- // --------------------------------------------------------------
- // 06.01.07.04 TREND & BOS | Price Legs | Short Merge
- // --------------------------------------------------------------
- if globalTrendDirection != 0
- // Extra offset is nullified in case this candle is breaching BOS and isn't a manipulation
- // In this case we are merging right before a bos level search to include candles that would otherwise be excluded
- // Otherwise we don't merge bars within this offset, so they don't overwrite previous legs that could be used
- splitOffset = 1 + (executeBosLevelSearch
- and ((not checkConditionManipulationLong(tfSensitiveSettings, tHigh, tLow, tClose, barIndex, globalHB) and nextTrend == 1)
- or (not checkConditionManipulationShort(tfSensitiveSettings, tHigh, tLow, tClose, barIndex, globalLB) and nextTrend == -1)) ? 0 :
- bosIgnoreManipulationsAmount)
- // Combine all price legs that get overwritten by price legs after the offset (in case of manipulation)
- i = arSizeFlt(aSFlt)
- // Go on while there are at least two legs left to compare
- while i >= 2
- i := i - 1
- if splitOffset and arGetInt(00, aSInt, i) > barIndex - splitOffset
- continue
- // Attempt merger of current leg with the previous one
- prevH = arGetFlt(00, aSFlt, i - 1)
- curH = arGetFlt(00, aSFlt, i)
- // Only legs with a lower low should be kept alive
- if na(curH) or prevH > curH
- continue
- // Take its reverse low and close if higher
- arSetFlt(02, aSFlt, i, math.min(arGetFlt(02, aSFlt, i), arGetFlt(02, aSFlt, i - 1)))
- arSetFlt(03, aSFlt, i, math.min(arGetFlt(03, aSFlt, i), arGetFlt(03, aSFlt, i - 1)))
- // Take its local low if it's lower
- prevL = arGetFlt(01, aSFlt, i - 1)
- if prevL < arGetFlt(01, aSFlt, i)
- arSetFlt(01, aSFlt, i, prevL)
- arSetInt(01, aSInt, i, arGetInt(01, aSInt, i - 1))
- arSetInt(02, aSInt, i, _ina)
- // Remove consumed leg
- arRemove(aSFlt, aSInt, i - 1)
- // --------------------------------------------------------------
- // 06.01.07.05 TREND & BOS | Price Legs | Long Sideways
- // --------------------------------------------------------------
- // What part of candle should be inside for it to be considered inside
- candleTotal = 100
- candlePercent = array.get(tfSensitiveSettings, 34)
- candleRemainder = candleTotal - candlePercent
- // What percent of candle should the body be for it to be considered a full body candle
- candleFullBodyPercent = array.get(tfSensitiveSettings, 35)
- // If candle is full body, at least candlePercent of candle's body must be inside
- // If candle is not full body, at least candlePercent of whole candle must be inside
- if globalTrendDirection != 0
- maxI = arSizeFlt(aLFlt) - 1
- maxI := maxI < 0 ? na : maxI
- for i = 0 to maxI
- // If localLow is filled then this is a complete price leg
- localH = arGetFlt(00, aLFlt, i)
- localL = arGetFlt(01, aLFlt, i)
- if localL
- // If sidewaysL is na then sideways L needs recalculation
- if na(arGetInt(02, aLInt, i))
- sidewaysL = 0
- localClose = arGetFlt(02, aLFlt, i)
- localReverse = arGetFlt(03, aLFlt, i)
- startBar = arGetInt(01, aLInt, i)
- lookbackStart = barIndex - startBar
- lookbackEnd = barIndex - math.min(arGetInt(00, aLInt, i), math.max(nz(bosLB), nz(bosSB), nz(arGetLastBar(aLInt, i))))
- lookbackEnd := lookbackEnd <= lookbackStart ? na : lookbackEnd
- arSetInt(03, aLInt, i, lookbackStart)
- arSetInt(04, aLInt, i, 0)
- for j = lookbackStart to lookbackEnd
- max = array.get(aHigh, j)
- min = array.get(aLow, j)
- maxOC = array.get(aMaxOC, j)
- minOC = array.get(aMinOC, j)
- // if full body candle compare body
- if (maxOC - minOC) / (max - min) > candleFullBodyPercent / candleTotal
- max := maxOC
- min := minOC
- bodyLow = (max * candleRemainder + min * candlePercent) / candleTotal
- bodyHigh = (max * candlePercent + min * candleRemainder) / candleTotal
- if bodyLow > localH or bodyHigh < localL
- break
- curReverse = array.get(aLow, j)
- curClose = array.get(aMaxOC, j)
- if na(localClose) or curClose > localClose
- localClose := curClose
- if na(localReverse) or curReverse > localReverse
- localReverse := curReverse
- sidewaysL := j - lookbackStart
- arSetInt(02, aLInt, i, sidewaysL)
- arSetFlt(02, aLFlt, i, math.min(localH, localClose))
- arSetFlt(03, aLFlt, i, localReverse)
- // If still moving sideways R
- if arGetInt(04, aLInt, i) == 0
- max = tHigh
- min = tLow
- // if full body candle compare body
- if (tMaxOC - tMinOC) / (max - min) > candleFullBodyPercent / candleTotal
- max := tMaxOC
- min := tMinOC
- bodyHigh = (max * candlePercent + min * candleRemainder) / candleTotal
- if bodyHigh > localH
- arSetInt(04, aLInt, i, 1)
- else
- arSetInt(03, aLInt, i, arGetInt(03, aLInt, i) + 1)
- // --------------------------------------------------------------
- // 06.01.07.06 TREND & BOS | Price Legs | Short Sideways
- // --------------------------------------------------------------
- if globalTrendDirection != 0
- // Sideways update for short legs
- maxI = arSizeFlt(aSFlt) - 1
- maxI := maxI < 0 ? na : maxI
- for i = 0 to maxI
- // If localHigh is filled then this is a complete price leg
- localH = arGetFlt(00, aSFlt, i)
- localL = arGetFlt(01, aSFlt, i)
- if localH
- // If sidewaysL = na then sideways L needs recalculation
- if na(arGetInt(02, aSInt, i))
- sidewaysL = 0
- localClose = arGetFlt(02, aSFlt, i)
- localReverse = arGetFlt(03, aSFlt, i)
- startBar = arGetInt(00, aSInt, i)
- lookbackStart = barIndex - startBar
- lookbackEnd = barIndex - math.min(arGetInt(01, aSInt, i), math.max(nz(bosLB), nz(bosSB), nz(arGetLastBar(aSInt, i))))
- lookbackEnd := lookbackEnd <= lookbackStart ? na : lookbackEnd
- arSetInt(03, aSInt, i, lookbackStart)
- arSetInt(04, aSInt, i, 0)
- for j = lookbackStart to lookbackEnd
- max = array.get(aHigh, j)
- min = array.get(aLow, j)
- maxOC = array.get(aMaxOC, j)
- minOC = array.get(aMinOC, j)
- // if full body candle compare body
- if (maxOC - minOC) / (max - min) > candleFullBodyPercent / candleTotal
- max := maxOC
- min := minOC
- bodyLow = (max * candleRemainder + min * candlePercent) / candleTotal
- bodyHigh = (max * candlePercent + min * candleRemainder) / candleTotal
- if bodyHigh > localH or bodyLow < localL
- break
- curReverse = array.get(aHigh, j)
- curClose = array.get(aMinOC, j)
- if na(localClose) or curClose < localClose
- localClose := curClose
- if na(localReverse) or curReverse < localReverse
- localReverse := curReverse
- sidewaysL := j - lookbackStart
- arSetInt(02, aSInt, i, sidewaysL)
- arSetFlt(02, aSFlt, i, math.max(localL, localClose))
- arSetFlt(03, aSFlt, i, localReverse)
- // If still moving sideways R
- if arGetInt(04, aSInt, i) == 0
- max = tHigh
- min = tLow
- // if full body candle compare body
- if (tMaxOC - tMinOC) / (max - min) > candleFullBodyPercent / candleTotal
- max := tMaxOC
- min := tMinOC
- bodyLow = (max * candleRemainder + min * candlePercent) / candleTotal
- if bodyLow < localL
- arSetInt(04, aSInt, i, 1)
- else
- arSetInt(03, aSInt, i, arGetInt(03, aSInt, i) + 1)
- // --------------------------------------------------------------
- // 06.01.08 TREND & BOS | BOS Search
- // --------------------------------------------------------------
- // First check if we have to consume price leg we left behind
- // If that leg was overwritten we instead remove it completely
- breakoutPriceLegConsumption = false
- // Long check:
- if nextTrend == 1 and not executeBosLevelSearch
- // a) we have long price legs
- if array.size(aLFlt) > 0
- // Ensure price leg is full
- // b) [0] price leg low bar is on or before global high bar
- // c) [0] price leg low bar is far away from barIndex (user input value)
- localLowB = arGetInt(01, aLInt, 0)
- if arGetFlt(01, aLFlt, 0) and localLowB <= globalHB and barIndex - localLowB >= bosSameCandleLegConsumptionDelay
- localLow = array.get(aMinOC, barIndex - localLowB)
- consumed = false
- // d) price low never went below that price leg's body low (meaning, potential BOS was not consumed)
- for i = 0 to bosSameCandleLegConsumptionDelay - 1
- if array.get(aLow, i) <= localLow
- arRemove(aLFlt, aLInt, 0)
- if array.size(aLFlt) == 0
- arPush(aLFlt, aLInt)
- consumed := true
- break
- // Then do intermittent bos search to consume that leg
- if not consumed
- breakoutPriceLegConsumption := true
- // Short check:
- if nextTrend == -1 and not executeBosLevelSearch
- // a) we have short price legs
- if array.size(aSFlt) > 0
- // Ensure price leg is full
- // b) [0] price leg high bar is on or before global low bar
- // c) [0] price leg high bar is far away from barIndex (user input value)
- localHighB = arGetInt(00, aSInt, 0)
- if arGetFlt(00, aSFlt, 0) and localHighB <= globalLB and barIndex - localHighB >= bosSameCandleLegConsumptionDelay
- localHigh = array.get(aMaxOC, barIndex - localHighB)
- consumed = false
- // d) price high never went above that price leg's body high (meaning, potential BOS was not consumed)
- for i = 0 to bosSameCandleLegConsumptionDelay
- if array.get(aHigh, i) >= localHigh
- arRemove(aSFlt, aSInt, 0)
- if array.size(aSFlt) == 0
- arPush(aSFlt, aSInt)
- consumed := true
- break
- // Then do intermittent bos search to consume that leg
- if not consumed
- breakoutPriceLegConsumption := true
- // --------------------------------------------------------------
- // 06.01.08.01 TREND & BOS | Long BOS Search
- // --------------------------------------------------------------
- if nextTrend == 1 and (executeBosLevelSearch or breakoutPriceLegConsumption)
- // If we are doing bos search after trend break or to consume breakout price leg then this is a special case
- intermediarySearch = breakoutPriceLegConsumption or (bosBreached and executeGlobalTrendChange)
- // If intermittent search after bos break:
- // Split away legs that were achieved above current global high
- if intermediarySearch
- [_void, splitBar] = findGlobalHigh(globalH, globalHB, tHigh, barIndex, aSFlt, aSInt)
- // If consuming breakout legs, we must offset by user's input value, because we could have made closer global highs afterwards,
- // but still need to consume only the original leg
- if breakoutPriceLegConsumption
- splitBar := barIndex - bosSameCandleLegConsumptionDelay
- arSplit(aLFlt, aLInt, sFlt, sInt, true, splitBar)
- // If normal search:
- // Split away entry added in the last bars in case this candle is a manipulation
- else
- splitOffset = 1 + (checkConditionManipulationLong(tfSensitiveSettings, tHigh, tLow, tClose, barIndex, globalHB) ? bosIgnoreManipulationsAmount : 0)
- arSplit(aLFlt, aLInt, sFlt, sInt, true, barIndex - splitOffset)
- // Output where we're checking Long BOS
- if array.get(tfIndependentSettings, 06) and array.get(tfSensitiveSettings, 60)
- debugText("BL\nS" + (breakoutPriceLegConsumption ? "B" : intermediarySearch ? "I" : "") +
- "\nS"+str.tostring(arSizeFlt(sFlt))+"\nO"+str.tostring(arSizeFlt(aLFlt)), true)
- // Remember first and last that passed our conditions
- float firstPassedL = na
- int firstPassedLB = na
- float lastPassedL = na
- int lastPassedLB = na
- bool found = false
- // Iterate until we find suitable LocalH or exhaust all options
- while not found and array.size(aLFlt) > 0
- // Get next leg to examine
- [curLLocalH, curLLocalHB, curLLocalL, curLLocalLB, curLClose, curLReverse, curLSidewaysL, curLSidewaysR, curLSidewaysF] = arPop(aLFlt, aLInt)
- found := checkConditionGlobalChange(tfSensitiveSettings, tfIndependentSettings, aBarIndex, curLLocalLB,
- globalH, globalLC, curLLocalH, curLLocalL, curLClose, curLReverse, curLSidewaysL, curLSidewaysR, atr, true)
- if array.get(tfSensitiveSettings, 61)
- printPriceLeg(tfSensitiveSettings, tfIndependentSettings, aBarIndex,
- curLLocalHB, curLLocalH, curLLocalLB, curLLocalL, curLClose, curLReverse, curLSidewaysL, curLSidewaysR, true, found)
- // Record last passed High
- if found
- lastPassedL := curLLocalL
- lastPassedLB := curLLocalLB
- // Record first passed High
- if na(firstPassedL)
- firstPassedL := curLLocalL
- firstPassedLB := curLLocalLB
- // If we can look further, have price legs remaining, and have something to compare to
- aSize = arSizeFlt(aLFlt)
- if bosConsiderNextEnabled and aSize > 0 and firstPassedL
- // If next point is within range - clear found flag to allow while loop to continue
- // Also ensure next point isn't within old BOS in case we're breaching
- float nextH = na
- nextL = arGetFlt(01, aLFlt, aSize - 1)
- nextMinOC = array.get(aMinOC, barIndex - arGetInt(01, aLInt, aSize - 1))
- nextDiff = (globalH - nextL) / (globalH - (bosConsiderNextRecursive ? lastPassedL : firstPassedL)) - 1
- nextConsumed = false
- if bosConsiderNextConsumptionEnabled
- nextConsumed := (nextMinOC - lastPassedL) / (nextMinOC - nextL) > bosConsiderNextConsumptionThreshold / 100
- if not nextConsumed and nextDiff < bosConsiderNextDistanceThreshold / 100
- and (not bosBreached or checkConditionNewBosBeyondOld(tfSensitiveSettings, nextTrend, nextL, nextMinOC, bosLH, bosLL, bosSH, bosSL))
- found := false
- // If next point is not within range - break
- else
- break
- // If we still have a localL value here that means we found a suitable local low to use as a new BOS
- if lastPassedL
- // Relocate global low and BOS on it
- executeBosLevelUpdate := true
- globalL := lastPassedL
- globalLB := lastPassedLB
- globalLC := math.max(curNextLC, globalL)
- // Set classic BOS bar in case we have an unused price leg, and that BOS is outside selected BOS by at least the threshold
- if array.size(aLInt) > 0
- // First we pick the last price leg, which is by definition the highest
- classicB := arGetInt(01, aLInt, 0)
- classicMinOC = array.get(aMinOC, barIndex - classicB)
- classicDiff = 1 - classicMinOC / lastPassedL
- // Classic BOS' closer boundary must be away from algorithm-chosen BOS by at least this much, otherwise it's discarded
- if classicDiff <= array.get(tfSensitiveSettings, 01) / 100
- classicB := na
- arClear(aLFlt, aLInt, true, tfSensitiveSettings, tfIndependentSettings, aBarIndex, true)
- arSplit(sFlt, sInt, aLFlt, aLInt)
- if array.size(aLFlt) == 0
- arPush(aLFlt, aLInt)
- // If not doing intermittent search
- if not intermediarySearch
- // Update global high
- globalH := tHigh
- globalHB := barIndex
- // Waste short accumulated values
- curSNextClose := na
- curSNextReverse := na
- // If not in bos breached mode the next lowest close is reset here
- // Otherwise it can also be reset if we confirm trend change and establish new BOS later
- if not bosBreached
- curNextLC := tMinOC
- // --------------------------------------------------------------
- // 06.01.08.02 TREND & BOS | Short BOS Search
- // --------------------------------------------------------------
- else if nextTrend == -1 and (executeBosLevelSearch or breakoutPriceLegConsumption)
- // If we are doing bos search after trend break or to consume breakout price leg then this is a special case
- intermediarySearch = breakoutPriceLegConsumption or (bosBreached and executeGlobalTrendChange)
- // Split away legs that were achieved below current global low
- if intermediarySearch
- [_void, splitBar] = findGlobalLow(globalL, globalLB, tLow, barIndex, aLFlt, aLInt)
- // If consuming breakout legs, we must offset by user's input value, because we could have made closer global lows afterwards,
- // but still need to consume only the original leg
- if breakoutPriceLegConsumption
- splitBar := barIndex - bosSameCandleLegConsumptionDelay
- arSplit(aSFlt, aSInt, sFlt, sInt, false, splitBar)
- // If normal search:
- // split away entry added in the last bars in case this candle is a manipulation
- else
- splitOffset = 1 + (checkConditionManipulationShort(tfSensitiveSettings, tHigh, tLow, tClose, barIndex, globalLB) ? bosIgnoreManipulationsAmount : 0)
- arSplit(aSFlt, aSInt, sFlt, sInt, false, barIndex - splitOffset)
- // Output where we're checking Short BOS
- if array.get(tfIndependentSettings, 06) and array.get(tfSensitiveSettings, 60)
- debugText("BS\nS" + (breakoutPriceLegConsumption ? "B" : intermediarySearch ? "I" : "") +
- "\nS"+str.tostring(arSizeFlt(sFlt))+"\nO"+str.tostring(arSizeFlt(aSFlt)), true)
- // Remember first and last that passed our conditions
- float firstPassedH = na
- int firstPassedHB = na
- float lastPassedH = na
- int lastPassedHB = na
- bool found = false
- // Iterate until we find suitable LocalH or exhaust all options
- while not found and array.size(aSFlt) > 0
- // Get next leg to examine
- [curSLocalH, curSLocalHB, curSLocalL, curSLocalLB, curSClose, curSReverse, curSSidewaysL, curSSidewaysR, curSSidewaysF] = arPop(aSFlt, aSInt)
- found := checkConditionGlobalChange(tfSensitiveSettings, tfIndependentSettings, aBarIndex, curSLocalHB,
- globalHC, globalL, curSLocalH, curSLocalL, curSClose, curSReverse, curSSidewaysL, curSSidewaysR, atr, false)
- if array.get(tfSensitiveSettings, 61)
- printPriceLeg(tfSensitiveSettings, tfIndependentSettings, aBarIndex,
- curSLocalHB, curSLocalH, curSLocalLB, curSLocalL, curSClose, curSReverse, curSSidewaysL, curSSidewaysR, false, found)
- // Record last passed High
- if found
- lastPassedH := curSLocalH
- lastPassedHB := curSLocalHB
- // Record first passed High
- if na(firstPassedH)
- firstPassedH := curSLocalH
- firstPassedHB := curSLocalHB
- // If we can look further, have price legs remaining, and have something to compare to
- aSize = arSizeFlt(aSFlt)
- if bosConsiderNextEnabled and aSize > 0 and firstPassedH
- // If next point is within range - clear found flag to allow while loop to continue
- // Also ensure next point isn't within old BOS in case we're breaching
- float nextL = na
- nextH = arGetFlt(00, aSFlt, aSize - 1)
- nextMaxOC = array.get(aMaxOC, barIndex - arGetInt(00, aSInt, aSize - 1))
- nextDiff = (nextH - globalL) / ((bosConsiderNextRecursive ? lastPassedH : firstPassedH) - globalL) - 1
- nextConsumed = false
- if bosConsiderNextConsumptionEnabled
- nextConsumed := (lastPassedH - nextMaxOC) / (nextH - nextMaxOC) > bosConsiderNextConsumptionThreshold / 100
- if not nextConsumed and nextDiff < bosConsiderNextDistanceThreshold / 100
- and (not bosBreached or checkConditionNewBosBeyondOld(tfSensitiveSettings, nextTrend, nextH, nextMaxOC, bosLH, bosLL, bosSH, bosSL))
- found := false
- // If next point is not within range - break
- else
- break
- // If we still have a localL value here that means we found a suitable local high to use as a new BOS
- if lastPassedH
- // Relocate global high and place BOS on it
- executeBosLevelUpdate := true
- globalH := lastPassedH
- globalHB := lastPassedHB
- globalHC := math.min(curNextHC, globalH)
- // Set classic BOS bar in case we have an unused price leg, and that BOS is outside selected BOS by at least the threshold
- if array.size(aSInt) > 0
- // First we pick the last price leg, which is by definition the highest
- classicB := arGetInt(00, aSInt, 0)
- classicMaxOC = array.get(aMaxOC, barIndex - classicB)
- classicDiff = classicMaxOC / lastPassedH - 1
- // Classic BOS' closer boundary must be away from algorithm-chosen BOS by at least this much, otherwise it's discarded
- if classicDiff <= array.get(tfSensitiveSettings, 01) / 100
- classicB := na
- arClear(aSFlt, aSInt, false, tfSensitiveSettings, tfIndependentSettings, aBarIndex, true)
- arSplit(sFlt, sInt, aSFlt, aSInt)
- if array.size(aSFlt) == 0
- arPush(aSFlt, aSInt)
- // If not doing intermittent search
- if not intermediarySearch
- // Update global low
- globalL := tLow
- globalLB := barIndex
- // Waste long accumulated values
- curLNextClose := na
- curLNextReverse := na
- // If not in bos breached mode the next highest close is reset here
- // Otherwise it can also be reset if we confirm trend change and establish new BOS later
- if not bosBreached
- curNextHC := tMaxOC
- // --------------------------------------------------------------
- // 06.01.09 TREND & BOS | TREND CHANGE
- // --------------------------------------------------------------
- if executeGlobalTrendChange
- // Global trend changed to SHORT
- if globalTrendDirection == 1
- globalTrendDirection := -1
- [g_l, g_lb] = findGlobalLow(globalL, globalLB, tLow, barIndex, aLFlt, aLInt)
- globalL := g_l
- globalLB := g_lb
- // Global trend changed to LONG
- else
- globalTrendDirection := 1
- [g_h, g_hb] = findGlobalHigh(globalH, globalHB, tHigh, barIndex, aSFlt, aSInt)
- globalH := g_h
- globalHB := g_hb
- // --------------------------------------------------------------
- // 06.01.10 BOS LEVEL UPDATE
- // --------------------------------------------------------------
- // First confirm BOS breach if breached, otherwise no BOS Update occurs
- if executeBosLevelUpdate
- if bosBreached
- highLow = globalTrendDirection == 1 ? globalL : globalH
- openClose = globalTrendDirection == 1 ? array.get(aMinOC, barIndex - globalLB) : array.get(aMaxOC, barIndex - globalHB)
- if checkConditionNewBosBeyondOld(tfSensitiveSettings, globalTrendDirection, highLow, openClose, bosLH, bosLL, bosSH, bosSL)
- bosBreached := false
- // --------------------------------------------------------------
- // 06.01.10.01 BOS LEVEL UPDATE | LONG
- // --------------------------------------------------------------
- if globalTrendDirection == 1 and not bosBreached
- // Waste short entries
- arClear(aSFlt, aSInt, false, tfSensitiveSettings, tfIndependentSettings, aBarIndex, not array.get(tfIndependentSettings, 05))
- arPush(aSFlt, aSInt)
- // Waste accumulated next lowest close
- curNextLC := tMinOC
- // Change BOS
- if true
- bosSB := globalLB
- lookbackBos = barIndex - bosSB
- bosSH := array.get(aMinOC, lookbackBos)
- bosSL := array.get(aLow, lookbackBos)
- // If current candle completely consumed BOS then ignore it
- beginI = tMinOC <= bosSL ? 1 : 0
- lookbackBos := lookbackBos <= beginI ? na : lookbackBos
- // Look ahead to narrow down the volume level range
- for i = beginI to lookbackBos - 1
- bosSH := math.min(bosSH, array.get(aMinOC, i))
- // Immediately check for testing
- bosTesting := (tLow < bosSH or array.get(aLow, 1) < bosSH)
- // Change CBOS
- if not na(classicB)
- cbosSB := classicB
- lookbackBos = barIndex - cbosSB
- cbosSH := array.get(aMinOC, lookbackBos)
- cbosSL := array.get(aLow, lookbackBos)
- // If current candle completely consumed BOS then ignore it
- beginI = tMinOC <= cbosSL ? 1 : 0
- lookbackBos := lookbackBos <= beginI ? na : lookbackBos
- // Look ahead to narrow down the volume level range
- for i = beginI to lookbackBos - 1
- cbosSH := math.min(cbosSH, array.get(aMinOC, i))
- bosLH := na
- bosLL := na
- cbosLH := na
- cbosLL := na
- // --------------------------------------------------------------
- // 06.01.10.02 BOS LEVEL UPDATE | SHORT
- // --------------------------------------------------------------
- if globalTrendDirection == -1 and not bosBreached
- // Waste long entries
- arClear(aLFlt, aLInt, true, tfSensitiveSettings, tfIndependentSettings, aBarIndex, not array.get(tfIndependentSettings, 05))
- arPush(aLFlt, aLInt)
- // Waste accumulated next highest close
- curNextHC := tMaxOC
- // Change BOS
- if true
- bosLB := globalHB
- lookbackBos = barIndex - bosLB
- bosLL := array.get(aMaxOC, lookbackBos)
- bosLH := array.get(aHigh, lookbackBos)
- // If current candle completely consumed BOS then ignore it
- beginI = tMaxOC >= bosLH ? 1 : 0
- lookbackBos := lookbackBos <= beginI ? na : lookbackBos
- // Look ahead to narrow down the volume level range
- for i = beginI to lookbackBos - 1
- bosLL:= math.max(bosLL, array.get(aMaxOC, i))
- // Immediately check for testing
- bosTesting := tHigh > bosLL or array.get(aHigh, 1) > bosLL
- // Change CBOS
- if not na(classicB)
- cbosLB := classicB
- lookbackBos = barIndex - cbosLB
- cbosLL := array.get(aMaxOC, lookbackBos)
- cbosLH := array.get(aHigh, lookbackBos)
- // If current candle completely consumed BOS then ignore it
- beginI = tMaxOC >= cbosLH ? 1 : 0
- lookbackBos := lookbackBos <= beginI ? na : lookbackBos
- // Look ahead to narrow down the volume level range
- for i = beginI to lookbackBos - 1
- cbosLL:= math.max(cbosLL, array.get(aMaxOC, i))
- bosSH := na
- bosSL := na
- cbosSH := na
- cbosSL := na
- // --------------------------------------------------------------
- // 06.01.11 TRIM ARRAYS
- // --------------------------------------------------------------
- if not array.get(tfIndependentSettings, 01)
- maxLookback = math.max(2, barIndex - math.min(bosLB, bosSB)) + 1
- while array.size(aHigh) > maxLookback
- array.pop(aHigh)
- array.pop(aLow)
- array.pop(aOpen)
- array.pop(aClose)
- array.pop(aMaxOC)
- array.pop(aMinOC)
- array.pop(aPivotH)
- array.pop(aPivotL)
- // --------------------------------------------------------------
- // 06.01.12 LAST BAR CLEANING
- // --------------------------------------------------------------
- // Cleaning house on last bar
- if finalize
- // Clear arrays so we can see their contents
- arInit(aLFlt, aLInt, aSFlt, aSInt, tfSensitiveSettings, tfIndependentSettings, aBarIndex, true)
- // --------------------------------------------------------------
- // 06.01.13 FINISHED, PACK DATA
- // --------------------------------------------------------------
- arStateSet(aStateInt, aStateBool, globalTrendDirection, bosTesting, bosBreached, bosBreachCandles)
- arValuesSet(aValuesFlt, aValuesInt, priorH, priorHB, priorL, priorLB, globalH, globalHB, globalL, globalLB,
- globalHC, globalLC, curNextHC, curNextLC,
- curLNextClose, curLNextReverse, curSNextClose, curSNextReverse,
- bosLH, bosLL, bosLB, bosSH, bosSL, bosSB,
- cbosLH, cbosLL, cbosLB, cbosSH, cbosSL, cbosSB)
- // --------------------------------------------------------------
- // 06.01 END TREND & BOS DETERMINATION ALGORITHM
- // --------------------------------------------------------------
- if globalTrendDirection != 0
- if globalTrendDirection == -1 and not bosBreached
- // Waste long entries
- arClear(aLFlt, aLInt, true, tfSensitiveSettings, tfIndependentSettings, aBarIndex, not array.get(tfIndependentSettings, 05))
- arPush(aLFlt, aLInt)
- // Waste accumulated next highest close
- curNextHC := tMaxOC
- // Change BOS
- if true
- bosLB := globalHB
- lookbackBos = barIndex - bosLB
- bosLL := array.get(aMaxOC, lookbackBos)
- bosLH := array.get(aHigh, lookbackBos)
- // If current candle completely consumed BOS then ignore it
- beginI = tMaxOC >= bosLH ? 1 : 0
- lookbackBos := lookbackBos <= beginI ? na : lookbackBos
- // Look ahead to narrow down the volume level range
- for i = beginI to lookbackBos - 1
- bosLL:= math.max(bosLL, array.get(aMaxOC, i))
- // Immediately check for testing
- bosTesting := tHigh > bosLL or array.get(aHigh, 1) > bosLL
- // Change CBOS
- if not na(classicB)
- cbosLB := classicB
- lookbackBos = barIndex - cbosLB
- cbosLL := array.get(aMaxOC, lookbackBos)
- cbosLH := array.get(aHigh, lookbackBos)
- // If current candle completely consumed BOS then ignore it
- beginI = tMaxOC >= cbosLH ? 1 : 0
- lookbackBos := lookbackBos <= beginI ? na : lookbackBos
- // Look ahead to narrow down the volume level range
- for i = beginI to lookbackBos - 1
- cbosLL:= math.max(cbosLL, array.get(aMaxOC, i))
- bosSH := na
- bosSL := na
- cbosSH := na
- cbosSL := na
- if globalTrendDirection != 0
- if globalTrendDirection == -1 and not bosBreached
- // Waste long entries
- arClear(aLFlt, aLInt, true, tfSensitiveSettings, tfIndependentSettings, aBarIndex, not array.get(tfIndependentSettings, 05))
- arPush(aLFlt, aLInt)
- // Waste accumulated next highest close
- curNextHC := tMaxOC
- // Change BOS
- if true
- bosLB := globalHB
- lookbackBos = barIndex - bosLB
- bosLL := array.get(aMaxOC, lookbackBos)
- bosLH := array.get(aHigh, lookbackBos)
- // If current candle completely consumed BOS then ignore it
- beginI = tMaxOC >= bosLH ? 1 : 0
- lookbackBos := lookbackBos <= beginI ? na : lookbackBos
- // Look ahead to narrow down the volume level range
- for i = beginI to lookbackBos - 1
- bosLL:= math.max(bosLL, array.get(aMaxOC, i))
- // Immediately check for testing
- bosTesting := tHigh > bosLL or array.get(aHigh, 1) > bosLL
- // Change CBOS
- if not na(classicB)
- cbosLB := classicB
- lookbackBos = barIndex - cbosLB
- cbosLL := array.get(aMaxOC, lookbackBos)
- cbosLH := array.get(aHigh, lookbackBos)
- // If current candle completely consumed BOS then ignore it
- beginI = tMaxOC >= cbosLH ? 1 : 0
- lookbackBos := lookbackBos <= beginI ? na : lookbackBos
- // Look ahead to narrow down the volume level range
- for i = beginI to lookbackBos - 1
- cbosLL:= math.max(cbosLL, array.get(aMaxOC, i))
- bosSH := na
- bosSL := na
- cbosSH := na
- cbosSL := na
- if globalTrendDirection != 0
- if globalTrendDirection == -1 and not bosBreached
- // Waste long entries
- arClear(aLFlt, aLInt, true, tfSensitiveSettings, tfIndependentSettings, aBarIndex, not array.get(tfIndependentSettings, 05))
- arPush(aLFlt, aLInt)
- // Waste accumulated next highest close
- curNextHC := tMaxOC
- // Change BOS
- if true
- bosLB := globalHB
- lookbackBos = barIndex - bosLB
- bosLL := array.get(aMaxOC, lookbackBos)
- bosLH := array.get(aHigh, lookbackBos)
- // If current candle completely consumed BOS then ignore it
- beginI = tMaxOC >= bosLH ? 1 : 0
- lookbackBos := lookbackBos <= beginI ? na : lookbackBos
- // Look ahead to narrow down the volume level range
- for i = beginI to lookbackBos - 1
- bosLL:= math.max(bosLL, array.get(aMaxOC, i))
- // Immediately check for testing
- bosTesting := tHigh > bosLL or array.get(aHigh, 1) > bosLL
- // Change CBOS
- if not na(classicB)
- cbosLB := classicB
- lookbackBos = barIndex - cbosLB
- cbosLL := array.get(aMaxOC, lookbackBos)
- cbosLH := array.get(aHigh, lookbackBos)
- // If current candle completely consumed BOS then ignore it
- beginI = tMaxOC >= cbosLH ? 1 : 0
- lookbackBos := lookbackBos <= beginI ? na : lookbackBos
- // Look ahead to narrow down the volume level range
- for i = beginI to lookbackBos - 1
- cbosLL:= math.max(cbosLL, array.get(aMaxOC, i))
- bosSH := na
- bosSL := na
- cbosSH := na
- cbosSL := na
- // --------------------------------------------------------------
- // 06.02 ALGORITHM EXECUTION
- // --------------------------------------------------------------
- // This condition only processes selected bars (for debug purposes) an doesn't try to acquire any longer
- inRange = not (bar_index < DBG_FirstBar or bar_index > DBG_LastBar)
- if inRange
- if initialCtfTrendDirection != 0
- array.set(carStateInt, 0, initialCtfTrendDirection)
- initialCtfTrendDirection := 0
- algoTrendAndBosTick(bar_index, cBarIndex,
- carHigh, carLow, carOpen, carClose, carMaxOC, carMinOC, carPivotH, carPivotL,
- carLFlt, carLInt, carSFlt, carSInt,
- ctfSensitiveSettings, tfIndependentSettings, carStateInt, carStateBool, carValuesFlt, carValuesInt,
- barstate.islastconfirmedhistory or bar_index == DBG_LastBar)
- // HTF Trend, Called every tick there was new data, and once to finalize
- if inRange and calculateHtfTrend and htfBarIndex >=0 and (newHtfDataThisTick or barstate.islastconfirmedhistory)
- if initialHtfTrendDirection != 0
- array.set(harStateInt, 0, initialHtfTrendDirection)
- initialHtfTrendDirection := 0
- algoTrendAndBosTick(htfBarIndex, harBarIndex,
- harHigh, harLow, harOpen, harClose, harMaxOC, harMinOC, harPivotH, harPivotL,
- harLFlt, harLInt, harSFlt, harSInt,
- htfSensitiveSettings, tfIndependentSettings, harStateInt, harStateBool, harValuesFlt, harValuesInt,
- barstate.islastconfirmedhistory or bar_index == DBG_LastBar)
- // Discard trend on last bar if processing select bars
- if bar_index == DBG_LastBar + 1
- array.set(carStateInt, 0, 0)
- array.set(harStateInt, 0, 0)
- // --------------------------------------------------------------
- // 06.03 POST-PROCESSING
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 06.03.01 GET DATA
- // --------------------------------------------------------------
- [globalTrendDirection, bosTesting, bosBreached, bosBreachCandles] = arStateGet(carStateInt, carStateBool)
- [priorH, priorHB, priorL, priorLB, globalH, globalHB, globalL, globalLB,
- globalHC, globalLC, curNextHC, curNextLC,
- curLNextClose, curLNextReverse, curSNextClose, curSNextReverse,
- bosLH, bosLL, bosLB, bosSH, bosSL, bosSB,
- cbosLH, cbosLL, cbosLB, cbosSH, cbosSL, cbosSB] = arValuesGet(carValuesFlt, carValuesInt)
- [htfglobalTrendDirection, htfbosTesting, htfbosBreached, htfbosBreachCandles] = arStateGet(harStateInt, harStateBool)
- [htfpriorH, _htfpriorHB, htfpriorL, _htfpriorLB, htfglobalH, _htfglobalHB, htfglobalL, _htfglobalLB,
- _htfGlobalHC, _htfGlobalLC, _htfCurNextHC, _htfCurNextLC,
- htfcurLNextClose, htfcurLNextReverse, htfcurSNextClose, htfcurSNextReverse,
- htfbosLH, htfbosLL, _htfbosLB, htfbosSH, htfbosSL, _htfbosSB,
- htfcbosLH, htfcbosLL, _htfcbosLB, htfcbosSH, htfcbosSL, _htfcbosSB] = arValuesGet(harValuesFlt, harValuesInt)
- htfglobalHB = array.get(harBarIndex, _htfglobalHB)
- htfglobalLB = array.get(harBarIndex, _htfglobalLB)
- htfbosLB = array.get(harBarIndex, _htfbosLB)
- htfbosSB = array.get(harBarIndex, _htfbosSB)
- htfcbosLB = array.get(harBarIndex, _htfcbosLB)
- htfcbosSB = array.get(harBarIndex, _htfcbosSB)
- priorTrend = globalTrendDirection == 0 ? 0 : bosBreached ? -globalTrendDirection : globalTrendDirection
- htfpriorTrend = htfglobalTrendDirection == 0 ? 0 : htfbosBreached ? -htfglobalTrendDirection : htfglobalTrendDirection
- // --------------------------------------------------------------
- // 06.03.02 TRIGGERS, ALERTS, EVENTS
- // --------------------------------------------------------------
- eventTrendBreak = bosBreached == true and bosBreached[1] == false
- eventTrendReversalConfirmed = bosBreached == false and bosBreached[1] == true and globalTrendDirection == globalTrendDirection[1]
- eventTrendResume = bosBreached == false and bosBreached[1] == true and globalTrendDirection != globalTrendDirection[1]
- htfeventTrendBreak = htfbosBreached == true and htfbosBreached[1] == false
- htfeventTrendReversalConfirmed = htfbosBreached == false and htfbosBreached[1] == true and htfglobalTrendDirection == htfglobalTrendDirection[1]
- htfeventTrendResume = htfbosBreached == false and htfbosBreached[1] == true and htfglobalTrendDirection != htfglobalTrendDirection[1]
- // --------------------------------------------------------------
- // 07 OUTPUT
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 07.01 OUTPUT: DEBUG OUTPUT PLOTS
- // --------------------------------------------------------------
- float outhtfOpen = na
- float outhtfHigh = na
- float outhtfLow = na
- float outhtfClose = na
- float outhtfPivotHigh = na
- float outhtfPivotLow = na
- if array.size(harHigh) > 0 and newHtfDataThisTick
- //debugText(bar_index)
- if DBG_ShowHTFDebugPlots and DBG_DebugEnabled
- outhtfOpen := array.get(harOpen, 0)
- outhtfHigh := array.get(harHigh, 0)
- outhtfLow := array.get(harLow, 0)
- outhtfClose := array.get(harClose, 0)
- if DBG_ShowHTFDebugPlots and DBG_DebugEnabled or showPPEnabled and showPPHtf
- outhtfPivotHigh := na(array.get(harPivotH, 0)) ? array.get(harPivotH, 1) : na
- outhtfPivotLow := na(array.get(harPivotL, 0)) ? array.get(harPivotL, 1) : na
- // HTF Plots
- plot(outhtfOpen, "HTF Open", color.purple, 2, offset = -htfOffset)
- plot(outhtfHigh, "HTF High", color.fuchsia, 2, offset = -htfOffset)
- plot(outhtfLow, "HTF Low", color.fuchsia, 2, offset = -htfOffset)
- plot(outhtfClose, "HTF Close", color.purple, 2, offset = -htfOffset)
- plotshape(DBG_ShowHTFDebugPlots ? outhtfPivotHigh : na, "HTF Pivot H", shape.xcross, location.absolute, color.fuchsia,
- -htfOffset - htfSidewaysMultiplier, size = size.small)
- plotshape(DBG_ShowHTFDebugPlots ? outhtfPivotLow : na, "HTF Pivot L", shape.xcross, location.absolute, color.fuchsia,
- -htfOffset - htfSidewaysMultiplier, size = size.small)
- // HLC / NHLC
- plot(DBG_DebugEnabled and DBG_ShowHLCDebugPlots and globalTrendDirection == 1 ? globalHC : na, "globalHC", color.red, linewidth = 3)
- plot(DBG_DebugEnabled and DBG_ShowHLCDebugPlots and globalTrendDirection == -1 ? globalLC : na, "globalLC", color.green, linewidth = 3)
- // Maybe this was better? But uses x2 plots since color not const
- // plot(DBG_DebugEnabled and DBG_ShowHLCDebugPlots ? globalHC : na, "globalHC", globalTrendDirection == 1 ? na : color.red, linewidth = 3)
- // plot(DBG_DebugEnabled and DBG_ShowHLCDebugPlots ? globalLC : na, "globalLC", globalTrendDirection == -1 ? na : color.green, linewidth = 3)
- plot(DBG_DebugEnabled and DBG_ShowHLCDebugPlots ? curNextHC : na, "curNextHC", color.new(color.red, 60), linewidth = 2)
- plot(DBG_DebugEnabled and DBG_ShowHLCDebugPlots ? curNextLC : na, "curNextLC", color.new(color.green, 60), linewidth = 2)
- // --------------------------------------------------------------
- // 07.02 OUTPUT: PIVOT POINTS
- // --------------------------------------------------------------
- plotshape(showPPEnabled and showPPCtf and not cPivotH ? cPivotH[1] : na, 'CTF High', shape.triangledown,
- location.abovebar, color.new(color.green,50), -ctfOffset - 1, "H", color.new(color.green,50))
- plotshape(showPPEnabled and showPPCtf and not cPivotL ? cPivotL[1] : na, 'CTF Low', shape.triangleup,
- location.belowbar, color.new(color.red,50), -ctfOffset - 1, "L", color.new(color.red,50))
- plotshape(showPPEnabled and showPPHtf ? outhtfPivotHigh : na, 'HTF High', shape.triangledown,
- location.abovebar, color.new(color.green,30), -htfOffset - htfSidewaysMultiplier, '[H]', color.new(color.green,30))
- plotshape(showPPEnabled and showPPHtf ? outhtfPivotLow : na, 'HTF Low', shape.triangleup,
- location.belowbar, color.new(color.red,30), -htfOffset - htfSidewaysMultiplier, '[L]', color.new(color.red,30))
- // --------------------------------------------------------------
- // 07.03 OUTPUT: BOS
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 07.03.01 OUTPUT: CTF BOS
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 07.03.01.01 OUTPUT: CTF BOS | LONG
- // --------------------------------------------------------------
- // CTF Long BOS Colors
- colorBosLongLineMainNormal = color.new(colorBosLongMain, ctfBosT3)
- colorBosLongLineMainTesting = color.new(colorBosLongMain, ctfBosT4)
- colorBosLongLineMainBreached = color.new(colorBosLongMain, ctfBosT5)
- colorBosLongLineAuxNormal = color.new(colorBosLongAux, ctfBosT2)
- colorBosLongLineAuxTesting = color.new(colorBosLongAux, ctfBosT3)
- colorBosLongLineAuxBreached = color.new(colorBosLongMain, ctfBosT3)
- colorBosLongBgNormal = color.new(colorBosLongAux, ctfBosT1)
- colorBosLongBgTesting = color.new(colorBosLongAux, ctfBosT2)
- colorBosLongBgBreached = color.new(colorBosLongMain, ctfBosT2)
- // CTF Long BOS Draw
- drawLongBos = showBosEnabled and priorTrend == -1
- longBosUnchanged = bosLH == bosLH[1] and bosLL == bosLL[1]
- drawLongBosRegular = drawLongBos and longBosUnchanged
- drawLongBosOrigin = drawLongBos and not longBosUnchanged
- colorBosLongLineMain = not drawLongBosRegular or not showBosCtfMainLine ? na :
- bosTesting ? colorBosLongLineMainTesting : bosBreached ? colorBosLongLineMainBreached : colorBosLongLineMainNormal
- colorBosLongLineAux = not drawLongBosRegular or not showBosCtfAuxLine? na :
- bosTesting ? colorBosLongLineAuxTesting : bosBreached ? colorBosLongLineAuxBreached : colorBosLongLineAuxNormal
- colorBosLongFill = not drawLongBosRegular or not showBosCtfFill ? na :
- bosTesting ? colorBosLongBgTesting : bosBreached ? colorBosLongBgBreached : colorBosLongBgNormal
- if drawLongBosOrigin and bosLH
- if showBosCtfOriginMainLine
- line.new(bosLB - ctfOffset, bosLH, bar_index - ctfOffset, bosLH, color = colorBosLongLineMainNormal, width = showBosCtfWidthMain)
- if showBosCtfOriginAuxLine
- line.new(bosLB - ctfOffset, bosLL, bar_index - ctfOffset, bosLL, color = colorBosLongLineAuxNormal, width = showBosCtfWidthAux)
- if showBosCtfOriginFill
- box.new(bosLB - ctfOffset, bosLH, bar_index - ctfOffset, bosLL, na, bgcolor = colorBosLongBgNormal)
- // --------------------------------------------------------------
- // 07.03.01.02 OUTPUT: CTF BOS | SHORT
- // --------------------------------------------------------------
- // CTF Short BOS Colors
- colorBosShortLineMainNormal = color.new(colorBosShortMain, ctfBosT3)
- colorBosShortLineMainTesting = color.new(colorBosShortMain, ctfBosT4)
- colorBosShortLineMainBreached = color.new(colorBosShortMain, ctfBosT5)
- colorBosShortLineAuxNormal = color.new(colorBosShortAux, ctfBosT2)
- colorBosShortLineAuxTesting = color.new(colorBosShortAux, ctfBosT3)
- colorBosShortLineAuxBreached = color.new(colorBosShortMain, ctfBosT3)
- colorBosShortBgNormal = color.new(colorBosShortAux, ctfBosT1)
- colorBosShortBgTesting = color.new(colorBosShortAux, ctfBosT2)
- colorBosShortBgBreached = color.new(colorBosShortMain, ctfBosT2)
- // CTF Short BOS Draw
- drawShortBos = showBosEnabled and priorTrend == 1
- shortBosUnchanged = bosSH == bosSH[1] and bosSL == bosSL[1]
- drawShortBosRegular = drawShortBos and shortBosUnchanged
- drawShortBosOrigin = drawShortBos and not shortBosUnchanged
- colorBosShortLineAux = not drawShortBosRegular or not showBosCtfAuxLine? na :
- bosTesting ? colorBosShortLineAuxTesting : bosBreached ? colorBosShortLineAuxBreached : colorBosShortLineAuxNormal
- colorBosShortLineMain = not drawShortBosRegular or not showBosCtfMainLine? na :
- bosTesting ? colorBosShortLineMainTesting : bosBreached ? colorBosShortLineMainBreached : colorBosShortLineMainNormal
- colorBosShortFill = not drawShortBosRegular or not showBosCtfFill? na :
- bosTesting ? colorBosShortBgTesting : bosBreached ? colorBosShortBgBreached : colorBosShortBgNormal
- if drawShortBosOrigin and bosSH
- if showBosCtfOriginAuxLine
- line.new(bosSB - ctfOffset, bosSH, bar_index - ctfOffset, bosSH, color = colorBosShortLineAuxNormal, width = showBosCtfWidthAux)
- if showBosCtfOriginMainLine
- line.new(bosSB - ctfOffset, bosSL, bar_index - ctfOffset, bosSL, color = colorBosShortLineMainNormal, width = showBosCtfWidthMain)
- if showBosCtfOriginFill
- box.new(bosSB - ctfOffset, bosSH, bar_index - ctfOffset, bosSL, na, bgcolor = colorBosShortBgNormal)
- // --------------------------------------------------------------
- // 07.03.01.03 OUTPUT: CTF BOS | PLOT
- // --------------------------------------------------------------
- ctfblh = plot(priorTrend == 1 ? bosSL : bosLH, "CTF BOS Main", priorTrend == 1 ? colorBosShortLineMain : colorBosLongLineMain, showBosCtfWidthMain,
- plot.style_line, offset = -ctfOffset, editable = false, display = display.pane + display.data_window + display.status_line)
- ctfbll = plot(priorTrend == 1 ? bosSH : bosLL, "CTF BOS Aux", priorTrend == 1 ? colorBosShortLineAux : colorBosLongLineAux, showBosCtfWidthAux,
- plot.style_line, offset = -ctfOffset, editable = false, display = display.pane + display.data_window + display.status_line)
- fill(ctfblh, ctfbll, priorTrend == 1 ? colorBosShortFill : colorBosLongFill , "CTF BOS Fill", editable = false)
- // --------------------------------------------------------------
- // 07.03.02 OUTPUT: CTF CLASSIC BOS
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 07.03.02.01 OUTPUT: CTF CLASSIC BOS | LONG
- // --------------------------------------------------------------
- // CTF Long Classic BOS Colors
- colorCBosLongLineMainNormal = color.new(colorCBosLongMain, ctfCBosT3)
- colorCBosLongLineAuxNormal = color.new(colorCBosLongAux, ctfCBosT2)
- colorCBosLongBgNormal = color.new(colorCBosLongAux, ctfCBosT1)
- // CTF Long Classic BOS Draw
- var float hiddenLH = na
- if showCBosHideCollision and cbosLH == htfbosLH
- hiddenLH := htfbosLH
- drawLongCBos = showBosEnabled and showCBosEnabled and priorTrend == -1 and (na(hiddenLH) or cbosLH != hiddenLH)
- longCBosUnchanged = cbosLH == cbosLH[1] and cbosLL == cbosLL[1]
- drawLongCBosRegular = drawLongCBos and longCBosUnchanged
- drawLongCBosOrigin = drawLongCBos and not longCBosUnchanged
- colorCBosLongLineMain = not drawLongCBosRegular or not showCBosCtfAuxLine ? na : colorCBosLongLineMainNormal
- colorCBosLongLineAux = not drawLongCBosRegular or not showCBosCtfAuxLine ? na : colorCBosLongLineAuxNormal
- colorCBosLongFill = not drawLongCBosRegular or not showCBosCtfFill ? na : colorCBosLongBgNormal
- if drawLongCBosOrigin and cbosLH
- if showCBosCtfOriginMainLine
- line.new(cbosLB - ctfOffset, cbosLH, bar_index - ctfOffset, cbosLH, color = colorCBosLongLineMainNormal, width = showCBosCtfWidthMain)
- if showCBosCtfOriginAuxLine
- line.new(cbosLB - ctfOffset, cbosLL, bar_index - ctfOffset, cbosLL, color = colorCBosLongLineAuxNormal, width = showCBosCtfWidthAux)
- if showCBosCtfOriginFill
- box.new(cbosLB - ctfOffset, cbosLH, bar_index - ctfOffset, cbosLL, na, bgcolor = colorCBosLongBgNormal)
- // --------------------------------------------------------------
- // 07.03.02.02 OUTPUT: CTF CLASSIC BOS | SHORT
- // --------------------------------------------------------------
- // CTF Short Classic BOS Colors
- colorCBosShortLineMainNormal = color.new(colorCBosShortMain, ctfCBosT3)
- colorCBosShortLineAuxNormal = color.new(colorCBosShortAux, ctfCBosT2)
- colorCBosShortBgNormal = color.new(colorCBosShortAux, ctfCBosT1)
- // CTF Short Classic BOS Draw
- var float hiddenSL = na
- if showCBosHideCollision and cbosSL == htfbosSL
- hiddenSL := htfbosSL
- drawShortCBos = showBosEnabled and showCBosEnabled and priorTrend == 1 and (na(hiddenSL) or cbosSL != hiddenSL)
- shortCBosUnchanged = cbosSH == cbosSH[1] and cbosSL == cbosSL[1]
- drawShortCBosRegular = drawShortCBos and shortCBosUnchanged
- drawShortCBosOrigin = drawShortCBos and not shortCBosUnchanged
- colorCBosShortLineAux = not drawShortCBosRegular or not showCBosCtfAuxLine ? na : colorCBosShortLineAuxNormal
- colorCBosShortLineMain = not drawShortCBosRegular or not showCBosCtfAuxLine ? na : colorCBosShortLineMainNormal
- colorCBosShortFill = not drawShortCBosRegular or not showCBosCtfFill? na : colorCBosShortBgNormal
- if drawShortCBosOrigin and cbosSH
- if showCBosCtfOriginAuxLine
- line.new(cbosSB - ctfOffset, cbosSH, bar_index - ctfOffset, cbosSH, color = colorCBosShortLineAuxNormal, width = showCBosCtfWidthAux)
- if showCBosCtfOriginMainLine
- line.new(cbosSB - ctfOffset, cbosSL, bar_index - ctfOffset, cbosSL, color = colorCBosShortLineMainNormal, width = showCBosCtfWidthMain)
- if showCBosCtfOriginFill
- box.new(cbosSB - ctfOffset, cbosSH, bar_index - ctfOffset, cbosSL, na, bgcolor = colorCBosShortBgNormal)
- // --------------------------------------------------------------
- // 07.03.02.03 OUTPUT: CTF CLASSIC BOS | PLOT
- // --------------------------------------------------------------
- ctfcblh = plot(priorTrend == 1 ? cbosSL : cbosLH, "CTF CBOS Main", priorTrend == 1 ? colorCBosShortLineMain : colorCBosLongLineMain, showCBosCtfWidthMain,
- plot.style_line, offset = -ctfOffset, editable = false, display = display.pane + display.data_window + display.status_line)
- ctfcbll = plot(priorTrend == 1 ? cbosSH : cbosLL, "CTF CBOS Aux", priorTrend == 1 ? colorCBosShortLineAux : colorCBosLongLineAux, showCBosCtfWidthAux,
- plot.style_line, offset = -ctfOffset, editable = false, display = display.pane + display.data_window + display.status_line)
- fill(ctfcblh, ctfcbll, priorTrend == 1 ? colorCBosShortFill : colorCBosLongFill, "CTF CBOS Fill", editable = false)
- // --------------------------------------------------------------
- // 07.03.03 OUTPUT: HTF BOS
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 07.03.03.01 OUTPUT: HTF BOS | LONG
- // --------------------------------------------------------------
- // HTF Long BOS Colors
- htfcolorBosLongLineMainNormal = color.new(htfcolorBosLongMain, htfBosT3)
- htfcolorBosLongLineMainTesting = color.new(htfcolorBosLongMain, htfBosT4)
- htfcolorBosLongLineMainBreached = color.new(htfcolorBosLongMain, htfBosT5)
- htfcolorBosLongLineAuxNormal = color.new(htfcolorBosLongAux, htfBosT2)
- htfcolorBosLongLineAuxTesting = color.new(htfcolorBosLongAux, htfBosT3)
- htfcolorBosLongLineAuxBreached = color.new(htfcolorBosLongMain, htfBosT2)
- htfcolorBosLongBgNormal = color.new(htfcolorBosLongAux, htfBosT1)
- htfcolorBosLongBgTesting = color.new(htfcolorBosLongAux, htfBosT2)
- htfcolorBosLongBgBreached = color.new(htfcolorBosLongMain, htfBosT2)
- // HTF Long BOS Draw
- htfdrawLongBos = showBosEnabled and htfpriorTrend == -1
- htflongBosUnchanged = htfbosLH == htfbosLH[1] and htfbosLL == htfbosLL[1]
- htfdrawLongBosRegular = htfdrawLongBos and htflongBosUnchanged
- htfdrawLongBosOrigin = htfdrawLongBos and not htflongBosUnchanged
- htfcolorBosLongLineMain = not htfdrawLongBosRegular or not showBosHtfMainLine ? na :
- htfbosTesting ? htfcolorBosLongLineMainTesting : htfbosBreached ? htfcolorBosLongLineMainBreached : htfcolorBosLongLineMainNormal
- htfcolorBosLongLineAux = not htfdrawLongBosRegular or not showBosHtfAuxLine ? na :
- htfbosTesting ? htfcolorBosLongLineAuxTesting : htfbosBreached ? htfcolorBosLongLineAuxBreached : htfcolorBosLongLineAuxNormal
- htfcolorBosLongFill = not htfdrawLongBosRegular or not showBosHtfFill ? na :
- htfbosTesting ? htfcolorBosLongBgTesting : htfbosBreached ? htfcolorBosLongBgBreached : htfcolorBosLongBgNormal
- if htfdrawLongBosOrigin and htfbosLH
- if showBosHtfOriginMainLine
- line.new(htfbosLB - htfOffset, htfbosLH, bar_index - htfOffset, htfbosLH, color = htfcolorBosLongLineMainNormal, width = showBosHtfWidthMain)
- if showBosHtfOriginAuxLine
- line.new(htfbosLB - htfOffset, htfbosLL, bar_index - htfOffset, htfbosLL, color = htfcolorBosLongLineAuxNormal, width = showBosHtfWidthAux)
- if showBosHtfOriginFill
- box.new(htfbosLB - htfOffset, htfbosLH, bar_index - htfOffset, htfbosLL, na, bgcolor = htfcolorBosLongBgNormal)
- // --------------------------------------------------------------
- // 07.03.03.02 OUTPUT: HTF BOS | SHORT
- // --------------------------------------------------------------
- // HTF Short BOS Colors
- htfcolorBosShortLineMainNormal = color.new(htfcolorBosShortMain, htfBosT3)
- htfcolorBosShortLineMainTesting = color.new(htfcolorBosShortMain, htfBosT4)
- htfcolorBosShortLineMainBreached = color.new(htfcolorBosShortMain, htfBosT5)
- htfcolorBosShortLineAuxNormal = color.new(htfcolorBosShortAux, htfBosT2)
- htfcolorBosShortLineAuxTesting = color.new(htfcolorBosShortAux, htfBosT3)
- htfcolorBosShortLineAuxBreached = color.new(htfcolorBosShortMain, htfBosT3)
- htfcolorBosShortBgNormal = color.new(htfcolorBosShortAux, htfBosT1)
- htfcolorBosShortBgTesting = color.new(htfcolorBosShortAux, htfBosT2)
- htfcolorBosShortBgBreached = color.new(htfcolorBosShortMain, htfBosT2)
- // HTF Short BOS Draw
- htfdrawShortBos = showBosEnabled and htfpriorTrend == 1
- htfshortBosUnchanged = htfbosSH == htfbosSH[1] and htfbosSL == htfbosSL[1]
- htfdrawShortBosRegular = htfdrawShortBos and htfshortBosUnchanged
- htfdrawShortBosOrigin = htfdrawShortBos and not htfshortBosUnchanged
- htfcolorBosShortLineAux = not htfdrawShortBosRegular or not showBosHtfAuxLine ? na :
- htfbosTesting ? htfcolorBosShortLineAuxTesting : htfbosBreached ? htfcolorBosShortLineAuxBreached : htfcolorBosShortLineAuxNormal
- htfcolorBosShortLineMain = not htfdrawShortBosRegular or not showBosHtfMainLine? na :
- htfbosTesting ? htfcolorBosShortLineMainTesting : htfbosBreached ? htfcolorBosShortLineMainBreached : htfcolorBosShortLineMainNormal
- htfcolorBosShortFill = not htfdrawShortBosRegular or not showBosHtfFill ? na :
- htfbosTesting ? htfcolorBosShortBgTesting : htfbosBreached ? htfcolorBosShortBgBreached : htfcolorBosShortBgNormal
- if htfdrawShortBosOrigin and htfbosSH
- if showBosHtfOriginAuxLine
- line.new(htfbosSB - htfOffset, htfbosSH, bar_index - htfOffset, htfbosSH, color = htfcolorBosShortLineAuxNormal, width = showBosHtfWidthAux)
- if showBosHtfOriginMainLine
- line.new(htfbosSB - htfOffset, htfbosSL, bar_index - htfOffset, htfbosSL, color = htfcolorBosShortLineMainNormal, width = showBosHtfWidthMain)
- if showBosHtfOriginFill
- box.new(htfbosSB - htfOffset, htfbosSH, bar_index - htfOffset, htfbosSL, na, bgcolor = htfcolorBosShortBgNormal)
- // --------------------------------------------------------------
- // 07.03.03.03 OUTPUT: HTF BOS | PLOT
- // --------------------------------------------------------------
- htfblh = plot(htfpriorTrend == 1 ? htfbosSL : htfbosLH, "HTF BOS Main", htfpriorTrend == 1 ? htfcolorBosShortLineMain : htfcolorBosLongLineMain, showBosHtfWidthMain,
- plot.style_line, offset = -htfOffset, editable = false, display = display.pane + display.data_window + display.status_line)
- htfbll = plot(htfpriorTrend == 1 ? htfbosSH : htfbosLL, "HTF BOS Aux", htfpriorTrend == 1 ? htfcolorBosShortLineAux : htfcolorBosLongLineAux, showBosHtfWidthAux,
- plot.style_line, offset = -htfOffset, editable = false, display = display.pane + display.data_window + display.status_line)
- fill(htfblh, htfbll, htfpriorTrend == 1 ? htfcolorBosShortFill : htfcolorBosLongFill , "HTF BOS Fill", editable = false)
- // --------------------------------------------------------------
- // 07.03.04 OUTPUT: HTF CLASSIC BOS
- // --------------------------------------------------------------
- // --------------------------------------------------------------
- // 07.03.04.01 OUTPUT: HTF CLASSIC BOS | LONG
- // --------------------------------------------------------------
- // HTF Long Classic BOS Colors
- htfcolorCBosLongLineMainNormal = color.new(htfcolorCBosLongMain, htfCBosT3)
- htfcolorCBosLongLineAuxNormal = color.new(htfcolorCBosLongAux, htfCBosT2)
- htfcolorCBosLongBgNormal = color.new(htfcolorCBosLongAux, htfCBosT1)
- // HTF Long Classic BOS Draw
- htfdrawLongCBos = showBosEnabled and showCBosEnabled and htfpriorTrend == -1
- htflongCBosUnchanged = htfcbosLH == htfcbosLH[1] and htfcbosLL == htfcbosLL[1]
- htfdrawLongCBosRegular = htfdrawLongCBos and htflongCBosUnchanged
- htfdrawLongCBosOrigin = htfdrawLongCBos and not htflongCBosUnchanged
- htfcolorCBosLongLineMain = not htfdrawLongCBosRegular or not showCBosHtfAuxLine ? na : htfcolorCBosLongLineMainNormal
- htfcolorCBosLongLineAux = not htfdrawLongCBosRegular or not showCBosHtfAuxLine ? na : htfcolorCBosLongLineAuxNormal
- htfcolorCBosLongFill = not htfdrawLongCBosRegular or not showCBosHtfFill ? na : htfcolorCBosLongBgNormal
- if htfdrawLongCBosOrigin and htfcbosLH
- if showCBosHtfOriginMainLine
- line.new(htfcbosLB - htfOffset, htfcbosLH, bar_index - htfOffset, htfcbosLH, color = htfcolorCBosLongLineMainNormal, width = showCBosHtfWidthMain)
- if showCBosHtfOriginAuxLine
- line.new(htfcbosLB - htfOffset, htfcbosLL, bar_index - htfOffset, htfcbosLL, color = htfcolorCBosLongLineAuxNormal, width = showCBosHtfWidthAux)
- if showCBosHtfOriginFill
- box.new(htfcbosLB - htfOffset, htfcbosLH, bar_index - htfOffset, htfcbosLL, na, bgcolor = htfcolorCBosLongBgNormal)
- // --------------------------------------------------------------
- // 07.03.04.02 OUTPUT: HTF CLASSIC BOS | SHORT
- // --------------------------------------------------------------
- // HTF Short Classic BOS Colors
- htfcolorCBosShortLineMainNormal = color.new(htfcolorCBosShortMain, htfCBosT3)
- htfcolorCBosShortLineAuxNormal = color.new(htfcolorCBosShortAux, htfCBosT2)
- htfcolorCBosShortBgNormal = color.new(htfcolorCBosShortAux, htfCBosT1)
- // HTF Short Classic BOS Draw
- htfdrawShortCBos = showBosEnabled and showCBosEnabled and htfpriorTrend == 1
- htfshortCBosUnchanged = htfcbosSH == htfcbosSH[1] and htfcbosSL == htfcbosSL[1]
- htfdrawShortCBosRegular = htfdrawShortCBos and htfshortCBosUnchanged
- htfdrawShortCBosOrigin = htfdrawShortCBos and not htfshortCBosUnchanged
- htfcolorCBosShortLineAux = not htfdrawShortCBosRegular or not showCBosHtfAuxLine ? na : htfcolorCBosShortLineAuxNormal
- htfcolorCBosShortLineMain = not htfdrawShortCBosRegular or not showCBosHtfAuxLine ? na : htfcolorCBosShortLineMainNormal
- htfcolorCBosShortFill = not htfdrawShortCBosRegular or not showCBosHtfFill ? na : htfcolorCBosShortBgNormal
- if htfdrawShortCBosOrigin and htfcbosSH
- if showCBosHtfOriginAuxLine
- line.new(htfcbosSB - htfOffset, htfcbosSH, bar_index - htfOffset, htfcbosSH, color = htfcolorCBosShortLineAuxNormal, width = showCBosHtfWidthAux)
- if showCBosHtfOriginMainLine
- line.new(htfcbosSB - htfOffset, htfcbosSL, bar_index - htfOffset, htfcbosSL, color = htfcolorCBosShortLineMainNormal, width = showCBosHtfWidthMain)
- if showCBosHtfOriginFill
- box.new(htfcbosSB - htfOffset, htfcbosSH, bar_index - ctfOffset, htfcbosSL, na, bgcolor = htfcolorCBosShortBgNormal)
- // --------------------------------------------------------------
- // 07.03.04.03 OUTPUT: HTF CLASSIC BOS | PLOT
- // --------------------------------------------------------------
- htfcblh = plot(htfpriorTrend == 1 ? htfcbosSL : htfcbosLH, "HTF CBOS Main", htfpriorTrend == 1 ? htfcolorCBosShortLineMain : htfcolorCBosLongLineMain, showCBosHtfWidthMain,
- plot.style_line, offset = -htfOffset, editable = false, display = display.pane + display.data_window + display.status_line)
- htfcbll = plot(htfpriorTrend == 1 ? htfcbosSH : htfcbosLL, "HTF CBOS Aux", htfpriorTrend == 1 ? htfcolorCBosShortLineAux : htfcolorCBosLongLineAux, showCBosHtfWidthAux,
- plot.style_line, offset = -htfOffset, editable = false, display = display.pane + display.data_window + display.status_line)
- fill(htfcblh, htfcbll, htfpriorTrend == 1 ? htfcolorCBosShortFill : htfcolorCBosLongFill, "HTF CBOS Fill", editable = false)
- // --------------------------------------------------------------
- // 07.04 OUTPUT: HH/LL LEVELS
- // --------------------------------------------------------------
- // In case we need to free more plots, we can use const color here, at the cost of switching to linebr style and losing one point on line switch
- // Highs
- colorHighPrior = color.new(color.green, 70)
- colorHighGlobal = color.new(color.yellow, 70)
- outPriorH = bosBreached ? priorH : globalH
- outputPriorH = showHhLlLevels and priorTrend == 1
- outputGlobalH = showHhLlLevels and globalTrendDirection == 1 and bosBreached
- plot(outputPriorH ? outPriorH : na, "Prior High", outputPriorH and outPriorH == outPriorH[1] ? colorHighPrior : na, offset = -ctfOffset,
- editable = false, display = display.pane + display.data_window + display.status_line)
- plot(outputGlobalH ? globalH : na, "Global High", outputGlobalH and globalH == globalH[1] ? colorHighGlobal : na, offset = -ctfOffset,
- editable = false, display = display.pane + display.data_window + display.status_line)
- if showHhLlLevelsOrigin
- if outputPriorH and globalTrendDirection[1] == 0
- line.new(globalHB - ctfOffset, outPriorH, bar_index - ctfOffset, outPriorH, color = colorHighPrior, width = 1)
- if outputGlobalH and not bosBreached[1]
- line.new(globalHB - ctfOffset, globalH, bar_index - ctfOffset, globalH, color = colorHighGlobal, width = 1)
- // Lows
- colorLowPrior = color.new(color.red, 70)
- colorLowGlobal = color.new(color.orange, 70)
- outPriorL = bosBreached ? priorL : globalL
- outputPriorL = showHhLlLevels and priorTrend == -1
- outputGlobalL = showHhLlLevels and globalTrendDirection == -1 and bosBreached
- plot(outputPriorL ? outPriorL : na, "Prior Low", outputPriorL and outPriorL == outPriorL[1] ? colorLowPrior : na, offset = -ctfOffset,
- editable = false, display = display.pane + display.data_window + display.status_line)
- plot(outputGlobalL ? globalL : na, "Global Low", outputGlobalL and globalL == globalL[1] ? colorLowGlobal : na, offset = -ctfOffset,
- editable = false, display = display.pane + display.data_window + display.status_line)
- if showHhLlLevelsOrigin
- if outputPriorL and globalTrendDirection[1] == 0
- line.new(globalLB - ctfOffset, outPriorL, bar_index - ctfOffset, outPriorL, color = colorLowPrior, width = 1)
- if outputGlobalL and not bosBreached[1]
- line.new(globalLB - ctfOffset, globalL, bar_index - ctfOffset, globalL, color = colorLowGlobal, width = 1)
- // -----------------------------
- // 07.05 OUTPUT TREND BG / EDGE
- // -----------------------------
- displayTrendBgDirection = showTrendBG == 1 ? globalTrendDirection : showTrendBG == 2 ? htfglobalTrendDirection : 0
- displayTrendBgWeak = showTrendBG == 1 ? bosBreached : showTrendBG == 2 ? htfbosBreached : 0
- displayTrendBgOffset = showTrendBG == 1 ? ctfOffset : showTrendBG == 2 ? htfOffset : 0
- displayTrendAboveDirection = showTrendAbove == 1 ? globalTrendDirection : showTrendAbove == 2 ? htfglobalTrendDirection : 0
- displayTrendAboveWeak = showTrendAbove == 1 ? bosBreached : showTrendAbove == 2 ? htfbosBreached : 0
- displayTrendAboveOffset = showTrendAbove == 1 ? ctfOffset : showTrendAbove == 2 ? htfOffset : 0
- displayTrendBelowDirection = showTrendBelow == 1 ? globalTrendDirection : showTrendBelow == 2 ? htfglobalTrendDirection : 0
- displayTrendBelowWeak = showTrendBelow == 1 ? bosBreached : showTrendBelow == 2 ? htfbosBreached : 0
- displayTrendBelowOffset = showTrendBelow == 1 ? ctfOffset : showTrendBelow == 2 ? htfOffset : 0
- bgcolor(displayTrendBgDirection == 0 ? na :
- displayTrendBgDirection == 1 ?
- (displayTrendBgWeak ? trendBgLongAux: trendBgLongMain) :
- (displayTrendBgWeak ? trendBgShortAux : trendBgShortMain),
- -displayTrendBgOffset)
- plotshape(displayTrendAboveDirection == 0 ? na : displayTrendAboveDirection, "Trend Display: Above", shape.circle, location.top,
- displayTrendAboveDirection == 1 ?
- (displayTrendAboveWeak ? trendEdgeLongAux : trendEdgeLongMain) :
- (displayTrendAboveWeak ? trendEdgeShortAux : trendEdgeShortMain), -displayTrendAboveOffset, size = size.tiny)
- plotshape(displayTrendBelowDirection == 0 ? na : displayTrendBelowDirection, "Trend Display: Below", shape.circle, location.bottom,
- displayTrendBelowDirection == 1 ?
- (displayTrendBelowWeak ? trendEdgeLongAux : trendEdgeLongMain) :
- (displayTrendBelowWeak ? trendEdgeShortAux : trendEdgeShortMain), -displayTrendBelowOffset, size = size.tiny)
- // --------------------------------------------------------------
- // 07.06 OUTPUT EVENTS
- // --------------------------------------------------------------
- if showTrendLabels
- if showTrendLabelsCtf
- if eventTrendBreak
- printLabel(globalTrendDirection, bar_index - ctfOffset,"CTF\nTrend\nBreak!", globalTrendDirection != 1, false)
- if eventTrendReversalConfirmed
- printLabel(globalTrendDirection, bar_index - ctfOffset,"CTF\nTrend\nReversal\nConfirmed!", globalTrendDirection != 1, true)
- if eventTrendResume
- printLabel(globalTrendDirection, bar_index - ctfOffset,"CTF\nTrend\nResume!", globalTrendDirection == 1, true)
- if showTrendLabelsHtf
- if htfeventTrendBreak
- printLabel(htfglobalTrendDirection, bar_index - htfOffset,"HTF\nTrend\nBreak!", htfglobalTrendDirection != 1, false)
- if htfeventTrendReversalConfirmed
- printLabel(htfglobalTrendDirection, bar_index - htfOffset,"HTF\nTrend\nReversal\nConfirmed!", htfglobalTrendDirection != 1, true)
- if htfeventTrendResume
- printLabel(htfglobalTrendDirection, bar_index - htfOffset,"HTF\nTrend\nResume!", htfglobalTrendDirection == 1, true)
- // --------------------------------------------------------------
- // 07.XX OUTPUT: DEBUG
- // --------------------------------------------------------------
- // plotshape(bosBreachCandles, "bosBreachCandles", color=na, offset = -ctfOffset)
- if barstate.islast
- tb = table.new(position.top_right, 1, 2, bgcolor = #111111, border_width = 1, border_color = color.gray, frame_width = 1, frame_color = color.gray)
- table.cell(tb, 0, 0, str.tostring(0,format.mintick), text_color = color.white, text_size = size.small)
- table.cell(tb, 0, 1, str.tostring(0/close*100,"#.##")+"%", text_color = color.white, text_size = size.small)
- if barstate.islast and DBG_DebugEnabled
- tb = table.new(position.top_right, 1, 2, bgcolor = #111111, border_width = 1, border_color = color.gray, frame_width = 1, frame_color = color.gray)
- table.cell(tb, 0, 0, str.tostring(0,format.mintick), text_color = color.white, text_size = size.small)
- table.cell(tb, 0, 1, str.tostring(0/close*100,"#.##")+"%", text_color = color.white, text_size = size.small)
- if barstate.islast and DBG_FirstLimitOn
- tb = table.new(position.top_right, 1, 2, bgcolor = #111111, border_width = 1, border_color = color.gray, frame_width = 1, frame_color = color.gray)
- table.cell(tb, 0, 0, str.tostring(0,format.mintick), text_color = color.white, text_size = size.small)
- table.cell(tb, 0, 1, str.tostring(0/close*100,"#.##")+"%", text_color = color.white, text_size = size.small)
- if barstate.islast and DBG_ShowHTFDebugPlots
- tb = table.new(position.top_right, 1, 2, bgcolor = #111111, border_width = 1, border_color = color.gray, frame_width = 1, frame_color = color.gray)
- table.cell(tb, 0, 0, str.tostring(0,format.mintick), text_color = color.white, text_size = size.small)
- table.cell(tb, 0, 1, str.tostring(0/close*100,"#.##")+"%", text_color = color.white, text_size = size.small)
- if true
- na
- if true
- na
- if true
- na
- if true
- na
- if true
- na
- if true
- na
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement