Advertisement
PineCoders

Signs of The Times

Dec 15th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.92 KB | None | 0 0
  1. //@version=4
  2. //@author=LucF
  3.  
  4. // Signs of The Times [LucF]
  5. // v0.5, 2019.12.15 03:54 — LucF
  6.  
  7. // Calculates a signal based on individual bar states and proximity rules with very close neighbors.
  8. // - Two higher timeframes can be calculated in 3 different ways: pre-defined steps from current TF, multiples of current TF or fixed.
  9. // - Alerts can be created on any combination of confirmed and/or filtered markers.
  10. // - A signal plot providing entries for the PineCoders Backtesting & Trading Engine is included.
  11.  
  12. // This indicator's page on TV:
  13.  
  14. study("Signs of The Times (SOTT) [LucF]", "Signs of The Times", true)
  15.  
  16.  
  17. // ———————————————————— Colors
  18. myGreenRaw = color.new(#00FF00,0), myGreenMedium = color.new(#00FF00,40), myGreenSemiDark = color.new(#00FF00,62), myGreenDark = color.new(#00FF00,75), myGreenDarkDark = color.new(#00FF00,82), myGreenDarkDarkDark = color.new(#00FF00,91)
  19. myRedRaw = color.new(#FF0000,0), myRedMedium = color.new(#FF0000,30), myRedSemiDark = color.new(#FF0000,50), myRedDark = color.new(#FF0000,75), myRedDarkDark = color.new(#FF0000,80), myRedDarkDarkDark = color.new(#FF0000,87)
  20. MyGreenBackGround = color.new(#00FF00,93), MyRedBackGround = color.new(#FF0000,90)
  21. invisible = color.new(color.white,100), myBlack = color.new(color.black,0)
  22.  
  23.  
  24. // {
  25. // ———————————————————— Inputs
  26. f_01(_bool) => _bool ? 1 : 0
  27.  
  28. TF1 = "1. Discrete Steps", TF2 = "2. Multiple of current TF", TF3 = "3. Fixed TF"
  29. HB1 = "Heaviest", HB2 = "Heavier", HB3 = "Normal", HB4 = "Subtler", HB5 = "Hidden"
  30. var cStep = 0.5
  31. var cMinVal = 0.0
  32.  
  33. _2 = input(false, "═══════════ Display ══════════")
  34. instantSott = input(false, "Instant SOTT")
  35. showWeaknesses = input(true, "Highlight weaknesses")
  36. breadthBrightness = input(HB3, "SOTT Breadth Display", options = [HB1, HB2, HB3, HB4, HB5])
  37. htfBrightness = input(HB3, "HTF Cloud Display", options = [HB1, HB2, HB3, HB4, HB5])
  38. reduceLength = input(true, "Accelerate on drops")
  39. showBgReducedLength = input(false, "Show background on drops")
  40. _4 = input(false, "══════════ Parameters ════════")
  41. sottLength = input(20, "SOTT sum length", minval = 1)
  42. reduceLengthDivisor = input(4, "SOTT drop accelerated length divisor", minval = 1)
  43. sottAmplification = input(4., "Signal amplification", minval = 1.)
  44. htfType = input(TF2, "HTF Selection", options=[TF1, TF2, TF3])
  45. htfType2a = input(12, "...2. Multiple of Current TF for HTF1", minval = 1)
  46. htfType2b = input(24, "...2. Multiple of Current TF for HTF2", minval = 1)
  47. htfType3a = input("D", "...3. Fixed HTF1", type = input.resolution)
  48. htfType3b = input("W", "...3. Fixed HTF2", type = input.resolution)
  49. atoms = input(true, "══════ Atomic Components ═════")
  50. atom01 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "Up Bar")
  51. atom02 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "Volume Bump")
  52. atom03 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "Wicks < Body")
  53. atom04 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "tr > tr[1]")
  54. atom05 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "Up Bar and WickHi > WickLo")
  55. atom06 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "Close > Previous close")
  56. atom07 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "High > Previous high")
  57. atom08 = f_01(atoms) * input(1.0, minval = cMinVal, step = cStep, title = "Low > Previous low")
  58. moles = input(true, "═════ Molecular Components ════")
  59. mole01 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Double volume bumps")
  60. mole02 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Pivot")
  61. mole03 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Consecutive up bars")
  62. mole04 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Gaps")
  63. mole05 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Down then good up bar")
  64. mole06 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Two rising close")
  65. mole07 = f_01(moles) * input(1.0, minval = cMinVal, step = cStep, title = "Three rising closes")
  66. // }
  67.  
  68.  
  69. // ———————————————————— Functions
  70. // {
  71. // ————— Converts current timeframe into minutes of type float.
  72. f_resInMinutes() =>
  73. _resInMinutes = timeframe.multiplier * (
  74. timeframe.isseconds ? 1. / 60. :
  75. timeframe.isminutes ? 1. :
  76. timeframe.isdaily ? 1440. :
  77. timeframe.isweekly ? 10080. :
  78. timeframe.ismonthly ? 43800. : na)
  79.  
  80. // ————— Returns a multiple of current TF as a string in period format usable with "security()".
  81. f_multipleOfRes(_mult) =>
  82. // Convert target timeframe to minutes.
  83. _targetResInMin = f_resInMinutes() * _mult
  84. // Find best way to express the TF.
  85. _targetResInMin <= 0.0417 ? "1S" :
  86. _targetResInMin <= 0.167 ? "5S" :
  87. _targetResInMin <= 0.376 ? "15S" :
  88. _targetResInMin <= 0.751 ? "30S" :
  89. _targetResInMin <= 1440 ? tostring(round(_targetResInMin)) :
  90. _targetResInMin <= 43800 ? tostring(round(min(_targetResInMin / 1440, 365))) + "D" :
  91. tostring(round(min(_targetResInMin / 43800, 12))) + "M"
  92.  
  93. // ————— Returns resolution of _resolution period in minutes.
  94. f_tfResInMinutes(_resolution) =>
  95. // _resolution: resolution of other timeframe (in timeframe.period string format).
  96. _mult = security(syminfo.tickerid, _resolution, timeframe.multiplier)
  97. _res = security(syminfo.tickerid, _resolution, timeframe.isseconds ? 1 : timeframe.isintraday ? 2 : timeframe.isdaily ? 3 : timeframe.isweekly ? 4 : timeframe.ismonthly ? 5 : na)
  98. _return =
  99. _res == 1 ? _mult / 60 :
  100. _res == 2 ? _mult :
  101. _res == 3 ? _mult * 1440 :
  102. _res == 4 ? _mult * 10080 :
  103. _res == 5 ? _mult * 43800 : na
  104.  
  105. // ————— Given current TF, returns next step1 and step2 of higher TF (HTF1 and HTF2).
  106. f_resNextStep1(_res) =>
  107. // _res: current TF in minutes.
  108. _step1 =
  109. _res <= 1 ? "60" :
  110. _res <= 360 ? "1D" :
  111. _res <= 1440 ? "1W" :
  112. _res <= 10080 ? "1M" : "12M"
  113. f_resNextStep2(_res) =>
  114. _step2 =
  115. _res <= 1 ? "1D" :
  116. _res <= 360 ? "1W" :
  117. _res <= 1440 ? "1M" : "12M"
  118.  
  119. // ————— Print a label at end of chart.
  120. f_print(_txt) => t = time + (time - time[1]) * 3, var _lbl = label.new(t, high, _txt, xloc.bar_time, yloc.price, #00000000, label.style_none, color.gray, size.large), label.set_xy(_lbl, t, high + 3 * tr)
  121. // }
  122.  
  123.  
  124. // ———————————————————— Indicator calcs
  125. // {
  126. // ————— Resolution calcs.
  127. // Get user-defined HTF.
  128. var resMultiple1 = f_multipleOfRes(htfType2a)
  129. var resMultiple2 = f_multipleOfRes(htfType2b)
  130. var resStep1 = f_resNextStep1(f_resInMinutes())
  131. var resStep2 = f_resNextStep2(f_resInMinutes())
  132. var htf1 = htfType == TF1 ? resStep1 : htfType == TF2 ? resMultiple1 : htfType3a
  133. var htf2 = htfType == TF1 ? resStep2 : htfType == TF2 ? resMultiple2 : htfType3b
  134. // If current res is not lower than HTF, print warning label (background at the end of plots will also show in red).
  135. if barstate.islast
  136. // Only call f_tfResInMinutes() on last bar because it uses "security()" calls.
  137. currentResIsNotLower = f_resInMinutes() >= f_tfResInMinutes(htf1)
  138. if currentResIsNotLower
  139. f_print("Chart resolution\nmust be lower than " + htf1)
  140.  
  141. // ————— Candle components and states.
  142. barUp = close > open
  143. barDn = close < open
  144. volUp = volume > volume[1]
  145. nonZeroValue = 10e-10
  146. noBody = close == open
  147. body = abs(close - open)
  148. wickLo = min(open, close) - low
  149. wickHi = high - max(open, close)
  150. nonZeroBody = open != close ? body : nonZeroValue
  151. nonZeroWickLo = min(open, close) != low ? wickLo : nonZeroValue
  152. nonZeroWickHi = max(open, close) != high ? wickHi : nonZeroValue
  153. fullHeight = high - low
  154. noMovement = high == low
  155.  
  156. // ————— Helper functions.
  157. // Returns bull, bear or neutral value given conditions.
  158. f_bbn(_bullCond, _bearCond, _val) => _bullCond ? _val : _bearCond ? - _val : 0
  159. // True when source is higher than on previous bar.
  160. f_isUp(_src) => rising(_src, 1)
  161. // True when source is lower than on previous bar.
  162. f_isDn(_src) => falling(_src, 1)
  163.  
  164. // —————————— Functions returning the weight (_w) if condition is bullish, the negative weight if it is bearish, 0 if neutral.
  165. // ————— Atoms.
  166. // Bar up/dn
  167. f_atom01(_w) => f_bbn(barUp, barDn, _w)
  168. // Volume bump
  169. f_atom02(_w) => volUp ? f_bbn(barUp, barDn, _w) : 0
  170. // Body > wicks
  171. f_atom03(_w) => wickHi + wickLo < body ? f_bbn(barUp, barDn, _w) : 0
  172. // True range increase
  173. f_atom04(_w) => tr > tr[1] ? f_bbn(barUp, barDn, _w) : 0
  174. //
  175. f_atom05(_w) => wickLo < body and wickHi < body ? barUp and wickHi > wickLo ? _w : barDn and wickLo > wickHi ? - _w : 0 : 0
  176. // Close > previous close
  177. f_atom06(_w) => f_bbn(f_isUp(close), f_isDn(close), _w)
  178. // High > previous high
  179. f_atom07(_w) => f_bbn(f_isUp(high), f_isDn(high), _w)
  180. // Low > previous low
  181. f_atom08(_w) => f_bbn(f_isUp(low), f_isDn(low), _w)
  182.  
  183. // ————— Molecules.
  184. // Double volume bump
  185. f_mole01(_w) => volUp and barUp and volUp[1] and barUp[1] ? _w : volUp and barDn and volUp[1] and barDn[1] ? -_w : 0
  186. // Pivot
  187. f_mole02(_w) => f_bbn(pivotlow(close, 1, 1), pivothigh(close, 1, 1), _w)
  188. // Consecutive bars
  189. f_mole03(_w) => f_bbn(barUp and barUp[1], barDn and barDn[1], _w)
  190. // Gaps
  191. f_mole04(_w) => f_bbn(open > close[1], open < close[1], _w)
  192. // Down then good up bar
  193. f_mole05(_w) => f_bbn(barDn[1] and barUp and close > open[1], barUp[1] and barDn and close < open[1], _w)
  194. // Two rising closes
  195. f_mole06(_w) => f_bbn(f_isUp(close) and f_isUp(close[1]), f_isDn(close) and f_isDn(close[1]), _w)
  196. // Three rising closes
  197. f_mole07(_w) => f_bbn(f_isUp(close) and f_isUp(close[1]) and f_isUp(close[2]), f_isDn(close) and f_isDn(close[1]) and f_isDn(close[2]), _w)
  198.  
  199. // ————— Signs Of The Times (SOTT) max/min range (+/- this value is the max range of the instant SOTT value).
  200. var maxNowValue =
  201. atom01 +
  202. atom02 +
  203. atom03 +
  204. atom04 +
  205. atom05 +
  206. atom06 +
  207. atom07 +
  208. atom08 +
  209. mole01 +
  210. mole02 +
  211. mole03 +
  212. mole04 +
  213. mole05 +
  214. mole06 +
  215. mole07 +
  216. 0
  217.  
  218. // ————— SOTT instant value.
  219. sottNow =
  220. f_atom01(atom01) +
  221. f_atom02(atom02) +
  222. f_atom03(atom03) +
  223. f_atom04(atom04) +
  224. f_atom05(atom05) +
  225. f_atom06(atom06) +
  226. f_atom07(atom07) +
  227. f_atom08(atom08) +
  228. f_mole01(mole01) +
  229. f_mole02(mole02) +
  230. f_mole03(mole03) +
  231. f_mole04(mole04) +
  232. f_mole05(mole05) +
  233. f_mole06(mole06) +
  234. f_mole07(mole07) +
  235. 0
  236.  
  237. // ————— Calc sum of SOTT and that value's proportion of max weight value, in %.
  238. var sottSumReducedLength = max(sottLength / reduceLengthDivisor, 1)
  239. sottPct = sottNow / maxNowValue
  240. sottSum = sum(sottNow, sottLength)
  241. sottSumReduced = sum(sottNow, sottSumReducedLength)
  242. sottSumDropping = sottSum > 0 and sottSumReduced <= 0
  243. sottSumRedPct = sottSumReduced / (sottSumReducedLength * maxNowValue)
  244. sottSumPct = sottSum / (sottLength * maxNowValue)
  245. sottForCloud = instantSott ? sottPct : reduceLength and sottSumDropping ? sottSumRedPct : sottSumPct
  246.  
  247. // ————— Calc cloud from percentage of sott.
  248. cloudBase = close
  249. atrBase = atr(3)
  250. sottCloud = cloudBase + (sottForCloud * atrBase * sottAmplification)
  251. sottCloudMax = cloudBase + (atrBase * sottAmplification)
  252. sottCloudMin = cloudBase - (atrBase * sottAmplification)
  253.  
  254. // ————— HTF values.
  255. sottCloudHtf1 = security(syminfo.tickerid, htf1, sottCloud[1], lookahead = barmerge.lookahead_on)
  256. sottCloudHtf2 = security(syminfo.tickerid, htf2, sottCloud[1], lookahead = barmerge.lookahead_on)
  257.  
  258. // ————— Cloud states.
  259. sottCloudUp = sottCloud > cloudBase
  260. sottCloudDn = sottCloud < cloudBase
  261. sottCloudBull = sottCloudUp and sottCloudUp[1]
  262. sottCloudBear = sottCloudDn and sottCloudDn[1]
  263. sottCloudHtf1Up = sottCloudHtf1 > cloudBase
  264. sottCloudHtf1Dn = sottCloudHtf1 < cloudBase
  265. sottCloudHtf1Bull = sottCloudHtf1Up and sottCloudHtf1Up[1]
  266. sottCloudHtf1Bear = sottCloudHtf1Dn and sottCloudHtf1Dn[1]
  267. sottCloudHtf2Up = sottCloudHtf2 > cloudBase
  268. sottCloudHtf2Dn = sottCloudHtf2 < cloudBase
  269. sottCloudHtf2Bull = sottCloudHtf2Up and sottCloudHtf2Up[1]
  270. sottCloudHtf2Bear = sottCloudHtf2Dn and sottCloudHtf2Dn[1]
  271. // }
  272.  
  273.  
  274. // ———————————————————— Plots
  275. // {
  276. // ————— SOTT Cloud.
  277. // SOTT cloud colors.
  278. cWeak = #FF9900FF
  279. cCloudBull = #33CC00FF
  280. cCloudBullWeak = showWeaknesses ? cWeak : #339900FF
  281. cCloudBear = #990000FF
  282. cCloudBearWeak = showWeaknesses ? cWeak : #800000FF
  283. cCloudNeut = color.new(color.gray, 70)
  284. // SOTT Cloud.
  285. p_cloudBase = plot(cloudBase, "Cloud base", invisible)
  286. p_sottCloud = plot(sottCloud, "Cloud line", invisible)
  287. fill(p_cloudBase, p_sottCloud, sottCloudBull ? cCloudBull : sottCloudBear ? cCloudBear : sottCloudUp ? cCloudBullWeak : sottCloudDn ? cCloudBearWeak : cWeak, title = "SOTT cloud fill")
  288.  
  289. // ————— Breadth cloud.
  290. var cBreadth = breadthBrightness == HB1 ? color.new(color.gray, 80) : breadthBrightness == HB2 ? color.new(color.gray, 85) : breadthBrightness == HB3 ? color.new(color.gray, 88) : color.new(color.gray, 92)
  291. p_cloudMax = plot(breadthBrightness != HB5 ? sottCloudBull ? sottCloudMax : sottCloud : na, "SOTT breadth cloud max", invisible)
  292. p_cloudMin = plot(breadthBrightness != HB5 ? sottCloudBull ? sottCloud : sottCloudMin : na, "SOTT breadth cloud min", invisible)
  293. fill(p_cloudMax, p_cloudMin, cBreadth, title = "SOTT breadth cloud fill")
  294.  
  295. // ————— HTF clouds.
  296. topCloud = max(sottCloud, cloudBase)
  297. botCloud = min(sottCloud, cloudBase)
  298. var cCloudHtf1Bull = htfBrightness == HB1 ? color.new(color.maroon, 80) : htfBrightness == HB2 ? color.new(color.maroon, 87) : htfBrightness == HB3 ? color.new(color.maroon, 90) : color.new(color.maroon, 93)
  299. var cCloudHtf1Bear = htfBrightness == HB1 ? color.new(color.green, 83) : htfBrightness == HB2 ? color.new(color.green, 90) : htfBrightness == HB3 ? color.new(color.green, 93) : color.new(color.green, 96)
  300. var cCloudHtf2Bull = htfBrightness == HB1 ? color.new(color.maroon, 75) : htfBrightness == HB2 ? color.new(color.maroon, 82) : htfBrightness == HB3 ? color.new(color.maroon, 84) : color.new(color.maroon, 88)
  301. var cCloudHtf2Bear = htfBrightness == HB1 ? color.new(color.green, 80) : htfBrightness == HB2 ? color.new(color.green, 87) : htfBrightness == HB3 ? color.new(color.green, 90) : color.new(color.green, 93)
  302. p_cloudHtf1Base = plot(sottCloudHtf1Bull ? topCloud : botCloud, "Cloud HTF1 base", invisible)
  303. p_cloudHtf2Base = plot(sottCloudHtf2Bull ? topCloud : botCloud, "Cloud HTF2 base", invisible)
  304. p_cloudHtf1 = plot(htfBrightness != HB5 ? sottCloudHtf1 : na, "Cloud HTF1", invisible)
  305. p_cloudHtf2 = plot(htfBrightness != HB5 ? sottCloudHtf2 : na, "Cloud HTF2", invisible)
  306. fill(p_cloudHtf2Base, p_cloudHtf2, sottCloudHtf2Bull ? cCloudHtf2Bull : cCloudHtf2Bear, title = "Clouf HTF2 fill")
  307. fill(p_cloudHtf1Base, p_cloudHtf1, sottCloudHtf1Bull ? cCloudHtf1Bull : cCloudHtf1Bear, title = "Clouf HTF1 fill")
  308.  
  309. // ————— Background.
  310. bgcolor(showBgReducedLength and sottSumDropping ? MyRedBackGround : na, title = "Background")
  311. // }
  312.  
  313.  
  314.  
  315. // f_print(htf1 + "-" + htf2)
  316. // plotchar(sottSum, "sottSum", "", location.top)
  317. // plotchar(sottSumReduced, "sottSumReduced", "", location.top)
  318. // plotchar(sottSumDropping, "sottSumDropping", "", location.top)
  319. // plotchar(sottSumReducedLength, "sottSumReducedLength", "", location.top)
  320. // plotchar(sottNow, "sottNow", "", location.top)
  321. // plotchar(sottSum, "sottSum", "", location.top)
  322. // plotchar((sottLength * maxNowValue), "(sottLength * maxNowValue)", "", location.top)
  323. // plotchar(sottPct*100, "sottPct*100", "", location.top)
  324.  
  325. // plotchar(atrBase, "atrBase", "", location.top)
  326. // plotchar(sottPct, "sottPct", "", location.top)
  327. // plotchar(sottNow, "sottNow", "", location.top)
  328. // plotchar(maxNowValue, "maxNowValue", "", location.top)
  329.  
  330. // sottForCloudHtf1 = security(syminfo.tickerid, htf1, sottForCloud[1], lookahead = barmerge.lookahead_on)
  331. // sottForCloudHtf2 = security(syminfo.tickerid, htf2, sottForCloud[1], lookahead = barmerge.lookahead_on)
  332. // plotchar(sottCloudHtf1, "sottCloudHtf1", "", location.top)
  333. // plotchar(sottCloudHtf2, "sottCloudHtf2", "", location.top)
  334. // plotchar(sottForCloudHtf1, "sottForCloudHtf1", "", location.top)
  335. // plotchar(sottForCloudHtf2, "sottForCloudHtf2", "", location.top)
  336. // }
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345. // _2 = input(false, "═══════════ Display ══════════")
  346. // rsiType = input(RS4, "RSI", options = [RS1, RS2, RS3, RS4])
  347. // showRsi = rsiType != RS1
  348. // bbType = input(RS4, "...BBs", options = [RS1, RS2, RS3, RS4])
  349. // showBb = bbType != RS1
  350. // rsiTypeHtf = input(RS4, "Higher Timeframe (HTF) RSI", options = [RS1, RS2, RS3, RS4])
  351. // showRsiHtf = rsiTypeHtf != RS1
  352. // bbTypeHtf = input(RS4, "...BBs", options = [RS1, RS2, RS3, RS4])
  353. // showBbHtf = bbTypeHtf != RS1
  354. // deltaRsiType = input(RS4, "Delta RSIs", options = [RS1, RS2, RS3, RS4])
  355. // showDeltaRsi = deltaRsiType != RS1
  356. // bbTypeDelta = input(RS4, "...BBs", options = [RS1, RS2, RS3, RS4])
  357. // showBbDelta = bbTypeDelta != RS1
  358. // statusType = input(BG02, "Status", options = [BG01, BG02, BG03, BG04, BG05, BG06, BG07, BG08, BG09, BG10])
  359. // bgType = input(BG09, "Background", options = [BG01, BG02, BG03, BG04, BG05, BG06, BG07, BG08, BG09, BG10])
  360. // showFilter = input(false, "Show Filter State")
  361. // showMinMax = input(false, "Show Min/Max Historical RSI Levels")
  362. // showOsOb = input(false, "Show Overbought/Oversold Levels")
  363. // smoothHtf = input(true, "Smooth HTF plots")
  364. // _3 = input(false, " ")
  365. // _4 = input(false, "═══════════ Markers ══════════")
  366. // markerDirection = input(MD1, "Direction", options = [MD1, MD2, MD3])
  367. // longsOnly = markerDirection == MD2
  368. // shortsOnly = markerDirection == MD3
  369. // showMarker1 = input(false, "1. State Transition")
  370. // marker1Trans = input(BG01, "...Transition", options = [BG01, BG02, BG03, BG04, BG05, BG06, BG07, BG08, BG09, BG10])
  371. // marker1Confirm = input(BG01, "...Confirmed by", options = [BG01, BG02, BG03, BG04, BG05, BG06, BG07, BG08, BG09, BG10])
  372. // marker1Filter = input(false, "...Filtered")
  373. // showMarker2 = input(false, "2. Crosses")
  374. // marker2Signal = input(LN1, "...Signal", options = [LN1, LN2, LN3, LN4, LN5, LN6, LN7, LN8])
  375. // marker2Cross = input(LN1, "...Crosses", options = [LN1, LN2, LN3, LN4, LN5, LN6])
  376. // marker2Confirm = input(BG01, "...Confirmed by", options = [BG01, BG02, BG03, BG04, BG05, BG06, BG07, BG08, BG09, BG10])
  377. // marker2Filter = input(false, "...Filtered")
  378. // showMarker3 = input(false, "3. Pivots")
  379. // marker3Signal = input(LN1, "...Pivot Signal", options = [LN1, LN2, LN3, LN4, LN5, LN6])
  380. // marker3Confirm = input(BG01, "...Confirmed by", options = [BG01, BG02, BG03, BG04, BG05, BG06, BG07, BG08, BG09, BG10])
  381. // marker3Filter = input(false, "...Filtered")
  382. // _5 = input(false, " ")
  383. // _6 = input(false, "═══════════ Filters ══════════")
  384. // filter1 = input(false, "1. Bar direction = Trade direction")
  385. // filter2 = input(false, "2. Bar close higher/lower than previous")
  386. // filter3 = input(false, "3. Rising Volume")
  387. // filter4 = input(false, "4. Volume over MA")
  388. // filter5 = input(false, "5. Chandelier")
  389. // _7 = input(false, " ")
  390. // _8 = input(false, "══════════ Parameters ════════")
  391. // rsiSrc = input(hlc3, "RSI Source")
  392. // rsiLength = input(20, "RSI Length", minval = 2)
  393. // rsiLengthHtf = input(40, "HTF RSI Length", minval = 2)
  394. // obLevel = input(85, "Overbought Level", minval = 50)
  395. // osLevel = input(20, "Oversold Level", minval = 0)
  396. // bbLength = input(7, "BB Length", minval = 2)
  397. // bbMult = input(1.0, "BB Multiplier", minval = 0.0, step = 0.1)
  398. // bbClamp = input(1.0, "BB clamping to centerline (%)", minval = 0.0, step = 0.5) / 100.
  399. // htfType = input(TF1, "HTF Selection", options=[TF1, TF2, TF3])
  400. // htfType2 = input(24, "...2. Multiple of Current TF", minval = 1)
  401. // htfType3 = input("D", "...3. Fixed TF", type = input.resolution)
  402. // filter4Len = input(20, "Volume MA Length", minval=2)
  403. // filter5Len = input(20, "Chandelier Length", minval=2)
  404. // filter5Mult = input(3, "Chandelier ATR Multiple", minval=0, step=0.25)
  405. // marker3PivotL = input(4, "Marker 3 Pivot Left Bars", minval=1)
  406. // marker3PivotR = input(2, "Marker 3 Pivot Right Bars", minval=1)
  407. // _9 = input(false, " ")
  408. // }
  409.  
  410.  
  411.  
  412. // ---------- Bearish Candles
  413. // // These patterns are identified at following candle so prints need to be offset.
  414. // atrBars = atr(7)
  415. // darkCloudCover = barDn[1] and barUp[2] and close[1]<open[2]+(body[2]/2) and close[1]>open[2] and high[1]>high[2] and high<high[1] and body[2]>atrBars*1.5
  416. // eveningStar = barDn and barDn[1] and barUp[2] and close[1]>=close[2] and close[1]>=open and body[2]>wickHi[2] and body[2]>wickLo[2] and close<open[2]+(body[2]/2)
  417. // shootingStar = fullHeight>3*nonZeroBody and high>high[1] and wickHi>wickLo and wickHi>atrBars*1.5
  418. // // These patterns don't require offsetting.
  419. // engulfingPattern = max(close[1],open[1])<max(close,open) and min(close[1],open[1])>min(close,open) and body>body[1] and barDn and barUp[1]
  420. // hangingMan = open[1]>open[2] and close[1]>close[2] and wickHi[1]<=body[1] and wickLo[1]>1.2*body[1] and rising(high[1],5) and close<min(open[1],close[1])
  421. // harami = min(open,close)>min(open[1],close[1]) and max(open,close)<max(open[1],close[1]) and (wickHi>body or wickLo>body) and body[1]>body*2
  422. // // ---------- Other Candles
  423. // doji = noMovement or (fullHeight>5*nonZeroBody and (wickLo>body or wickHi>body))
  424. // hammer = fullHeight>3*body and wickLo>3*nonZeroBody and body>2*wickHi
  425.  
  426. // TweezerTolerance = 0.06
  427. // PinFactor = 1.25
  428. // UPL = false
  429. // UPH = false
  430. // UPL := pivotlow(close,2,2) and RedCandle[2] and GreenCandle //and GreenCandle[1]
  431. // UPH := pivothigh(close,2,2) and GreenCandle[2] and RedCandle //and RedCandle[1]
  432. // NoPHInBetween = barssince(UPL[1])<barssince(UPH[1])
  433. // NoPLInBetween = barssince(UPH[1])<barssince(UPL[1])
  434. // IncreasingVolume = volume>volume[1]
  435. // IncreasingVolume2 = IncreasingVolume and IncreasingVolume[1]
  436. // InsideBar = high<high[1] and low>low[1]
  437.  
  438. // InsideBarUp = InsideBar and rising(R2,2) and GreenCandle
  439. // InsideBarDn = InsideBar and falling(R2,2) and RedCandle
  440. // ScalingUp = GreenCandle and WickLo+WickHi<Body and WickLo<WickHi and IncreasingVolume
  441. // ScalingDn = RedCandle and WickLo+WickHi<Body and WickLo>WickHi and IncreasingVolume
  442. // ScalingUp2 = ScalingUp and ScalingUp[1]
  443. // ScalingDn2 = ScalingDn and ScalingDn[1]
  444. // TweezerTop = NonZeroWickHi and NonZeroWickHi[1] and abs(high-high[1])<AbsFullHeight*TweezerTolerance and RedCandle and close<close[1]
  445. // TweezerBot = NonZeroWickLo and NonZeroWickLo[1] and abs(low-low[1])<AbsFullHeight*TweezerTolerance and GreenCandle and close>close[1]
  446. // PinTop = WickHi>ATR1*PinFactor and high>high[1] //and GreenCandle[1] and WickHi>2.5*(NonZeroBody+WickLo)
  447. // PinBot = WickLo>ATR1*PinFactor and low<low[1] //and GreenCandle[1] and WickHi>2.5*(NonZeroBody+WickLo)
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454. // }
  455.  
  456.  
  457. // // ———————————————————— Markers
  458. // // {
  459. // f_signal(_signal, _direction) =>
  460. // // Returns the value of a signal corresponding to LN? static.
  461. // // Dependencies: LN?, signals/levels.
  462. // _signal == LN1 ? myRsi :
  463. // _signal == LN2 ? myRsiHtf :
  464. // _signal == LN3 ? deltaRsi :
  465. // _signal == LN4 ? _direction > 0 ? bbLo : bbHi :
  466. // _signal == LN5 ? _direction > 0 ? bbLoHtf : bbHiHtf :
  467. // _signal == LN6 ? _direction > 0 ? bbLoDelta : bbHiDelta :
  468. // _signal == LN7 ? _direction > 0 ? osLevel : obLevel :
  469. // _signal == LN8 ? ctrLine : na
  470.  
  471. // // ————— Conditions
  472. // C1U = f_bull(marker1Trans) and not f_bull(marker1Trans)[1] and (marker1Confirm == BG01 or f_bull(marker1Confirm)) and (not marker1Filter or filterLong)
  473. // C1D = f_bear(marker1Trans) and not f_bear(marker1Trans)[1] and (marker1Confirm == BG01 or f_bear(marker1Confirm)) and (not marker1Filter or filterShort)
  474. // C2U = crossover(f_signal(marker2Signal, 1), f_signal(marker2Cross, 1)) and (marker2Confirm == BG01 or f_bull(marker2Confirm)) and (not marker2Filter or filterLong)
  475. // C2D = crossunder(f_signal(marker2Signal, -1), f_signal(marker2Cross, -1)) and (marker2Confirm == BG01 or f_bear(marker2Confirm)) and (not marker2Filter or filterShort)
  476. // C3U = pivotlow(f_signal(marker3Signal, 1), marker3PivotL, marker3PivotR) > ctrLine and (marker3Confirm == BG01 or f_bull(marker3Confirm)) and (not marker3Filter or filterLong)
  477. // C3D = pivothigh(f_signal(marker3Signal, -1), marker3PivotL, marker3PivotR) < ctrLine and (marker3Confirm == BG01 or f_bear(marker3Confirm)) and (not marker3Filter or filterShort)
  478.  
  479. // // ————— Assembly
  480. // A1U = showMarker1 and not shortsOnly and C1U
  481. // A1D = showMarker1 and not longsOnly and C1D
  482. // A2U = showMarker2 and not shortsOnly and C2U
  483. // A2D = showMarker2 and not longsOnly and C2D
  484. // A3U = showMarker3 and not shortsOnly and C3U
  485. // A3D = showMarker3 and not longsOnly and C3D
  486.  
  487. // // ————— Plots
  488. // plotshape(A1U, "Marker 1 Up", shape.triangleup, location.bottom, myGreenRaw, size = size.tiny, text = "1")
  489. // plotshape(A1D, "Marker 1 Dn", shape.triangledown, location.top, myRedRaw, size = size.tiny, text = "1")
  490. // plotshape(A2U, "Marker 2 Up", shape.triangleup, location.bottom, myGreenRaw, size = size.tiny, text = "2")
  491. // plotshape(A2D, "Marker 2 Dn", shape.triangledown, location.top, myRedRaw, size = size.tiny, text = "2")
  492. // plotshape(A3U, "Marker 3 Up", shape.triangleup, location.bottom, myGreenRaw, size = size.tiny, text = "3")
  493. // plotshape(A3D, "Marker 3 Dn", shape.triangledown, location.top, myRedRaw, size = size.tiny, text = "3")
  494. // // }
  495.  
  496.  
  497. // // ———————————————————— Alert
  498. // alertcondition( A1U or A1D or A2U or A2D or A3U or A3D, "Visual RSI: Configured Markers", "Visual RSI Marker")
  499.  
  500.  
  501. // // ———————————————————— Signal line (entries only) for the PineCoders Backtesting & Trading Engine
  502. // // The Engine is here: https://www.tradingview.com/script/dYqL95JB-Backtesting-Trading-Engine-PineCoders/
  503. // plot(A1U or A2U or A3U ? 2 : A1D or A2D or A3D ? -2 : na, "BTE Signal for Entries", invisible)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement