ajiim

🎁

Oct 11th, 2026
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.87 KB | None | 0 0
  1. //@version=6
  2. indicator("Trend Average (Zeiierman)", shorttitle = "Trend Average (Zeiierman)", overlay = true, max_lines_count = 500, max_labels_count = 500, max_bars_back = 500)
  3.  
  4. string GRP_TA = "Trend Average"
  5. string GRP_SIG = "Signals"
  6. string GRP_PH = "Trend Phase Engine"
  7. string GRP_LF = "Layered Trend Filters"
  8. string GRP_EXT = "External Chart Filter"
  9. string GRP_STY = "Style"
  10. string GRP_VIS = "Trend Visuals"
  11.  
  12. string modeInput = input.string("Intraday", "Signal Mode", options = ["Intraday", "Scalping"], group = GRP_TA, tooltip = "Intraday: cleaner, more confirmed pullback setups with structured continuation logic.\nScalping: faster signal engine acting on less-confirmed pullbacks and enabling the Trend Phase color engine.")
  13. float srcInput = input.source(close, "Source", group = GRP_TA, tooltip = "Price source used by the adaptive Trend Average ribbon.")
  14. int lenInput = input.int(40, "Trend Length", minval = 5, maxval = 500, group = GRP_TA, tooltip = "Base length of the Trend Average (center line). All ribbon bands are derived from this length.")
  15. float spreadInput = input.float(0.5, "Ribbon Spread", minval = 0.1, maxval = 3.0, step = 0.05, group = GRP_TA, tooltip = "Controls the distance between the ribbon bands. Higher values create a wider ribbon that expands more during strong trends.")
  16. float sensInput = input.float(1.0, "Adaptive Sensitivity", minval = 0.0, maxval = 3.0, step = 0.1, group = GRP_TA, tooltip = "How strongly the ribbon adapts to market activity. Higher values react faster during strong directional movement and stabilize more during quiet periods. 0 = non-adaptive.")
  17. int erLenInput = input.int(14, "Efficiency Length", minval = 2, maxval = 200, group = GRP_TA, tooltip = "Lookback used to measure directional efficiency (trend strength vs. noise) that drives the adaptive speed.")
  18.  
  19. bool showEntryInput = input.bool(true, "Show Entry", group = GRP_SIG, inline = "SIG")
  20. bool showConfInput = input.bool(true, "Show Conf", group = GRP_SIG, inline = "SIG", tooltip = "Entry highlights the pullback opportunity. Conf validates the continuation when price closes beyond the tracked confirmation level.")
  21. int confWinInput = input.int(30, "Confirmation Window", minval = 1, maxval = 500, group = GRP_SIG, tooltip = "Number of bars after an Entry during which price must close beyond the Conf level. Otherwise, or if price closes beyond the Entry level, the setup is invalidated.")
  22. int minPbInput = input.int(2, "Min Pullback Bars", minval = 1, maxval = 50, group = GRP_SIG, tooltip = "Intraday mode: minimum number of counter-trend bars required before an Entry may trigger. Scalping mode always uses 1.")
  23. int flowLenInput = input.int(5, "Event Lookback", minval = 2, maxval = 50, group = GRP_SIG, tooltip = "Number of recent bars whose bullish and bearish price action events are scored to define the directional flow.")
  24. float flowThrInput = input.float(0.5, "Event Threshold", minval = 0.0, maxval = 10.0, step = 0.25, group = GRP_SIG, tooltip = "Net event score required to flip the directional flow. Higher values = fewer flips.")
  25. int swingLenInput = input.int(5, "Swing Length", minval = 1, maxval = 50, group = GRP_SIG, tooltip = "Bars on each side used to detect swing highs and lows for the swing-based events.")
  26. string lblSizeInput = input.string("Normal", "Label Size", options = ["Tiny", "Small", "Normal", "Large"], group = GRP_SIG)
  27. string lineStyleInput = input.string("Dotted", "Level Line", options = ["Dotted", "Dashed", "Solid"], group = GRP_SIG, inline = "LN")
  28. int lineWidthInput = input.int(2, "", minval = 1, maxval = 4, group = GRP_SIG, inline = "LN", tooltip = "Style and width of the Entry and Conf level lines.")
  29.  
  30. int phaseLenInput = input.int(10, "Phase Lookback", minval = 2, maxval = 100, group = GRP_PH, tooltip = "Scalping mode: number of recent bars used to score bullish and bearish pressure.")
  31. int phaseSmInput = input.int(3, "Phase Smoothing", minval = 1, maxval = 20, group = GRP_PH, tooltip = "Smoothing applied to the normalized phase score.")
  32. float strongInput = input.float(0.4, "Strong Phase Threshold", minval = 0.05, maxval = 1.0, step = 0.05, group = GRP_PH, tooltip = "Normalized score (0 to 1) required to classify a phase as Strong. Below it, phases are Early (building) or Weak (fading).")
  33.  
  34. bool useL1Input = input.bool(false, "Layer 1: Ribbon Direction", group = GRP_LF, tooltip = "Longs only while the Trend Average is rising, shorts only while it is falling.")
  35. bool useL2Input = input.bool(false, "Layer 2: Ribbon Structure", group = GRP_LF, tooltip = "Longs only when the ribbon is stacked bullish (fast > center > slow), shorts only when stacked bearish.")
  36. bool useL3Input = input.bool(false, "Layer 3: Higher Timeframe", group = GRP_LF, inline = "L3")
  37. string htfInput = input.timeframe("240", "", group = GRP_LF, inline = "L3", tooltip = "Longs only when the Trend Average on this timeframe points up, shorts only when it points down. Uses the last confirmed higher-timeframe bar (no repainting). If lower than the chart timeframe, the chart trend is used.")
  38.  
  39. bool useExtInput = input.bool(false, "Source Filter", group = GRP_EXT, inline = "EXT")
  40. float extSrcInput = input.source(close, "", group = GRP_EXT, inline = "EXT", tooltip = "Select an external chart source such as a Moving Average plot. Entries are only allowed when the close is on the required side of it.")
  41. string extModeInput = input.string("Long: Above / Short: Below", "Source Condition", options = ["Long: Above / Short: Below", "Long: Below / Short: Above"], group = GRP_EXT)
  42. bool useLvlInput = input.bool(false, "Level Filter", group = GRP_EXT, inline = "LVL")
  43. float lvlSrcInput = input.source(close, "", group = GRP_EXT, inline = "LVL")
  44. float lvlInput = input.float(50.0, "Level", group = GRP_EXT, inline = "LVL", tooltip = "Select a source (e.g. a Stochastic) and a level. Entries are only allowed when the source is on the required side of the level.")
  45. string lvlModeInput = input.string("Long: Below / Short: Above", "Level Condition", options = ["Long: Below / Short: Above", "Long: Above / Short: Below"], group = GRP_EXT)
  46.  
  47. bool showRibbonInput = input.bool(true, "Show Ribbon", group = GRP_STY)
  48. color bullColInput = input.color(#22AB94, "Intraday Bull", group = GRP_STY, inline = "ID")
  49. color bearColInput = input.color(#F23645, "Bear", group = GRP_STY, inline = "ID")
  50. color strongBullInput = input.color(#00E676, "Strong Bull", group = GRP_STY, inline = "SB")
  51. color earlyBullInput = input.color(#26C6A9, "Early Bull", group = GRP_STY, inline = "SB")
  52. color weakBullInput = input.color(#2196F3, "Weak Bull", group = GRP_STY, inline = "SB")
  53. color strongBearInput = input.color(#FF1744, "Strong Bear", group = GRP_STY, inline = "SS")
  54. color earlyBearInput = input.color(#FF6E8A, "Early Bear", group = GRP_STY, inline = "SS")
  55. color weakBearInput = input.color(#FF9800, "Weak Bear", group = GRP_STY, inline = "SS")
  56. int fillTranspInput = input.int(85, "Ribbon Fill Transparency", minval = 0, maxval = 100, group = GRP_STY)
  57.  
  58. bool showBgInput = input.bool(false, "Trend Background Color", group = GRP_VIS)
  59. bool candleInput = input.bool(false, "Trend Candle Coloring", group = GRP_VIS)
  60. bool showTrackerInput = input.bool(false, "Trend Tracker Line", group = GRP_VIS, inline = "TRK")
  61. int trackLenInput = input.int(10, "", minval = 2, maxval = 200, group = GRP_VIS, inline = "TRK", tooltip = "Ratcheting trailing line that follows the extreme of the last N bars in the trend direction.")
  62.  
  63. int PH_STRONG_BULL = 3
  64. int PH_EARLY_BULL = 2
  65. int PH_WEAK_BULL = 1
  66. int PH_WEAK_BEAR = -1
  67. int PH_EARLY_BEAR = -2
  68. int PH_STRONG_BEAR = -3
  69. int ATR_FAST = 10
  70. int ATR_SLOW = 50
  71. int ENTRY_EXT = 2
  72. int MAX_PB_BARS = 75
  73. color NO_COLOR = color.new(color.black, 100)
  74. bool IS_SCALP = modeInput == "Scalping"
  75. int MIN_PB_BARS = IS_SCALP ? 1 : minPbInput
  76. color LONG_SIG_COL = IS_SCALP ? strongBullInput : bullColInput
  77. color SHORT_SIG_COL = IS_SCALP ? strongBearInput : bearColInput
  78.  
  79. f_lineStyle(string s) =>
  80. switch s
  81. "Dashed" => line.style_dashed
  82. "Solid" => line.style_solid
  83. => line.style_dotted
  84.  
  85. f_labelSize(string s) =>
  86. switch s
  87. "Tiny" => size.tiny
  88. "Small" => size.small
  89. "Large" => size.large
  90. => size.normal
  91.  
  92. string LINE_STYLE = f_lineStyle(lineStyleInput)
  93. string LABEL_SIZE = f_labelSize(lblSizeInput)
  94.  
  95. f_efficiency(float src, int len) =>
  96. float change = math.abs(src - src[len])
  97. float noise = math.sum(math.abs(src - src[1]), len)
  98. float er = noise > 0 ? change / noise : 0.0
  99. nz(er)
  100.  
  101. f_speed(float src, int erLen, float sens) =>
  102. float er = f_efficiency(src, erLen)
  103. float atrFast = ta.atr(ATR_FAST)
  104. float atrSlow = ta.atr(ATR_SLOW)
  105. float volRatio = nz(atrSlow) > 0 ? nz(atrFast) / atrSlow : 1.0
  106. float volClamp = math.max(0.6, math.min(1.6, volRatio))
  107. float volFact = math.pow(volClamp, 0.5 * sens)
  108. float momFact = 1.0 + sens * (2.2 * er - 0.6)
  109. math.max(0.2, math.min(3.0, momFact * volFact))
  110.  
  111. f_adaptiveMA(float src, float len, float speed) =>
  112. var float am = na
  113. float alpha = math.max(0.0005, math.min(1.0, 2.0 / (math.max(len, 1.0) + 1.0) * speed))
  114. am := na(am) ? src : am + alpha * (src - am)
  115. am
  116.  
  117. f_ribbon(float src, int len, float spread, float speed) =>
  118. float fastOuter = f_adaptiveMA(src, len / (1.0 + 2.0 * spread), speed)
  119. float fastInner = f_adaptiveMA(src, len / (1.0 + spread), speed)
  120. float mid = f_adaptiveMA(src, len * 1.0, speed)
  121. float slowInner = f_adaptiveMA(src, len * (1.0 + spread), speed)
  122. float slowOuter = f_adaptiveMA(src, len * (1.0 + 2.0 * spread), speed)
  123. [fastOuter, fastInner, mid, slowInner, slowOuter]
  124.  
  125. f_htfTrendPrev(float src, int len, float spread, int erLen, float sens) =>
  126. float spd = f_speed(src, erLen, sens)
  127. [fo, fi, md, si, so] = f_ribbon(src, len, spread, spd)
  128. var int dir = 0
  129. dir := fi > si and md > md[1] ? 1 : fi < si and md < md[1] ? -1 : dir
  130. nz(dir[1])
  131.  
  132. type PullbackSetup
  133. int dir
  134. float advExt = na
  135. int advExtBar = na
  136. bool inPullback = false
  137. float confCand = na
  138. int confCandBar = na
  139. float pbExt = na
  140. int pbExtBar = na
  141. int pbBars = 0
  142. bool armed = false
  143. float entryLevel = na
  144. float confLevel = na
  145. int confBar = na
  146. int expiryBar = na
  147. line confLine = na
  148.  
  149. method favPrice(PullbackSetup this) =>
  150. this.dir == 1 ? high : low
  151.  
  152. method adverse(PullbackSetup this) =>
  153. this.dir == 1 ? low : high
  154.  
  155. method isBeyond(PullbackSetup this, float a, float b) =>
  156. this.dir == 1 ? a > b : a < b
  157.  
  158. method resetAdvance(PullbackSetup this) =>
  159. this.advExt := this.favPrice()
  160. this.advExtBar := bar_index
  161. this.inPullback := false
  162. this.pbExt := na
  163. this.pbExtBar := na
  164. this.pbBars := 0
  165. this
  166.  
  167. method trackAdvance(PullbackSetup this) =>
  168. float fav = this.favPrice()
  169. if na(this.advExt) or this.isBeyond(fav, this.advExt)
  170. this.advExt := fav
  171. this.advExtBar := bar_index
  172. this
  173.  
  174. method startPullback(PullbackSetup this) =>
  175. this.inPullback := true
  176. this.confCand := this.advExt
  177. this.confCandBar := this.advExtBar
  178. this.pbExt := this.adverse()
  179. this.pbExtBar := bar_index
  180. this.pbBars := 1
  181. this
  182.  
  183. method trackPullback(PullbackSetup this) =>
  184. float adv = this.adverse()
  185. if na(this.pbExt) or this.isBeyond(this.pbExt, adv)
  186. this.pbExt := adv
  187. this.pbExtBar := bar_index
  188. this
  189.  
  190. method abortPullback(PullbackSetup this) =>
  191. this.inPullback := false
  192. this.pbExt := na
  193. this.pbExtBar := na
  194. this.pbBars := 0
  195. this
  196.  
  197. method invalidate(PullbackSetup this) =>
  198. if not na(this.confLine)
  199. this.confLine.delete()
  200. this.confLine := na
  201. this.armed := false
  202. this
  203.  
  204. method step(PullbackSetup this, bool trendOk, bool counterMove, bool realign, bool filtersOk, color sigCol) =>
  205. bool entryFired = false
  206. bool confFired = false
  207. bool invalid = false
  208. if this.armed
  209. if not na(this.confLine)
  210. this.confLine.set_x2(bar_index)
  211. if this.isBeyond(close, this.confLevel)
  212. confFired := true
  213. if showConfInput
  214. int midX = math.round((this.confBar + bar_index) / 2.0)
  215. label.new(midX, this.confLevel, "Conf", color = NO_COLOR, style = this.dir == 1 ? label.style_label_down : label.style_label_up, textcolor = sigCol, size = LABEL_SIZE, tooltip = (this.dir == 1 ? "Long" : "Short") + " continuation confirmed\nConf level: " + str.tostring(this.confLevel, format.mintick))
  216. this.confLine := na
  217. this.armed := false
  218. else if bar_index >= this.expiryBar or this.isBeyond(this.entryLevel, close)
  219. invalid := true
  220. this.invalidate()
  221. if not trendOk
  222. this.resetAdvance()
  223. else if this.inPullback
  224. this.trackPullback()
  225. if realign
  226. if this.pbBars >= MIN_PB_BARS
  227. if not this.armed and filtersOk and not na(this.confCand) and not na(this.pbExt) and this.isBeyond(this.confCand, this.pbExt)
  228. entryFired := true
  229. this.entryLevel := this.pbExt
  230. this.confLevel := this.confCand
  231. this.confBar := this.confCandBar
  232. this.expiryBar := bar_index + confWinInput
  233. this.armed := true
  234. if showEntryInput
  235. int x1 = this.pbExtBar
  236. int x2 = bar_index + ENTRY_EXT
  237. line.new(x1, this.pbExt, x2, this.pbExt, color = sigCol, style = LINE_STYLE, width = lineWidthInput)
  238. label.new(math.round((x1 + x2) / 2.0), this.pbExt, "Entry", color = NO_COLOR, style = this.dir == 1 ? label.style_label_up : label.style_label_down, textcolor = sigCol, size = LABEL_SIZE, tooltip = (this.dir == 1 ? "Long" : "Short") + " pullback Entry\nEntry level: " + str.tostring(this.pbExt, format.mintick) + "\nConf level: " + str.tostring(this.confCand, format.mintick))
  239. if showConfInput
  240. this.confLine := line.new(this.confBar, this.confLevel, bar_index, this.confLevel, color = sigCol, style = LINE_STYLE, width = lineWidthInput)
  241. this.resetAdvance()
  242. else
  243. this.abortPullback()
  244. this.trackAdvance()
  245. else
  246. this.pbBars := this.pbBars + 1
  247. if this.pbBars > MAX_PB_BARS
  248. this.resetAdvance()
  249. else
  250. this.trackAdvance()
  251. if counterMove
  252. this.startPullback()
  253. [entryFired, confFired, invalid]
  254.  
  255. float speed = f_speed(srcInput, erLenInput, sensInput)
  256. [fastOuter, fastInner, center, slowInner, slowOuter] = f_ribbon(srcInput, lenInput, spreadInput, speed)
  257.  
  258. var int trendDir = 0
  259. bool ribbonUp = fastInner > slowInner and center > center[1]
  260. bool ribbonDn = fastInner < slowInner and center < center[1]
  261. trendDir := ribbonUp ? 1 : ribbonDn ? -1 : trendDir
  262.  
  263. float pivHigh = ta.pivothigh(high, swingLenInput, swingLenInput)
  264. float pivLow = ta.pivotlow(low, swingLenInput, swingLenInput)
  265.  
  266. var float lastSwingHigh = na
  267. var float prevSwingHigh = na
  268. var float lastSwingLow = na
  269. var float prevSwingLow = na
  270.  
  271. bool newSwingHigh = not na(pivHigh)
  272. bool newSwingLow = not na(pivLow)
  273. if newSwingHigh
  274. prevSwingHigh := lastSwingHigh
  275. lastSwingHigh := pivHigh
  276. if newSwingLow
  277. prevSwingLow := lastSwingLow
  278. lastSwingLow := pivLow
  279.  
  280. bool higherHigh = newSwingHigh and not na(prevSwingHigh) and lastSwingHigh > prevSwingHigh
  281. bool lowerHigh = newSwingHigh and not na(prevSwingHigh) and lastSwingHigh < prevSwingHigh
  282. bool higherLow = newSwingLow and not na(prevSwingLow) and lastSwingLow > prevSwingLow
  283. bool lowerLow = newSwingLow and not na(prevSwingLow) and lastSwingLow < prevSwingLow
  284.  
  285. bool evRangeBull = close > high[1]
  286. bool evRangeBear = close < low[1]
  287. bool evBarBull = high > high[1] and low > low[1]
  288. bool evBarBear = high < high[1] and low < low[1]
  289. bool evReclaimBull = ta.crossover(close, center)
  290. bool evReclaimBear = ta.crossunder(close, center)
  291. bool evSwingBull = ta.crossover(close, lastSwingHigh)
  292. bool evSwingBear = ta.crossunder(close, lastSwingLow)
  293. bool evStructBull = higherHigh or higherLow
  294. bool evStructBear = lowerHigh or lowerLow
  295.  
  296. float bullPts = (evRangeBull ? 1.0 : 0.0) + (evBarBull ? 0.5 : 0.0) + (evReclaimBull ? 1.0 : 0.0) + (evSwingBull ? 1.5 : 0.0) + (evStructBull ? 1.0 : 0.0)
  297. float bearPts = (evRangeBear ? 1.0 : 0.0) + (evBarBear ? 0.5 : 0.0) + (evReclaimBear ? 1.0 : 0.0) + (evSwingBear ? 1.5 : 0.0) + (evStructBear ? 1.0 : 0.0)
  298.  
  299. float flowNet = nz(math.sum(bullPts - bearPts, flowLenInput))
  300. var int flowState = 0
  301. flowState := flowNet > flowThrInput ? 1 : flowNet < -flowThrInput ? -1 : flowState
  302.  
  303. float bullPress = nz(math.sum(bullPts, phaseLenInput))
  304. float bearPress = nz(math.sum(bearPts, phaseLenInput))
  305. float pressTotal = bullPress + bearPress
  306. float rawPhase = pressTotal > 0 ? (bullPress - bearPress) / pressTotal : 0.0
  307. float phaseScore = nz(ta.ema(rawPhase, phaseSmInput))
  308. float phasePrev = nz(phaseScore[1])
  309.  
  310. int phase = 0
  311. if trendDir >= 0
  312. phase := phaseScore >= strongInput ? PH_STRONG_BULL : phaseScore > 0 ? (phaseScore >= phasePrev ? PH_EARLY_BULL : PH_WEAK_BULL) : phaseScore > -strongInput ? PH_WEAK_BULL : PH_EARLY_BEAR
  313. else
  314. phase := phaseScore <= -strongInput ? PH_STRONG_BEAR : phaseScore < 0 ? (phaseScore <= phasePrev ? PH_EARLY_BEAR : PH_WEAK_BEAR) : phaseScore < strongInput ? PH_WEAK_BEAR : PH_EARLY_BULL
  315.  
  316. bool l1Long = not useL1Input or center > center[1]
  317. bool l1Short = not useL1Input or center < center[1]
  318. bool l2Long = not useL2Input or (fastInner > center and center > slowInner)
  319. bool l2Short = not useL2Input or (fastInner < center and center < slowInner)
  320.  
  321. int htfDirRaw = request.security(syminfo.tickerid, htfInput, f_htfTrendPrev(close, lenInput, spreadInput, erLenInput, sensInput), lookahead = barmerge.lookahead_on)
  322. bool htfValid = timeframe.in_seconds(htfInput) >= timeframe.in_seconds(timeframe.period)
  323. int htfTrend = htfValid ? nz(htfDirRaw) : trendDir
  324. bool l3Long = not useL3Input or htfTrend == 1
  325. bool l3Short = not useL3Input or htfTrend == -1
  326.  
  327. bool extLongAbove = extModeInput == "Long: Above / Short: Below"
  328. bool extLongOk = not useExtInput or (extLongAbove ? close > extSrcInput : close < extSrcInput)
  329. bool extShortOk = not useExtInput or (extLongAbove ? close < extSrcInput : close > extSrcInput)
  330. bool lvlLongBelow = lvlModeInput == "Long: Below / Short: Above"
  331. bool lvlLongOk = not useLvlInput or (lvlLongBelow ? lvlSrcInput < lvlInput : lvlSrcInput > lvlInput)
  332. bool lvlShortOk = not useLvlInput or (lvlLongBelow ? lvlSrcInput > lvlInput : lvlSrcInput < lvlInput)
  333.  
  334. bool longFiltersOk = l1Long and l2Long and l3Long and extLongOk and lvlLongOk
  335. bool shortFiltersOk = l1Short and l2Short and l3Short and extShortOk and lvlShortOk
  336.  
  337. bool longCounter = IS_SCALP ? (close < close[1] and low < low[1]) : flowState == -1
  338. bool longRealign = IS_SCALP ? (close > high[1] and close > open) : flowState == 1
  339. bool shortCounter = IS_SCALP ? (close > close[1] and high > high[1]) : flowState == 1
  340. bool shortRealign = IS_SCALP ? (close < low[1] and close < open) : flowState == -1
  341.  
  342. var PullbackSetup longSetup = PullbackSetup.new(dir = 1)
  343. var PullbackSetup shortSetup = PullbackSetup.new(dir = -1)
  344.  
  345. bool longEntry = false
  346. bool shortEntry = false
  347. bool longConf = false
  348. bool shortConf = false
  349.  
  350. if barstate.isconfirmed
  351. [lEntry, lConf, lInvalid] = longSetup.step(trendDir == 1, longCounter, longRealign, longFiltersOk, LONG_SIG_COL)
  352. [sEntry, sConf, sInvalid] = shortSetup.step(trendDir == -1, shortCounter, shortRealign, shortFiltersOk, SHORT_SIG_COL)
  353. if sEntry and longSetup.armed
  354. longSetup.invalidate()
  355. if lEntry and shortSetup.armed
  356. shortSetup.invalidate()
  357. longEntry := lEntry
  358. shortEntry := sEntry
  359. longConf := lConf
  360. shortConf := sConf
  361.  
  362. color flowColor = (flowState != 0 ? flowState : trendDir) >= 0 ? bullColInput : bearColInput
  363. color phaseColor = switch phase
  364. PH_STRONG_BULL => strongBullInput
  365. PH_EARLY_BULL => earlyBullInput
  366. PH_WEAK_BULL => weakBullInput
  367. PH_STRONG_BEAR => strongBearInput
  368. PH_EARLY_BEAR => earlyBearInput
  369. => weakBearInput
  370. color ribbonColor = IS_SCALP ? phaseColor : flowColor
  371. color trendColor = trendDir >= 0 ? LONG_SIG_COL : SHORT_SIG_COL
  372.  
  373. pFastOuter = plot(showRibbonInput ? fastOuter : na, "Ribbon Fast Outer", color = color.new(ribbonColor, 75), linewidth = 1)
  374. pFastInner = plot(showRibbonInput ? fastInner : na, "Ribbon Fast Inner", color = color.new(ribbonColor, 55), linewidth = 1)
  375. plot(showRibbonInput ? center : na, "Trend Average Glow", color = color.new(ribbonColor, 80), linewidth = 5, display = display.pane)
  376. pCenter = plot(showRibbonInput ? center : na, "Trend Average", color = ribbonColor, linewidth = 2)
  377. pSlowInner = plot(showRibbonInput ? slowInner : na, "Ribbon Slow Inner", color = color.new(ribbonColor, 55), linewidth = 1)
  378. pSlowOuter = plot(showRibbonInput ? slowOuter : na, "Ribbon Slow Outer", color = color.new(ribbonColor, 75), linewidth = 1)
  379.  
  380. fill(pFastOuter, pFastInner, color = color.new(ribbonColor, math.min(100, fillTranspInput + 6)), title = "Ribbon Fill Fast Outer")
  381. fill(pFastInner, pCenter, color = color.new(ribbonColor, fillTranspInput), title = "Ribbon Fill Fast Inner")
  382. fill(pCenter, pSlowInner, color = color.new(ribbonColor, fillTranspInput), title = "Ribbon Fill Slow Inner")
  383. fill(pSlowInner, pSlowOuter, color = color.new(ribbonColor, math.min(100, fillTranspInput + 6)), title = "Ribbon Fill Slow Outer")
  384.  
  385. float trkLow = ta.lowest(low, trackLenInput)
  386. float trkHigh = ta.highest(high, trackLenInput)
  387. var float tracker = na
  388. if trendDir == 1
  389. tracker := nz(trendDir[1]) != 1 or na(tracker) ? trkLow : math.max(tracker, trkLow)
  390. else if trendDir == -1
  391. tracker := nz(trendDir[1]) != -1 or na(tracker) ? trkHigh : math.min(tracker, trkHigh)
  392. bool trackerFlip = trendDir != nz(trendDir[1])
  393. plot(showTrackerInput and not trackerFlip ? tracker : na, "Trend Tracker", color = trendColor, linewidth = 2, style = plot.style_steplinebr)
  394.  
  395. bgcolor(showBgInput ? color.new(trendColor, 90) : na, title = "Trend Background")
  396. barcolor(candleInput ? ribbonColor : na, title = "Trend Candles")
  397.  
  398. bool bullTrend = trendDir == 1 and nz(trendDir[1]) == -1
  399. bool bearTrend = trendDir == -1 and nz(trendDir[1]) == 1
  400. bool bullMomentum = phase == PH_STRONG_BULL and nz(phase[1]) != PH_STRONG_BULL
  401. bool bearMomentum = phase == PH_STRONG_BEAR and nz(phase[1]) != PH_STRONG_BEAR
  402.  
  403. alertcondition(longEntry, "Long Entry", "Trend Average (Zeiierman): Long Entry on {{ticker}} ({{interval}}) at {{close}}")
  404. alertcondition(shortEntry, "Short Entry", "Trend Average (Zeiierman): Short Entry on {{ticker}} ({{interval}}) at {{close}}")
  405. alertcondition(longConf, "Long Conf", "Trend Average (Zeiierman): Long Conf on {{ticker}} ({{interval}}) at {{close}}")
  406. alertcondition(shortConf, "Short Conf", "Trend Average (Zeiierman): Short Conf on {{ticker}} ({{interval}}) at {{close}}")
  407. alertcondition(bullTrend, "Bullish Trend", "Trend Average (Zeiierman): Bullish Trend on {{ticker}} ({{interval}})")
  408. alertcondition(bearTrend, "Bearish Trend", "Trend Average (Zeiierman): Bearish Trend on {{ticker}} ({{interval}})")
  409. alertcondition(bullMomentum, "Bullish Momentum", "Trend Average (Zeiierman): Strong Bullish Momentum on {{ticker}} ({{interval}})")
  410. alertcondition(bearMomentum, "Bearish Momentum", "Trend Average (Zeiierman): Strong Bearish Momentum on {{ticker}} ({{interval}})")
  411.  
  412. string ALERT_TAG = "Trend Average (Zeiierman): "
  413. if longEntry
  414. alert(ALERT_TAG + "Long Entry | " + syminfo.ticker + " | " + timeframe.period + " | " + str.tostring(close, format.mintick), alert.freq_once_per_bar_close)
  415. if shortEntry
  416. alert(ALERT_TAG + "Short Entry | " + syminfo.ticker + " | " + timeframe.period + " | " + str.tostring(close, format.mintick), alert.freq_once_per_bar_close)
  417. if longConf
  418. alert(ALERT_TAG + "Long Conf | " + syminfo.ticker + " | " + timeframe.period + " | " + str.tostring(close, format.mintick), alert.freq_once_per_bar_close)
  419. if shortConf
  420. alert(ALERT_TAG + "Short Conf | " + syminfo.ticker + " | " + timeframe.period + " | " + str.tostring(close, format.mintick), alert.freq_once_per_bar_close)
  421. if bullTrend
  422. alert(ALERT_TAG + "Bullish Trend | " + syminfo.ticker + " | " + timeframe.period, alert.freq_once_per_bar_close)
  423. if bearTrend
  424. alert(ALERT_TAG + "Bearish Trend | " + syminfo.ticker + " | " + timeframe.period, alert.freq_once_per_bar_close)
  425. if bullMomentum
  426. alert(ALERT_TAG + "Strong Bullish Momentum | " + syminfo.ticker + " | " + timeframe.period, alert.freq_once_per_bar_close)
  427. if bearMomentum
  428. alert(ALERT_TAG + "Strong Bearish Momentum | " + syminfo.ticker + " | " + timeframe.period, alert.freq_once_per_bar_close)
Advertisement
Add Comment
Please, Sign In to add comment