├── ADX.pscript ├── CandleReconUltimate.pscript ├── CandleReconUltimateOld.pscript ├── Divergence-for-many-indicator-v3.pscript ├── IchimokuTwistOnly.pscript ├── ImbalanceZoneFinder.pscript ├── README.md ├── Support-Resistance-Dynamic-v2.pscript ├── Support-Resistance-V2-Indicator.pscript ├── TrendLinesImproved.pscript └── TrendLinesImproved2.pscript /ADX.pscript: -------------------------------------------------------------------------------- 1 | //@version=4 2 | study("ADX and DI Improved", shorttitle="ADX and DI Improved", overlay=false) 3 | 4 | len = input(title="Length", type=input.integer, defval=14) 5 | th = input(title="threshold", type=input.integer, defval=20) 6 | 7 | TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1]))) 8 | DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0 9 | DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0 10 | 11 | float SmoothedTrueRange = na 12 | float SmoothedDirectionalMovementPlus = na 13 | float SmoothedDirectionalMovementMinus = na 14 | 15 | SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange 16 | SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus 17 | SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus 18 | 19 | DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100 20 | DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100 21 | DX = abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100 22 | ADX = sma(DX, len) 23 | 24 | plot(DIPlus, color=color.green, title="DI+") 25 | plot(DIMinus, color=color.red, title="DI-") 26 | plot(ADX, color=color.black, title="ADX") 27 | hline(th, color=color.black, linestyle=hline.style_dashed) 28 | 29 | crossUpDiplusDiminus = crossover(DIPlus, DIMinus) 30 | crossDownDiplusDiminus = crossunder(DIPlus, DIMinus) 31 | 32 | bgcolor(color=crossUpDiplusDiminus ? color.green : na, title="Tenkan Sen cross over Kijun Sen", transp=90, offset=-1) 33 | bgcolor(color=crossDownDiplusDiminus ? color.red : na, title="Tenkan Sen cross under Kijun Sen", transp=90, offset=-1) 34 | -------------------------------------------------------------------------------- /CandleReconUltimate.pscript: -------------------------------------------------------------------------------- 1 | // © KrustyHack 2 | 3 | //@version=4 4 | study("Candle Recon Ultimate", shorttitle="CRU", overlay=true) 5 | 6 | // START misc. options 7 | // 10 days high price moving average 8 | avgh10 = high[1] + high[2] + high[3] + high[4] + high[5] + high[6] + high[7] + high[8] + high[9] + high[10] / 10 9 | 10 | // 10 days low price moving average 11 | avgl10 = low[1] + low[2] + low[3] + low[4] + low[5] + low[6] + low[7] + low[8] + low[9] + low[10] / 10 12 | 13 | // Lowest low over 10 past periods 14 | minl10 = lowest(low, 10) 15 | 16 | // Highest high over 10 past periods 17 | maxh10 = highest(high, 10) 18 | 19 | // Lowest open price over 10 past periods 20 | mino10 = lowest(open, 10) 21 | 22 | // Highest open price over 10 past periods 23 | maxo10 = highest(open, 10) 24 | 25 | var displayCandlesNames = input(defval=true, title="Display candles names", type=input.bool) 26 | 27 | C_DownTrend = true 28 | C_UpTrend = true 29 | var trendRule1 = "SMA50" 30 | var trendRule2 = "SMA50, SMA200" 31 | var trendRule = input(trendRule2, "Detect Trend Based On", options=[trendRule1, trendRule2, "No detection"]) 32 | 33 | if trendRule == trendRule1 34 | priceAvg = sma(close, 50) 35 | C_DownTrend := close < priceAvg 36 | C_UpTrend := close > priceAvg 37 | 38 | if trendRule == trendRule2 39 | sma200 = sma(close, 200) 40 | sma50 = sma(close, 50) 41 | C_DownTrend := close < sma50 and sma50 < sma200 42 | C_UpTrend := close > sma50 and sma50 > sma200 43 | C_Len = 14 // ema depth for bodyAvg 44 | C_ShadowPercent = 100.0 // size of shadows 45 | C_ShadowEqualsPercent = 100.0 46 | C_DojiBodyPercent = 5.0 47 | C_Factor = 2.0 // shows the number of times the shadow dominates the candlestick body 48 | 49 | C_BodyHi = max(close, open) 50 | C_BodyLo = min(close, open) 51 | C_Body = C_BodyHi - C_BodyLo 52 | C_BodyAvg = ema(C_Body, C_Len) 53 | C_SmallBody = C_Body < C_BodyAvg 54 | C_LongBody = C_Body > C_BodyAvg 55 | C_UpShadow = high - C_BodyHi 56 | C_DnShadow = C_BodyLo - low 57 | C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body 58 | C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body 59 | C_WhiteBody = open < close 60 | C_BlackBody = open > close 61 | C_Range = high-low 62 | C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo 63 | C_BodyMiddle = C_Body / 2 + C_BodyLo 64 | C_ShadowEquals = C_UpShadow == C_DnShadow or (abs(C_UpShadow - C_DnShadow) / C_DnShadow * 100) < C_ShadowEqualsPercent and (abs(C_DnShadow - C_UpShadow) / C_UpShadow * 100) < C_ShadowEqualsPercent 65 | C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100 66 | C_Doji = C_IsDojiBody and C_ShadowEquals 67 | 68 | patternLabelPosLow = low - (atr(30) * 0.6) 69 | patternLabelPosHigh = high + (atr(30) * 0.6) 70 | 71 | // END misc. options 72 | 73 | // START Stochastic RSI 74 | stochrsi_smoothK = input(3, minval=1) 75 | stochrsi_smoothD = input(3, minval=1) 76 | stochrsi_lengthRSI = input(14, minval=1) 77 | stochrsi_lengthStoch = input(14, minval=1) 78 | stochrsi_src = input(close, title="RSI Source") 79 | 80 | stochrsi_rsi1 = rsi(stochrsi_src, stochrsi_lengthRSI) 81 | stochrsi_k = sma(stoch(stochrsi_rsi1, stochrsi_rsi1, stochrsi_rsi1, stochrsi_lengthStoch), stochrsi_smoothK) 82 | stochrsi_d = sma(stochrsi_k, stochrsi_smoothD) 83 | // plot(k, color=blue) 84 | // plot(d, color=orange) 85 | // stochrsi_h0 = hline(80) 86 | // stochrsi_h1 = hline(20) 87 | // fill(h0, h1, color=purple, transp=80) 88 | 89 | stochrsi_RSIComingDown = crossunder(stochrsi_k, stochrsi_d) and stochrsi_k >= 80 90 | stochrsi_RSITop = stochrsi_k > 80 91 | stochrsi_RSIComingUp = crossover(stochrsi_k, stochrsi_d) and stochrsi_k <= 30 92 | stochrsi_RSIBottom = stochrsi_k < 30 93 | // END Stochastic RSI 94 | 95 | // START Ichimoku 96 | tenkanSenPeriods = 9 97 | kijunSenPeriods = 26 98 | chikouSpanPeriods = 52 99 | displacement = 26 100 | donchian(len) => avg(lowest(len), highest(len)) 101 | tenkanSen = donchian(tenkanSenPeriods) 102 | kijunSen = donchian(kijunSenPeriods) 103 | senkouSpanA = avg(tenkanSen, kijunSen) 104 | senkouSpanB = donchian(chikouSpanPeriods) 105 | 106 | activeKumoSpan = input(defval=true, title='Draw Kumo Span', type=input.bool) 107 | activeSenkouSpanA = input(defval=false, title='Draw Senkou Span A', type=input.bool) 108 | activeSenkouSpanB = input(defval=true, title='Draw Senkou Span B', type=input.bool) 109 | activeKijunSen = input(defval=true, title='Draw Kijun Sen', type=input.bool) 110 | activeTenkanSen = input(defval=true, title='Draw Tenkan Sen', type=input.bool) 111 | activeChikouSpan = input(defval=true, title='Draw Chikou Span', type=input.bool) 112 | 113 | ichimokuUpTrend = (senkouSpanA > senkouSpanB) and (close > close[26]) 114 | ichimokuDownTrend = (senkouSpanA < senkouSpanB) and (close < close[26]) 115 | 116 | crossUpTenkanSenKijunSen = crossover(tenkanSen, kijunSen) 117 | crossDownTenkanSenKijunSen = crossunder(tenkanSen, kijunSen) 118 | 119 | // bgcolor(color=crossUpTenkanSenKijunSen ? color.green : na, title="Tenkan Sen cross over Kijun Sen", transp=90) 120 | // bgcolor(color=crossDownTenkanSenKijunSen ? color.red : na, title="Tenkan Sen cross under Kijun Sen", transp=90) 121 | 122 | // plot(crossUpTenkanSenKijunSen ? tenkanSen : na, color = color.green , style = plot.style_circles, linewidth = 3) 123 | // plot(crossDownTenkanSenKijunSen ? tenkanSen : na, color = color.red , style = plot.style_circles, linewidth = 3) 124 | 125 | plot(tenkanSen, color=#2196f3, title="Tenkan Sen", linewidth=1, transp=activeTenkanSen ? 30 : 100) 126 | plot(kijunSen, color=#b71c1c, title="Kijun Sen", linewidth=1, transp=activeKijunSen ? 0 : 100) 127 | plot(close, offset = -displacement + 1, color=#FFFFFF, title="Chikou Span", linewidth=1, transp=activeChikouSpan ? 30 : 100) 128 | 129 | p1 = plot(senkouSpanA, offset = displacement -1, color=color.green, 130 | title="Senkou Span A", transp=activeSenkouSpanA ? 0 : 100) 131 | p2 = plot(senkouSpanB, offset = displacement -1 , color=color.red, 132 | title="Senkou Span B", transp=activeSenkouSpanB ? 0 : 100, linewidth=1) 133 | fill(p1, p2, color = senkouSpanA > senkouSpanB ? color.green : color.red, transp=activeKumoSpan ? 85 : 100) 134 | 135 | // ALERTING 136 | // Alert on Kumo twist (range probability) 137 | kumoTwist = cross(senkouSpanA, senkouSpanB) 138 | alertcondition(kumoTwist, "Ichimoku - Kumo twist", "Kumo twist spotted !") 139 | 140 | // Alert on Tenkan Sen / Kijun Sen crossing 141 | tenkanSenKijunSenCross = cross(tenkanSen, kijunSen) 142 | alertcondition(tenkanSenKijunSenCross, "Ichimoku - Tenkan/Kijun cross", "Tenkan and Kijun crossed !") 143 | 144 | // Alert on Chikou Span leaving Kumo 145 | // TODO: check how to put alerting on Chikou because it's only a plot with offset displacement... 146 | // chikouSpanLeaveKumo = 147 | // alertcondition(chikouSpanLeaveKumo, "Chikou leave Kumo !", "Chikou get out of Kumo !") 148 | 149 | priceSSACross = cross(close, senkouSpanA) 150 | priceSSBCross = cross(close, senkouSpanB) 151 | 152 | alertcondition(priceSSACross, "Ichimoku - Price SSA cross", "Prices and SSA crossed !") 153 | alertcondition(priceSSBCross, "Ichimoku - Price SSB cross", "Prices and SSB crossed !") 154 | 155 | priceTenkanSenCross = cross(close, tenkanSen) 156 | priceKijunSenCross = cross(close, kijunSen) 157 | 158 | alertcondition(priceTenkanSenCross, "Ichimoku - Price Tenkan Sen cross", "Prices and Tenkan Sen crossed") 159 | alertcondition(priceKijunSenCross, "Ichimoku - Price Kijun Sen cross", "Prices and Kijun Sen crossed !") 160 | 161 | // END Ichimoku 162 | 163 | 164 | // Bearish Engulfing 165 | C_EngulfingBearishNumberOfCandles = 2 166 | C_EngulfingBearish_1 = C_BlackBody and C_LongBody and C_WhiteBody[1] and C_SmallBody[1] and close <= open[1] and open >= close[1] and ( close < open[1] or open > close[1] ) 167 | C_EngulfingBearish_2 = ((close[1] > open[1]) and (open > close) and (open >= close[1]) and (open[1] >= close) and ((open - close) > (close[1] - open[1]))) 168 | C_EngulfingBearish = (ichimokuUpTrend and stochrsi_RSITop) and (C_EngulfingBearish_1 or C_EngulfingBearish_2) 169 | 170 | alertcondition(C_EngulfingBearish, title = "Candlesticks - Engulfing", message = "New Engulfing - Bearish pattern detected.") 171 | 172 | if C_EngulfingBearish and displayCandlesNames 173 | var ttBearishEngulfing = "Engulfing\nAt the end of a given uptrend, a reversal pattern will most likely appear. During the first day, this candlestick pattern uses a small body. It is then followed by a day where the candle body fully overtakes the body from the day before it and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to fully overtake the range (high to low), rather only the open and the close." 174 | label.new(bar_index, patternLabelPosHigh, text="BE", style=label.style_label_down, size = size.tiny, color = color.red, textcolor=color.black, tooltip = ttBearishEngulfing) 175 | 176 | 177 | // Bullish Engulfing 178 | C_EngulfingBullishNumberOfCandles = 2 179 | C_EngulfingBullish_1 = C_WhiteBody and C_LongBody and C_BlackBody[1] and C_SmallBody[1] and close >= open[1] and open <= close[1] and ( close > open[1] or open < close[1] ) 180 | C_EngulfingBullish_2 = ((open[1] > close[1]) and (close > open) and (close >= open[1]) and (close[1] >= open) and ((close - open) > (open[1] - close[1]))) 181 | C_EngulfingBullish = (ichimokuDownTrend and stochrsi_RSIBottom) and (C_EngulfingBullish_1 or C_EngulfingBullish_2) 182 | 183 | alertcondition(C_EngulfingBullish, title = "Candlesticks - Engulfing", message = "New Engulfing - Bullish pattern detected.") 184 | 185 | if C_EngulfingBullish and displayCandlesNames 186 | var ttBullishEngulfing = "Engulfing\nAt the end of a given downward trend, there will most likely be a reversal pattern. To distinguish the first day, this candlestick pattern uses a small body, followed by a day where the candle body fully overtakes the body from the day before, and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to completely overtake the range (high to low), rather only the open and the close." 187 | label.new(bar_index, patternLabelPosLow, text="BE", style=label.style_label_up, size = size.tiny, color = color.blue, textcolor=color.white, tooltip = ttBullishEngulfing) 188 | 189 | 190 | // Bullish Hammer 191 | C_HammerBullishNumberOfCandles = 1 192 | C_HammerBullish_1 = C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body 193 | C_HammerBullish_2 = (((high - low) > 3 * (open - close)) and ((close - low) / (0.001 + high - low) > 0.6) and ((open - low) / (0.001 + high - low) > 0.6)) 194 | C_HammerBullish = (ichimokuDownTrend and stochrsi_RSIBottom) and (C_HammerBullish_1 or C_HammerBullish_2) 195 | 196 | alertcondition(C_HammerBullish, title = "Candlesticks - Hammer", message = "New Hammer - Bullish pattern detected.") 197 | 198 | if C_HammerBullish and displayCandlesNames 199 | var ttBullishHammer = "Hammer\nHammer candlesticks form when a security moves lower after the open, but continues to rally into close above the intraday low. The candlestick that you are left with will look like a square attached to a long stick-like figure. This candlestick is called a Hammer if it happens to form during a decline." 200 | label.new(bar_index, patternLabelPosLow, text="H", style=label.style_label_up, size = size.tiny, color = color.blue, textcolor=color.white, tooltip = ttBullishHammer) 201 | 202 | 203 | // Bearish Hanging Man 204 | C_HangingManBearishNumberOfCandles = 1 205 | C_HangingManBearish_1 = C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow 206 | C_HangingManBearish_2 = (((high - low) > 4 * (open - close)) and ((close - low) / (0.001 + high - low) >= 0.75) and ((open - low) / (0.001 + high - low) >= 0.75)) 207 | C_HangingManBearish = (ichimokuUpTrend and stochrsi_RSITop) and (C_HangingManBearish_1 or C_HangingManBearish_2) 208 | 209 | alertcondition(C_HangingManBearish, title = "Candlesticks - Hanging Man", message = "New Hanging Man - Bearish pattern detected.") 210 | 211 | if C_HangingManBearish and displayCandlesNames 212 | var ttBearishHangingMan = "Hanging Man\nWhen a specified security notably moves lower after the open, but continues to rally to close above the intraday low, a Hanging Man candlestick will form. The candlestick will resemble a square, attached to a long stick-like figure. It is referred to as a Hanging Man if the candlestick forms during an advance." 213 | label.new(bar_index, patternLabelPosHigh, text="HM", style=label.style_label_down, size = size.tiny, color = color.red, textcolor=color.black, tooltip = ttBearishHangingMan) 214 | 215 | 216 | // Bullish Inverted Hammer 217 | C_InvertedHammerBullishNumberOfCandles = 1 218 | C_InvertedHammerBullish_1 = C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow 219 | // TODO: seems broken 220 | // C_InvertedHammerBullish_2 = (((high - low) > 3 * (open - close)) and ((high - close) / (0.001 + high - low) > 0.6) and ((high - low) / (0.001 + high - low) > 0.6)) 221 | C_InvertedHammerBullish = (ichimokuDownTrend and stochrsi_RSIBottom) and (C_InvertedHammerBullish_1) 222 | 223 | alertcondition(C_InvertedHammerBullish, title = "Candlesticks - Inverted Hammer", message = "New Inverted Hammer - Bullish pattern detected.") 224 | 225 | if C_InvertedHammerBullish and displayCandlesNames 226 | var ttBullishInvertedHammer = "Inverted Hammer\nIf in a downtrend, then the open is lower. When it eventually trades higher, but closes near its open, it will look like an inverted version of the Hammer Candlestick. This is a one-day bullish reversal pattern." 227 | label.new(bar_index, patternLabelPosLow, text="IH", style=label.style_label_up, size = size.tiny, color = color.blue, textcolor=color.white, tooltip = ttBullishInvertedHammer) 228 | 229 | 230 | // Bearish Shooting Star 231 | C_ShootingStarBearishNumberOfCandles = 1 232 | C_ShootingStarBearish_1 = C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body 233 | C_ShootingStarBearish_2 = (((high - low) > 4 * (open - close)) and ((high - close) / (0.001 + high - low) >= 0.75) and ((high - open) / (0.001 + high - low) >= 0.75)) 234 | C_ShootingStarBearish = (ichimokuUpTrend and stochrsi_RSITop) and (C_ShootingStarBearish_2) 235 | 236 | alertcondition(C_ShootingStarBearish, title = "Candlesticks - Shooting Star", message = "New Shooting Star - Bearish pattern detected.") 237 | 238 | if C_ShootingStarBearish and displayCandlesNames 239 | var ttBearishShootingStar = "Shooting Star\nThis single day pattern can appear during an uptrend and opens high, while it closes near its open. It trades much higher as well. It is bearish in nature, but looks like an Inverted Hammer." 240 | label.new(bar_index, patternLabelPosHigh, text="SS", style=label.style_label_down, size = size.tiny, color = color.red, textcolor=color.black, tooltip = ttBearishShootingStar) 241 | 242 | 243 | // Marubozu White 244 | C_MarubozuWhiteBullishNumberOfCandles = 1 245 | C_MarubozuShadowPercentWhite = 5.0 246 | C_MarubozuWhiteBullish_1 = C_WhiteBody and C_LongBody and C_UpShadow <= C_MarubozuShadowPercentWhite/100*C_Body and C_DnShadow <= C_MarubozuShadowPercentWhite/100*C_Body and C_WhiteBody 247 | 248 | C_MarubozuWhiteBullish = C_MarubozuWhiteBullish_1 249 | 250 | alertcondition(C_MarubozuWhiteBullish, title = "Candlesticks - Marubozu White", message = "New Marubozu White - Bullish pattern detected.") 251 | 252 | if C_MarubozuWhiteBullish and displayCandlesNames 253 | var ttBullishMarubozuWhite = "Marubozu White\nA Marubozu White Candle is a candlestick that does not have a shadow that extends from its candle body at either the open or the close. Marubozu is Japanese for “close-cropped” or “close-cut.” Other sources may call it a Bald or Shaven Head Candle." 254 | label.new(bar_index, patternLabelPosLow, text="MW", style=label.style_label_up, size = size.tiny, color = color.blue, textcolor=color.white, tooltip = ttBullishMarubozuWhite) 255 | 256 | 257 | // Marubozu Black 258 | C_MarubozuBlackBearishNumberOfCandles = 1 259 | C_MarubozuShadowPercentBearish = 5.0 260 | C_MarubozuBlackBearish_1 = C_BlackBody and C_LongBody and C_UpShadow <= C_MarubozuShadowPercentBearish/100*C_Body and C_DnShadow <= C_MarubozuShadowPercentBearish/100*C_Body and C_BlackBody 261 | 262 | C_MarubozuBlackBearish = C_MarubozuBlackBearish_1 263 | 264 | alertcondition(C_MarubozuBlackBearish, title = "Candlesticks - Marubozu Black", message = "New Marubozu Black - Bearish pattern detected.") 265 | 266 | if C_MarubozuBlackBearish and displayCandlesNames 267 | var ttBearishMarubozuBlack = "Marubozu Black\nThis is a candlestick that has no shadow, which extends from the red-bodied candle at the open, the close, or even at both. In Japanese, the name means “close-cropped” or “close-cut.” The candlestick can also be referred to as Bald or Shaven Head." 268 | label.new(bar_index, patternLabelPosHigh, text="MB", style=label.style_label_down, size = size.tiny, color = color.red, textcolor=color.white, tooltip = ttBearishMarubozuBlack) 269 | 270 | 271 | // Doji 272 | C_DojiNumberOfCandles = 1 273 | C_DragonflyDoji = C_IsDojiBody and C_UpShadow <= C_Body 274 | C_GravestoneDojiOne = C_IsDojiBody and C_DnShadow <= C_Body 275 | 276 | alertcondition(C_Doji and not C_DragonflyDoji and not C_GravestoneDojiOne, title = "Candlesticks - Doji", message = "New Doji pattern detected.") 277 | 278 | if C_Doji and not C_DragonflyDoji and not C_GravestoneDojiOne and displayCandlesNames 279 | var ttDoji = "Doji\nWhen the open and close of a security are essentially equal to each other, a doji candle forms. The length of both upper and lower shadows may vary, causing the candlestick you are left with to either resemble a cross, an inverted cross, or a plus sign. Doji candles show the playout of buyer-seller indecision in a tug-of-war of sorts. As price moves either above or below the opening level during the session, the close is either at or near the opening level." 280 | label.new(bar_index, patternLabelPosLow, text="D", style=label.style_label_up, size = size.tiny, color = color.gray, textcolor=color.white, tooltip = ttDoji) 281 | 282 | 283 | // Gravestone Doji 284 | C_GravestoneDojiBearishNumberOfCandles = 1 285 | C_GravestoneDojiBearish = C_IsDojiBody and C_DnShadow <= C_Body 286 | 287 | alertcondition(C_GravestoneDojiBearish, title = "Candlesticks - Gravestone Doji", message = "New Gravestone Doji - Bearish pattern detected.") 288 | 289 | if C_GravestoneDojiBearish and displayCandlesNames 290 | var ttBearishGravestoneDoji = "Gravestone Doji\nWhen a doji is at or is close to the day’s low point, a doji line will develop." 291 | label.new(bar_index, patternLabelPosHigh, text="GD", style=label.style_label_down, size = size.tiny, color = color.red, textcolor=color.white, tooltip = ttBearishGravestoneDoji) 292 | 293 | 294 | // Dragonfly Doji 295 | C_DragonflyDojiBullishNumberOfCandles = 1 296 | C_DragonflyDojiBullish = C_IsDojiBody and C_UpShadow <= C_Body 297 | 298 | alertcondition(C_DragonflyDojiBullish, title = "Candlesticks - Dragonfly Doji", message = "New Dragonfly Doji - Bullish pattern detected.") 299 | 300 | if C_DragonflyDojiBullish and displayCandlesNames 301 | var ttBullishDragonflyDoji = "Dragonfly Doji\nSimilar to other Doji days, this particular Doji also regularly appears at pivotal market moments. This is a specific Doji where both the open and close price are at the high of a given day." 302 | label.new(bar_index, patternLabelPosLow, text="DD", style=label.style_label_up, size = size.tiny, color = color.blue, textcolor=color.white, tooltip = ttBullishDragonflyDoji) 303 | 304 | // C_OnNeckBearishNumberOfCandles = 2 305 | // C_OnNeckBearish = false 306 | // if C_DownTrend and C_BlackBody[1] and C_LongBody[1] and C_WhiteBody and open < close[1] and C_SmallBody and C_Range!=0 and abs(close-low[1])<=C_BodyAvg*0.05 307 | // C_OnNeckBearish := true 308 | // alertcondition(C_OnNeckBearish, title = "On Neck", message = "New On Neck - Bearish pattern detected.") 309 | // if C_OnNeckBearish and OnNeckInput and (("Bearish" == CandleType) or CandleType == "Both") 310 | 311 | // var ttBearishOnNeck = "On Neck\nOn Neck is a two-line continuation pattern found in a downtrend. The first candle is long and red, the second candle is short and has a green body. The closing price of the second candle is close or equal to the first candle's low price. The pattern hints at a continuation of a downtrend, and penetrating the low of the green candlestick is sometimes considered a confirmation. " 312 | // label.new(bar_index, patternLabelPosHigh, text="ON", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishOnNeck) 313 | // C_RisingWindowBullishNumberOfCandles = 2 314 | // C_RisingWindowBullish = false 315 | // if C_UpTrend[1] and (C_Range!=0 and C_Range[1]!=0) and low > high[1] 316 | // C_RisingWindowBullish := true 317 | // alertcondition(C_RisingWindowBullish, title = "Rising Window", message = "New Rising Window - Bullish pattern detected.") 318 | // if C_RisingWindowBullish and RisingWindowInput and (("Bullish" == CandleType) or CandleType == "Both") 319 | 320 | // var ttBullishRisingWindow = "Rising Window\nRising Window is a two-candle bullish continuation pattern that forms during an uptrend. Both candles in the pattern can be of any type with the exception of the Four-Price Doji. The most important characteristic of the pattern is a price gap between the first candle's high and the second candle's low. That gap (window) between two bars signifies support against the selling pressure." 321 | // label.new(bar_index, patternLabelPosLow, text="RW", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishRisingWindow) 322 | // C_FallingWindowBearishNumberOfCandles = 2 323 | // C_FallingWindowBearish = false 324 | // if C_DownTrend[1] and (C_Range!=0 and C_Range[1]!=0) and high < low[1] 325 | // C_FallingWindowBearish := true 326 | // alertcondition(C_FallingWindowBearish, title = "Falling Window", message = "New Falling Window - Bearish pattern detected.") 327 | // if C_FallingWindowBearish and FallingWindowInput and (("Bearish" == CandleType) or CandleType == "Both") 328 | 329 | // var ttBearishFallingWindow = "Falling Window\nFalling Window is a two-candle bearish continuation pattern that forms during a downtrend. Both candles in the pattern can be of any type, with the exception of the Four-Price Doji. The most important characteristic of the pattern is a price gap between the first candle's low and the second candle's high. The existence of this gap (window) means that the bearish trend is expected to continue." 330 | // label.new(bar_index, patternLabelPosHigh, text="FW", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishFallingWindow) 331 | // C_FallingThreeMethodsBearishNumberOfCandles = 5 332 | // C_FallingThreeMethodsBearish = false 333 | // if C_DownTrend[4] and (C_LongBody[4] and C_BlackBody[4]) and (C_SmallBody[3] and C_WhiteBody[3] and open[3]>low[4] and close[3]low[4] and close[2]low[4] and close[1]low[4]) and (C_SmallBody[2] and C_BlackBody[2] and open[2]low[4]) and (C_SmallBody[1] and C_BlackBody[1] and open[1]low[4]) and (C_LongBody and C_WhiteBody and close>close[4]) 343 | // C_RisingThreeMethodsBullish := true 344 | // alertcondition(C_RisingThreeMethodsBullish, title = "Rising Three Methods", message = "New Rising Three Methods - Bullish pattern detected.") 345 | // if C_RisingThreeMethodsBullish and RisingThreeMethodsInput and (("Bullish" == CandleType) or CandleType == "Both") 346 | 347 | // var ttBullishRisingThreeMethods = "Rising Three Methods\nRising Three Methods is a five-candle bullish pattern that signifies a continuation of an existing uptrend. The first candle is long and green, followed by three short red candles with bodies inside the range of the first candle. The last candle is also green and long and it closes above the close of the first candle. This decisive fifth strongly bullish candle hints that bears could not reverse the prior uptrend and that bulls have regained control of the market." 348 | // label.new(bar_index, patternLabelPosLow, text="RTM", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishRisingThreeMethods) 349 | // C_TweezerTopBearishNumberOfCandles = 2 350 | // C_TweezerTopBearish = false 351 | // if C_UpTrend[1] and (not C_IsDojiBody or (C_HasUpShadow and C_HasDnShadow)) and abs(high-high[1]) <= C_BodyAvg*0.05 and C_WhiteBody[1] and C_BlackBody and C_LongBody[1] 352 | // C_TweezerTopBearish := true 353 | // alertcondition(C_TweezerTopBearish, title = "Tweezer Top", message = "New Tweezer Top - Bearish pattern detected.") 354 | // if C_TweezerTopBearish and TweezerTopInput and (("Bearish" == CandleType) or CandleType == "Both") 355 | 356 | // var ttBearishTweezerTop = "Tweezer Top\nTweezer Top is a two-candle pattern that signifies a potential bearish reversal. The pattern is found during an uptrend. The first candle is long and green, the second candle is red, and its high is nearly identical to the high of the previous candle. The virtually identical highs, together with the inverted directions, hint that bears might be taking over the market." 357 | // label.new(bar_index, patternLabelPosHigh, text="TT", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishTweezerTop) 358 | // C_TweezerBottomBullishNumberOfCandles = 2 359 | // C_TweezerBottomBullish = false 360 | // if C_UpTrend[1] and (not C_IsDojiBody or (C_HasUpShadow and C_HasDnShadow)) and abs(low-low[1]) <= C_BodyAvg*0.05 and C_BlackBody[1] and C_WhiteBody and C_LongBody[1] 361 | // C_TweezerBottomBullish := true 362 | // alertcondition(C_TweezerBottomBullish, title = "Tweezer Bottom", message = "New Tweezer Bottom - Bullish pattern detected.") 363 | // if C_TweezerBottomBullish and TweezerBottomInput and (("Bullish" == CandleType) or CandleType == "Both") 364 | 365 | // var ttBullishTweezerBottom = "Tweezer Bottom\nTweezer Bottom is a two-candle pattern that signifies a potential bullish reversal. The pattern is found during a downtrend. The first candle is long and red, the second candle is green, its lows nearly identical to the low of the previous candle. The virtually identical lows together with the inverted directions hint that bulls might be taking over the market." 366 | // label.new(bar_index, patternLabelPosLow, text="TB", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishTweezerBottom) 367 | // C_DarkCloudCoverBearishNumberOfCandles = 2 368 | // C_DarkCloudCoverBearish = false 369 | // if (C_UpTrend[1] and C_WhiteBody[1] and C_LongBody[1]) and (C_BlackBody and open >= high[1] and close < C_BodyMiddle[1] and close > open[1]) 370 | // C_DarkCloudCoverBearish := true 371 | // alertcondition(C_DarkCloudCoverBearish, title = "Dark Cloud Cover", message = "New Dark Cloud Cover - Bearish pattern detected.") 372 | // if C_DarkCloudCoverBearish and DarkCloudCoverInput and (("Bearish" == CandleType) or CandleType == "Both") 373 | 374 | // var ttBearishDarkCloudCover = "Dark Cloud Cover\nDark Cloud Cover is a two-candle bearish reversal candlestick pattern found in an uptrend. The first candle is green and has a larger than average body. The second candle is red and opens above the high of the prior candle, creating a gap, and then closes below the midpoint of the first candle. The pattern shows a possible shift in the momentum from the upside to the downside, indicating that a reversal might happen soon." 375 | // label.new(bar_index, patternLabelPosHigh, text="DCC", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishDarkCloudCover) 376 | // C_DownsideTasukiGapBearishNumberOfCandles = 3 377 | // C_DownsideTasukiGapBearish = false 378 | // if C_LongBody[2] and C_SmallBody[1] and C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] and C_BlackBody[1] and C_WhiteBody and C_BodyHi <= C_BodyLo[2] and C_BodyHi >= C_BodyHi[1] 379 | // C_DownsideTasukiGapBearish := true 380 | // alertcondition(C_DownsideTasukiGapBearish, title = "Downside Tasuki Gap", message = "New Downside Tasuki Gap - Bearish pattern detected.") 381 | // if C_DownsideTasukiGapBearish and DownsideTasukiGapInput and (("Bearish" == CandleType) or CandleType == "Both") 382 | 383 | // var ttBearishDownsideTasukiGap = "Downside Tasuki Gap\nDownside Tasuki Gap is a three-candle pattern found in a downtrend that usually hints at the continuation of the downtrend. The first candle is long and red, followed by a smaller red candle with its opening price that gaps below the body of the previous candle. The third candle is green and it closes inside the gap created by the first two candles, unable to close it fully. The bull’s inability to close that gap hints that the downtrend might continue." 384 | // label.new(bar_index, patternLabelPosHigh, text="DTG", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishDownsideTasukiGap) 385 | // C_UpsideTasukiGapBullishNumberOfCandles = 3 386 | // C_UpsideTasukiGapBullish = false 387 | // if C_LongBody[2] and C_SmallBody[1] and C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_WhiteBody[1] and C_BlackBody and C_BodyLo >= C_BodyHi[2] and C_BodyLo <= C_BodyLo[1] 388 | // C_UpsideTasukiGapBullish := true 389 | // alertcondition(C_UpsideTasukiGapBullish, title = "Upside Tasuki Gap", message = "New Upside Tasuki Gap - Bullish pattern detected.") 390 | // if C_UpsideTasukiGapBullish and UpsideTasukiGapInput and (("Bullish" == CandleType) or CandleType == "Both") 391 | 392 | // var ttBullishUpsideTasukiGap = "Upside Tasuki Gap\nUpside Tasuki Gap is a three-candle pattern found in an uptrend that usually hints at the continuation of the uptrend. The first candle is long and green, followed by a smaller green candle with its opening price that gaps above the body of the previous candle. The third candle is red and it closes inside the gap created by the first two candles, unable to close it fully. The bear’s inability to close the gap hints that the uptrend might continue." 393 | // label.new(bar_index, patternLabelPosLow, text="UTG", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishUpsideTasukiGap) 394 | // C_EveningDojiStarBearishNumberOfCandles = 3 395 | // C_EveningDojiStarBearish = false 396 | // if C_LongBody[2] and C_IsDojiBody[1] and C_LongBody and C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_BlackBody and C_BodyLo <= C_BodyMiddle[2] and C_BodyLo > C_BodyLo[2] and C_BodyLo[1] > C_BodyHi 397 | // C_EveningDojiStarBearish := true 398 | // alertcondition(C_EveningDojiStarBearish, title = "Evening Doji Star", message = "New Evening Doji Star - Bearish pattern detected.") 399 | // if C_EveningDojiStarBearish and EveningDojiStarInput and (("Bearish" == CandleType) or CandleType == "Both") 400 | 401 | // var ttBearishEveningDojiStar = "Evening Doji Star\nThis candlestick pattern is a variation of the Evening Star pattern. It is bearish and continues an uptrend with a long-bodied, green candle day. It is then followed by a gap and a Doji candle and concludes with a downward close. The close would be below the first day’s midpoint. It is more bearish than the regular evening star pattern because of the existence of the Doji." 402 | // label.new(bar_index, patternLabelPosHigh, text="EDS", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishEveningDojiStar) 403 | // C_DojiStarBearishNumberOfCandles = 2 404 | // C_DojiStarBearish = false 405 | // if C_UpTrend and C_WhiteBody[1] and C_LongBody[1] and C_IsDojiBody and C_BodyLo > C_BodyHi[1] 406 | // C_DojiStarBearish := true 407 | // alertcondition(C_DojiStarBearish, title = "Doji Star", message = "New Doji Star - Bearish pattern detected.") 408 | // if C_DojiStarBearish and DojiStarInput and (("Bearish" == CandleType) or CandleType == "Both") 409 | 410 | // var ttBearishDojiStar = "Doji Star\nThis is a bearish reversal candlestick pattern that is found in an uptrend and consists of two candles. First comes a long green candle, followed by a Doji candle (except 4-Price Doji) that opens above the body of the first one, creating a gap. It is considered a reversal signal with confirmation during the next trading day." 411 | // label.new(bar_index, patternLabelPosHigh, text="DS", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishDojiStar) 412 | // C_DojiStarBullishNumberOfCandles = 2 413 | // C_DojiStarBullish = false 414 | // if C_DownTrend and C_BlackBody[1] and C_LongBody[1] and C_IsDojiBody and C_BodyHi < C_BodyLo[1] 415 | // C_DojiStarBullish := true 416 | // alertcondition(C_DojiStarBullish, title = "Doji Star", message = "New Doji Star - Bullish pattern detected.") 417 | // if C_DojiStarBullish and DojiStarInput and (("Bullish" == CandleType) or CandleType == "Both") 418 | 419 | // var ttBullishDojiStar = "Doji Star\nThis is a bullish reversal candlestick pattern that is found in a downtrend and consists of two candles. First comes a long red candle, followed by a Doji candle (except 4-Price Doji) that opens below the body of the first one, creating a gap. It is considered a reversal signal with confirmation during the next trading day." 420 | // label.new(bar_index, patternLabelPosLow, text="DS", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishDojiStar) 421 | // C_MorningDojiStarBullishNumberOfCandles = 3 422 | // C_MorningDojiStarBullish = false 423 | // if C_LongBody[2] and C_IsDojiBody[1] and C_LongBody and C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] and C_WhiteBody and C_BodyHi >= C_BodyMiddle[2] and C_BodyHi < C_BodyHi[2] and C_BodyHi[1] < C_BodyLo 424 | // C_MorningDojiStarBullish := true 425 | // alertcondition(C_MorningDojiStarBullish, title = "Morning Doji Star", message = "New Morning Doji Star - Bullish pattern detected.") 426 | // if C_MorningDojiStarBullish and MorningDojiStarInput and (("Bullish" == CandleType) or CandleType == "Both") 427 | 428 | // var ttBullishMorningDojiStar = "Morning Doji Star\nThis candlestick pattern is a variation of the Morning Star pattern. A three-day bullish reversal pattern, which consists of three candlesticks will look something like this: The first being a long-bodied red candle that extends the current downtrend. Next comes a Doji that gaps down on the open. After that comes a long-bodied green candle, which gaps up on the open and closes above the midpoint of the body of the first day. It is more bullish than the regular morning star pattern because of the existence of the Doji." 429 | // label.new(bar_index, patternLabelPosLow, text="MDS", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishMorningDojiStar) 430 | // C_PiercingBullishNumberOfCandles = 2 431 | // C_PiercingBullish = false 432 | // if (C_DownTrend[1] and C_BlackBody[1] and C_LongBody[1]) and (C_WhiteBody and open <= low[1] and close > C_BodyMiddle[1] and close < open[1]) 433 | // C_PiercingBullish := true 434 | // alertcondition(C_PiercingBullish, title = "Piercing", message = "New Piercing - Bullish pattern detected.") 435 | // if C_PiercingBullish and PiercingInput and (("Bullish" == CandleType) or CandleType == "Both") 436 | 437 | // var ttBullishPiercing = "Piercing\nPiercing is a two-candle bullish reversal candlestick pattern found in a downtrend. The first candle is red and has a larger than average body. The second candle is green and opens below the low of the prior candle, creating a gap, and then closes above the midpoint of the first candle. The pattern shows a possible shift in the momentum from the downside to the upside, indicating that a reversal might happen soon." 438 | // label.new(bar_index, patternLabelPosLow, text="P", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishPiercing) 439 | // C_HammerBullishNumberOfCandles = 1 440 | // // C_HammerBullish = C_DownTrend and C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow 441 | // C_HammerBullish = stochrsi_RSIBottom and C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow 442 | 443 | // alertcondition(C_HammerBullish, title = "Hammer", message = "New Hammer - Bullish pattern detected.") 444 | // if C_HammerBullish and HammerInput and (("Bullish" == CandleType) or CandleType == "Both") 445 | 446 | // var ttBullishHammer = "Hammer\nHammer candlesticks form when a security moves lower after the open, but continues to rally into close above the intraday low. The candlestick that you are left with will look like a square attached to a long stick-like figure. This candlestick is called a Hammer if it happens to form during a decline." 447 | // label.new(bar_index, patternLabelPosLow, text="H", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishHammer) 448 | // C_HangingManBearishNumberOfCandles = 1 449 | // // C_HangingManBearish = C_UpTrend and C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow 450 | // C_HangingManBearish = stochrsi_RSITop and C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow 451 | 452 | // alertcondition(C_HangingManBearish, title = "Hanging Man", message = "New Hanging Man - Bearish pattern detected.") 453 | // if C_HangingManBearish and HangingManInput and (("Bearish" == CandleType) or CandleType == "Both") 454 | 455 | // var ttBearishHangingMan = "Hanging Man\nWhen a specified security notably moves lower after the open, but continues to rally to close above the intraday low, a Hanging Man candlestick will form. The candlestick will resemble a square, attached to a long stick-like figure. It is referred to as a Hanging Man if the candlestick forms during an advance." 456 | // label.new(bar_index, patternLabelPosHigh, text="HM", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishHangingMan) 457 | 458 | 459 | // C_ShootingStarBearishNumberOfCandles = 1 460 | // // C_ShootingStarBearish = C_UpTrend and C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow 461 | // C_ShootingStarBearish = C_UpTrend and stochrsi_RSIBottom and C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow 462 | 463 | // alertcondition(C_ShootingStarBearish, title = "Shooting Star", message = "New Shooting Star - Bearish pattern detected.") 464 | // if C_ShootingStarBearish and ShootingStarInput and (("Bearish" == CandleType) or CandleType == "Both") 465 | 466 | // var ttBearishShootingStar = "Shooting Star\nThis single day pattern can appear during an uptrend and opens high, while it closes near its open. It trades much higher as well. It is bearish in nature, but looks like an Inverted Hammer." 467 | // label.new(bar_index, patternLabelPosHigh, text="SS", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishShootingStar) 468 | 469 | 470 | // C_InvertedHammerBullishNumberOfCandles = 1 471 | // // C_InvertedHammerBullish = C_DownTrend and C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow 472 | // C_InvertedHammerBullish = stochrsi_RSITop and C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow 473 | 474 | // alertcondition(C_InvertedHammerBullish, title = "Inverted Hammer", message = "New Inverted Hammer - Bullish pattern detected.") 475 | // if C_InvertedHammerBullish and InvertedHammerInput and (("Bullish" == CandleType) or CandleType == "Both") 476 | 477 | // var ttBullishInvertedHammer = "Inverted Hammer\nIf in a downtrend, then the open is lower. When it eventually trades higher, but closes near its open, it will look like an inverted version of the Hammer Candlestick. This is a one-day bullish reversal pattern." 478 | // label.new(bar_index, patternLabelPosLow, text="IH", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishInvertedHammer) 479 | 480 | 481 | // C_MorningStarBullishNumberOfCandles = 3 482 | // C_MorningStarBullish = C_LongBody[2] and C_SmallBody[1] and C_LongBody and C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] and C_WhiteBody and C_BodyHi >= C_BodyMiddle[2] and C_BodyHi < C_BodyHi[2] and C_BodyHi[1] < C_BodyLo 483 | 484 | // alertcondition(C_MorningStarBullish, title = "Morning Star", message = "New Morning Star - Bullish pattern detected.") 485 | // if C_MorningStarBullish and MorningStarInput and (("Bullish" == CandleType) or CandleType == "Both") 486 | 487 | // var ttBullishMorningStar = "Morning Star\nA three-day bullish reversal pattern, which consists of three candlesticks will look something like this: The first being a long-bodied red candle that extends the current downtrend. Next comes a short, middle candle that gaps down on the open. After comes a long-bodied green candle, which gaps up on the open and closes above the midpoint of the body of the first day." 488 | // label.new(bar_index, patternLabelPosLow, text="MS", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishMorningStar) 489 | // C_EveningStarBearishNumberOfCandles = 3 490 | // C_EveningStarBearish = false 491 | // if C_LongBody[2] and C_SmallBody[1] and C_LongBody 492 | // if C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_BlackBody and C_BodyLo <= C_BodyMiddle[2] and C_BodyLo > C_BodyLo[2] and C_BodyLo[1] > C_BodyHi 493 | // C_EveningStarBearish := true 494 | // alertcondition(C_EveningStarBearish, title = "Evening Star", message = "New Evening Star - Bearish pattern detected.") 495 | // if C_EveningStarBearish and EveningStarInput and (("Bearish" == CandleType) or CandleType == "Both") 496 | 497 | // var ttBearishEveningStar = "Evening Star\nThis candlestick pattern is bearish and continues an uptrend with a long-bodied, green candle day. It is then followed by a gapped and small-bodied candle day, and concludes with a downward close. The close would be below the first day’s midpoint." 498 | // label.new(bar_index, patternLabelPosHigh, text="ES", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishEveningStar) 499 | // C_MarubozuWhiteBullishNumberOfCandles = 1 500 | // C_MarubozuShadowPercentWhite = 5.0 501 | // C_MarubozuWhiteBullish = C_WhiteBody and C_LongBody and C_UpShadow <= C_MarubozuShadowPercentWhite/100*C_Body and C_DnShadow <= C_MarubozuShadowPercentWhite/100*C_Body and C_WhiteBody 502 | // alertcondition(C_MarubozuWhiteBullish, title = "Marubozu White", message = "New Marubozu White - Bullish pattern detected.") 503 | // if C_MarubozuWhiteBullish and MarubozuWhiteInput and (("Bullish" == CandleType) or CandleType == "Both") 504 | 505 | // var ttBullishMarubozuWhite = "Marubozu White\nA Marubozu White Candle is a candlestick that does not have a shadow that extends from its candle body at either the open or the close. Marubozu is Japanese for “close-cropped” or “close-cut.” Other sources may call it a Bald or Shaven Head Candle." 506 | // label.new(bar_index, patternLabelPosLow, text="MW", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishMarubozuWhite) 507 | // C_MarubozuBlackBearishNumberOfCandles = 1 508 | // C_MarubozuShadowPercentBearish = 5.0 509 | // C_MarubozuBlackBearish = C_BlackBody and C_LongBody and C_UpShadow <= C_MarubozuShadowPercentBearish/100*C_Body and C_DnShadow <= C_MarubozuShadowPercentBearish/100*C_Body and C_BlackBody 510 | // alertcondition(C_MarubozuBlackBearish, title = "Marubozu Black", message = "New Marubozu Black - Bearish pattern detected.") 511 | // if C_MarubozuBlackBearish and MarubozuBlackInput and (("Bearish" == CandleType) or CandleType == "Both") 512 | 513 | // var ttBearishMarubozuBlack = "Marubozu Black\nThis is a candlestick that has no shadow, which extends from the red-bodied candle at the open, the close, or even at both. In Japanese, the name means “close-cropped” or “close-cut.” The candlestick can also be referred to as Bald or Shaven Head." 514 | // label.new(bar_index, patternLabelPosHigh, text="MB", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishMarubozuBlack) 515 | // C_DojiNumberOfCandles = 1 516 | // C_DragonflyDoji = C_IsDojiBody and C_UpShadow <= C_Body 517 | // C_GravestoneDojiOne = C_IsDojiBody and C_DnShadow <= C_Body 518 | // alertcondition(C_Doji and not C_DragonflyDoji and not C_GravestoneDojiOne, title = "Doji", message = "New Doji pattern detected.") 519 | // if C_Doji and not C_DragonflyDoji and not C_GravestoneDojiOne and DojiInput 520 | // var ttDoji = "Doji\nWhen the open and close of a security are essentially equal to each other, a doji candle forms. The length of both upper and lower shadows may vary, causing the candlestick you are left with to either resemble a cross, an inverted cross, or a plus sign. Doji candles show the playout of buyer-seller indecision in a tug-of-war of sorts. As price moves either above or below the opening level during the session, the close is either at or near the opening level." 521 | // label.new(bar_index, patternLabelPosLow, text="D", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttDoji) 522 | // C_GravestoneDojiBearishNumberOfCandles = 1 523 | // C_GravestoneDojiBearish = C_IsDojiBody and C_DnShadow <= C_Body 524 | // alertcondition(C_GravestoneDojiBearish, title = "Gravestone Doji", message = "New Gravestone Doji - Bearish pattern detected.") 525 | // if C_GravestoneDojiBearish and GravestoneDojiInput and (("Bearish" == CandleType) or CandleType == "Both") 526 | 527 | // var ttBearishGravestoneDoji = "Gravestone Doji\nWhen a doji is at or is close to the day’s low point, a doji line will develop." 528 | // label.new(bar_index, patternLabelPosHigh, text="GD", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishGravestoneDoji) 529 | // C_DragonflyDojiBullishNumberOfCandles = 1 530 | // C_DragonflyDojiBullish = C_IsDojiBody and C_UpShadow <= C_Body 531 | // alertcondition(C_DragonflyDojiBullish, title = "Dragonfly Doji", message = "New Dragonfly Doji - Bullish pattern detected.") 532 | // if C_DragonflyDojiBullish and DragonflyDojiInput and (("Bullish" == CandleType) or CandleType == "Both") 533 | 534 | // var ttBullishDragonflyDoji = "Dragonfly Doji\nSimilar to other Doji days, this particular Doji also regularly appears at pivotal market moments. This is a specific Doji where both the open and close price are at the high of a given day." 535 | // label.new(bar_index, patternLabelPosLow, text="DD", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishDragonflyDoji) 536 | // C_HaramiCrossBullishNumberOfCandles = 2 537 | // C_HaramiCrossBullish = C_LongBody[1] and C_BlackBody[1] and C_DownTrend[1] and C_IsDojiBody and high <= C_BodyHi[1] and low >= C_BodyLo[1] 538 | // alertcondition(C_HaramiCrossBullish, title = "Harami Cross", message = "New Harami Cross - Bullish pattern detected.") 539 | // if C_HaramiCrossBullish and HaramiCrossInput and (("Bullish" == CandleType) or CandleType == "Both") 540 | 541 | // var ttBullishHaramiCross = "Harami Cross\nThis candlestick pattern is a variation of the Harami Bullish pattern. It is found during a downtrend. The two-day candlestick pattern consists of a Doji candle that is entirely encompassed within the body of what was once a red-bodied candle." 542 | // label.new(bar_index, patternLabelPosLow, text="HC", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishHaramiCross) 543 | // C_HaramiCrossBearishNumberOfCandles = 2 544 | // C_HaramiCrossBearish = C_LongBody[1] and C_WhiteBody[1] and C_UpTrend[1] and C_IsDojiBody and high <= C_BodyHi[1] and low >= C_BodyLo[1] 545 | // alertcondition(C_HaramiCrossBearish, title = "Harami Cross", message = "New Harami Cross - Bearish pattern detected.") 546 | // if C_HaramiCrossBearish and HaramiCrossInput and (("Bearish" == CandleType) or CandleType == "Both") 547 | 548 | // var ttBearishHaramiCross = "Harami Cross\nThis candlestick pattern is a variation of the Harami Bearish pattern. It is found during an uptrend. This is a two-day candlestick pattern with a Doji candle that is entirely encompassed within the body that was once a green-bodied candle. The Doji shows that some indecision has entered the minds of sellers, and the pattern hints that the trend might reverse." 549 | // label.new(bar_index, patternLabelPosHigh, text="HC", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishHaramiCross) 550 | // C_HaramiBullishNumberOfCandles = 2 551 | // C_HaramiBullish = C_LongBody[1] and C_BlackBody[1] and C_DownTrend[1] and C_WhiteBody and C_SmallBody and high <= C_BodyHi[1] and low >= C_BodyLo[1] 552 | // alertcondition(C_HaramiBullish, title = "Harami", message = "New Harami - Bullish pattern detected.") 553 | // if C_HaramiBullish and HaramiInput and (("Bullish" == CandleType) or CandleType == "Both") 554 | 555 | // var ttBullishHarami = "Harami\nThis two-day candlestick pattern consists of a small-bodied green candle that is entirely encompassed within the body of what was once a red-bodied candle." 556 | // label.new(bar_index, patternLabelPosLow, text="BH", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishHarami) 557 | // C_HaramiBearishNumberOfCandles = 2 558 | // C_HaramiBearish = C_LongBody[1] and C_WhiteBody[1] and C_UpTrend[1] and C_BlackBody and C_SmallBody and high <= C_BodyHi[1] and low >= C_BodyLo[1] 559 | // alertcondition(C_HaramiBearish, title = "Harami", message = "New Harami - Bearish pattern detected.") 560 | // if C_HaramiBearish and HaramiInput and (("Bearish" == CandleType) or CandleType == "Both") 561 | 562 | // var ttBearishHarami = "Harami\nThis is a two-day candlestick pattern with a small, red-bodied candle that is entirely encompassed within the body that was once a green-bodied candle." 563 | // label.new(bar_index, patternLabelPosHigh, text="BH", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishHarami) 564 | // C_LongLowerShadowBullishNumberOfCandles = 1 565 | // C_LongLowerShadowPercent = 75.0 566 | // C_LongLowerShadowBullish = C_DnShadow > C_Range/100*C_LongLowerShadowPercent 567 | // alertcondition(C_LongLowerShadowBullish, title = "Long Lower Shadow", message = "New Long Lower Shadow - Bullish pattern detected.") 568 | // if C_LongLowerShadowBullish and LongLowerShadowInput and (("Bullish" == CandleType) or CandleType == "Both") 569 | 570 | // var ttBullishLongLowerShadow = "Long Lower Shadow\nTo indicate seller domination of the first part of a session, candlesticks will present with long lower shadows and short upper shadows, consequently lowering prices." 571 | // label.new(bar_index, patternLabelPosLow, text="LLS", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishLongLowerShadow) 572 | // C_LongUpperShadowBearishNumberOfCandles = 1 573 | // C_LongShadowPercent = 75.0 574 | // C_LongUpperShadowBearish = C_UpShadow > C_Range/100*C_LongShadowPercent 575 | // alertcondition(C_LongUpperShadowBearish, title = "Long Upper Shadow", message = "New Long Upper Shadow - Bearish pattern detected.") 576 | // if C_LongUpperShadowBearish and LongUpperShadowInput and (("Bearish" == CandleType) or CandleType == "Both") 577 | 578 | // var ttBearishLongUpperShadow = "Long Upper Shadow\nTo indicate buyer domination of the first part of a session, candlesticks will present with long upper shadows, as well as short lower shadows, consequently raising bidding prices." 579 | // label.new(bar_index, patternLabelPosHigh, text="LUS", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishLongUpperShadow) 580 | // C_SpinningTopWhiteNumberOfCandles = 1 581 | // C_SpinningTopWhitePercent = 34.0 582 | // C_IsSpinningTopWhite = C_DnShadow >= C_Range / 100 * C_SpinningTopWhitePercent and C_UpShadow >= C_Range / 100 * C_SpinningTopWhitePercent and not C_IsDojiBody 583 | // C_SpinningTopWhite = C_IsSpinningTopWhite and C_WhiteBody 584 | // alertcondition(C_SpinningTopWhite, title = "Spinning Top White", message = "New Spinning Top White pattern detected.") 585 | // if C_SpinningTopWhite and SpinningTopWhiteInput 586 | // var ttSpinningTopWhite = "Spinning Top White\nWhite spinning tops are candlestick lines that are small, green-bodied, and possess shadows (upper and lower) that end up exceeding the length of candle bodies. They often signal indecision between buyer and seller." 587 | // label.new(bar_index, patternLabelPosLow, text="STW", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttSpinningTopWhite) 588 | // C_SpinningTopBlackNumberOfCandles = 1 589 | // C_SpinningTopBlackPercent = 34.0 590 | // C_IsSpinningTop = C_DnShadow >= C_Range / 100 * C_SpinningTopBlackPercent and C_UpShadow >= C_Range / 100 * C_SpinningTopBlackPercent and not C_IsDojiBody 591 | // C_SpinningTopBlack = C_IsSpinningTop and C_BlackBody 592 | // alertcondition(C_SpinningTopBlack, title = "Spinning Top Black", message = "New Spinning Top Black pattern detected.") 593 | // if C_SpinningTopBlack and SpinningTopBlackInput 594 | // var ttSpinningTopBlack = "Spinning Top Black\nBlack spinning tops are candlestick lines that are small, red-bodied, and possess shadows (upper and lower) that end up exceeding the length of candle bodies. They often signal indecision." 595 | // label.new(bar_index, patternLabelPosLow, text="STB", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttSpinningTopBlack) 596 | // C_ThreeWhiteSoldiersBullishNumberOfCandles = 3 597 | // C_3WSld_ShadowPercent = 5.0 598 | // C_3WSld_HaveNotUpShadow = C_Range * C_3WSld_ShadowPercent / 100 > C_UpShadow 599 | // C_ThreeWhiteSoldiersBullish = false 600 | // if C_LongBody and C_LongBody[1] and C_LongBody[2] 601 | // if C_WhiteBody and C_WhiteBody[1] and C_WhiteBody[2] 602 | // C_ThreeWhiteSoldiersBullish := close > close[1] and close[1] > close[2] and open < close[1] and open > open[1] and open[1] < close[2] and open[1] > open[2] and C_3WSld_HaveNotUpShadow and C_3WSld_HaveNotUpShadow[1] and C_3WSld_HaveNotUpShadow[2] 603 | // alertcondition(C_ThreeWhiteSoldiersBullish, title = "Three White Soldiers", message = "New Three White Soldiers - Bullish pattern detected.") 604 | // if C_ThreeWhiteSoldiersBullish and ThreeWhiteSoldiersInput and (("Bullish" == CandleType) or CandleType == "Both") 605 | 606 | // var ttBullishThreeWhiteSoldiers = "Three White Soldiers\nThis bullish reversal pattern is made up of three long-bodied, green candles in immediate succession. Each one opens within the body before it and the close is near to the daily high." 607 | // label.new(bar_index, patternLabelPosLow, text="3WS", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishThreeWhiteSoldiers) 608 | // C_ThreeBlackCrowsBearishNumberOfCandles = 3 609 | // C_3BCrw_ShadowPercent = 5.0 610 | // C_3BCrw_HaveNotDnShadow = C_Range * C_3BCrw_ShadowPercent / 100 > C_DnShadow 611 | // C_ThreeBlackCrowsBearish = false 612 | // if C_LongBody and C_LongBody[1] and C_LongBody[2] 613 | // if C_BlackBody and C_BlackBody[1] and C_BlackBody[2] 614 | // C_ThreeBlackCrowsBearish := close < close[1] and close[1] < close[2] and open > close[1] and open < open[1] and open[1] > close[2] and open[1] < open[2] and C_3BCrw_HaveNotDnShadow and C_3BCrw_HaveNotDnShadow[1] and C_3BCrw_HaveNotDnShadow[2] 615 | // alertcondition(C_ThreeBlackCrowsBearish, title = "Three Black Crows", message = "New Three Black Crows - Bearish pattern detected.") 616 | // if C_ThreeBlackCrowsBearish and ThreeBlackCrowsInput and (("Bearish" == CandleType) or CandleType == "Both") 617 | 618 | // var ttBearishThreeBlackCrows = "Three Black Crows\nThis is a bearish reversal pattern that consists of three long, red-bodied candles in immediate succession. For each of these candles, each day opens within the body of the day before and closes either at or near its low." 619 | // label.new(bar_index, patternLabelPosHigh, text="3BC", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishThreeBlackCrows) 620 | // C_EngulfingBullishNumberOfCandles = 2 621 | // // C_EngulfingBullish = C_DownTrend and C_WhiteBody and C_LongBody and C_BlackBody[1] and C_SmallBody[1] and close >= open[1] and open <= close[1] and ( close > open[1] or open < close[1] ) 622 | // C_EngulfingBullish = C_DownTrend and stochrsi_RSIBottom and C_WhiteBody and C_LongBody and C_BlackBody[1] and C_SmallBody[1] and close >= open[1] and open <= close[1] and ( close > open[1] or open < close[1] ) 623 | // alertcondition(C_EngulfingBullish, title = "Engulfing", message = "New Engulfing - Bullish pattern detected.") 624 | // if C_EngulfingBullish and EngulfingInput and (("Bullish" == CandleType) or CandleType == "Both") 625 | 626 | // var ttBullishEngulfing = "Engulfing\nAt the end of a given downward trend, there will most likely be a reversal pattern. To distinguish the first day, this candlestick pattern uses a small body, followed by a day where the candle body fully overtakes the body from the day before, and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to completely overtake the range (high to low), rather only the open and the close." 627 | // label.new(bar_index, patternLabelPosLow, text="BE", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishEngulfing) 628 | // C_EngulfingBearishNumberOfCandles = 2 629 | // C_EngulfingBearish_1 = C_BlackBody and C_LongBody and C_WhiteBody[1] and C_SmallBody[1] and close <= open[1] and open >= close[1] and ( close < open[1] or open > close[1] ) 630 | // C_EngulfingBearish_2 = ((close[1] > open[1]) and (open > close) and (open >= close[1]) and (open[1] >= close) and ((open - close) > (close[1] - open[1]))) 631 | // // C_EngulfingBearish = C_UpTrend and C_BlackBody and C_LongBody and C_WhiteBody[1] and C_SmallBody[1] and close <= open[1] and open >= close[1] and ( close < open[1] or open > close[1] ) 632 | // C_EngulfingBearish = (C_UpTrend and stochrsi_RSITop) and (C_EngulfingBearish_1 or C_EngulfingBearish_2) 633 | // alertcondition(C_EngulfingBearish, title = "Engulfing", message = "New Engulfing - Bearish pattern detected.") 634 | // if C_EngulfingBearish and EngulfingInput and (("Bearish" == CandleType) or CandleType == "Both") 635 | 636 | // var ttBearishEngulfing = "Engulfing\nAt the end of a given uptrend, a reversal pattern will most likely appear. During the first day, this candlestick pattern uses a small body. It is then followed by a day where the candle body fully overtakes the body from the day before it and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to fully overtake the range (high to low), rather only the open and the close." 637 | // label.new(bar_index, patternLabelPosHigh, text="BE", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishEngulfing) 638 | // C_AbandonedBabyBullishNumberOfCandles = 3 639 | // C_AbandonedBabyBullish = C_DownTrend[2] and C_BlackBody[2] and C_IsDojiBody[1] and low[2] > high[1] and C_WhiteBody and high[1] < low 640 | // alertcondition(C_AbandonedBabyBullish, title = "Abandoned Baby", message = "New Abandoned Baby - Bullish pattern detected.") 641 | // if C_AbandonedBabyBullish and AbandonedBabyInput and (("Bullish" == CandleType) or CandleType == "Both") 642 | 643 | // var ttBullishAbandonedBaby = "Abandoned Baby\nThis candlestick pattern is quite rare as far as reversal patterns go. The first of the pattern is a large down candle. Next comes a doji candle that gaps below the candle before it. The doji candle is then followed by another candle that opens even higher and swiftly moves to the upside." 644 | // label.new(bar_index, patternLabelPosLow, text="AB", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishAbandonedBaby) 645 | // C_AbandonedBabyBearishNumberOfCandles = 3 646 | // C_AbandonedBabyBearish = C_UpTrend[2] and C_WhiteBody[2] and C_IsDojiBody[1] and high[2] < low[1] and C_BlackBody and low[1] > high 647 | // alertcondition(C_AbandonedBabyBearish, title = "Abandoned Baby", message = "New Abandoned Baby - Bearish pattern detected.") 648 | // if C_AbandonedBabyBearish and AbandonedBabyInput and (("Bearish" == CandleType) or CandleType == "Both") 649 | 650 | // var ttBearishAbandonedBaby = "Abandoned Baby\nA bearish abandoned baby is a specific candlestick pattern that often signals a downward reversal trend in terms of security price. It is formed when a gap appears between the lowest price of a doji-like candle and the candlestick of the day before. The earlier candlestick is green, tall, and has small shadows. The doji candle is also tailed by a gap between its lowest price point and the highest price point of the candle that comes next, which is red, tall and also has small shadows. The doji candle shadows must completely gap either below or above the shadows of the first and third day in order to have the abandoned baby pattern effect." 651 | // label.new(bar_index, patternLabelPosHigh, text="AB", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishAbandonedBaby) 652 | // C_TriStarBullishNumberOfCandles = 3 653 | // C_3DojisBullish = C_Doji[2] and C_Doji[1] and C_Doji 654 | // C_BodyGapUpBullish = C_BodyHi[1] < C_BodyLo 655 | // C_BodyGapDnBullish = C_BodyLo[1] > C_BodyHi 656 | // C_TriStarBullish = C_3DojisBullish and C_DownTrend[2] and C_BodyGapDnBullish[1] and C_BodyGapUpBullish 657 | // alertcondition(C_TriStarBullish, title = "Tri-Star", message = "New Tri-Star - Bullish pattern detected.") 658 | // if C_TriStarBullish and TriStarInput and (("Bullish" == CandleType) or CandleType == "Both") 659 | 660 | // var ttBullishTriStar = "Tri-Star\nA bullish TriStar candlestick pattern can form when three doji candlesticks materialize in immediate succession at the tail-end of an extended downtrend. The first doji candle marks indecision between bull and bear. The second doji gaps in the direction of the leading trend. The third changes the attitude of the market once the candlestick opens in the direction opposite to the trend. Each doji candle has a shadow, all comparatively shallow, which signify an interim cutback in volatility." 661 | // label.new(bar_index, patternLabelPosLow, text="3S", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishTriStar) 662 | // C_TriStarBearishNumberOfCandles = 3 663 | // C_3Dojis = C_Doji[2] and C_Doji[1] and C_Doji 664 | // C_BodyGapUp = C_BodyHi[1] < C_BodyLo 665 | // C_BodyGapDn = C_BodyLo[1] > C_BodyHi 666 | // C_TriStarBearish = C_3Dojis and C_UpTrend[2] and C_BodyGapUp[1] and C_BodyGapDn 667 | // alertcondition(C_TriStarBearish, title = "Tri-Star", message = "New Tri-Star - Bearish pattern detected.") 668 | // if C_TriStarBearish and TriStarInput and (("Bearish" == CandleType) or CandleType == "Both") 669 | 670 | // var ttBearishTriStar = "Tri-Star\nThis particular pattern can form when three doji candlesticks appear in immediate succession at the end of an extended uptrend. The first doji candle marks indecision between bull and bear. The second doji gaps in the direction of the leading trend. The third changes the attitude of the market once the candlestick opens in the direction opposite to the trend. Each doji candle has a shadow, all comparatively shallow, which signify an interim cutback in volatility." 671 | // label.new(bar_index, patternLabelPosHigh, text="3S", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishTriStar) 672 | // C_KickingBullishNumberOfCandles = 2 673 | // C_MarubozuShadowPercent = 5.0 674 | // C_Marubozu = C_LongBody and C_UpShadow <= C_MarubozuShadowPercent/100*C_Body and C_DnShadow <= C_MarubozuShadowPercent/100*C_Body 675 | // C_MarubozuWhiteBullishKicking = C_Marubozu and C_WhiteBody 676 | // C_MarubozuBlackBullish = C_Marubozu and C_BlackBody 677 | // C_KickingBullish = C_MarubozuBlackBullish[1] and C_MarubozuWhiteBullishKicking and high[1] < low 678 | // alertcondition(C_KickingBullish, title = "Kicking", message = "New Kicking - Bullish pattern detected.") 679 | // if C_KickingBullish and KickingInput and (("Bullish" == CandleType) or CandleType == "Both") 680 | 681 | // var ttBullishKicking = "Kicking\nThe first day candlestick is a bearish marubozu candlestick with next to no upper or lower shadow and where the price opens at the day’s high and closes at the day’s low. The second day is a bullish marubozu pattern, with next to no upper or lower shadow and where the price opens at the day’s low and closes at the day’s high. Additionally, the second day gaps up extensively and opens above the opening price of the day before. This gap or window, as the Japanese call it, lies between day one and day two’s bullish candlesticks." 682 | // label.new(bar_index, patternLabelPosLow, text="K", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishKicking) 683 | // C_KickingBearishNumberOfCandles = 2 684 | // C_MarubozuBullishShadowPercent = 5.0 685 | // C_MarubozuBearishKicking = C_LongBody and C_UpShadow <= C_MarubozuBullishShadowPercent/100*C_Body and C_DnShadow <= C_MarubozuBullishShadowPercent/100*C_Body 686 | // C_MarubozuWhiteBearish = C_MarubozuBearishKicking and C_WhiteBody 687 | // C_MarubozuBlackBearishKicking = C_MarubozuBearishKicking and C_BlackBody 688 | // C_KickingBearish = C_MarubozuWhiteBearish[1] and C_MarubozuBlackBearishKicking and low[1] > high 689 | // alertcondition(C_KickingBearish, title = "Kicking", message = "New Kicking - Bearish pattern detected.") 690 | // if C_KickingBearish and KickingInput and (("Bearish" == CandleType) or CandleType == "Both") 691 | 692 | // var ttBearishKicking = "Kicking\nA bearish kicking pattern will occur, subsequently signaling a reversal for a new downtrend. The first day candlestick is a bullish marubozu. The second day gaps down extensively and opens below the opening price of the day before. There is a gap between day one and two’s bearish candlesticks." 693 | // label.new(bar_index, patternLabelPosHigh, text="K", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishKicking) 694 | // var ttAllCandlestickPatterns = "All Candlestick Patterns\n" 695 | // label.new(bar_index, patternLabelPosLow, text="Collection", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttAllCandlestickPatterns) 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | // /// Classic 705 | // bullCandle = (close > open) 706 | // bullCandleLong = ((close > open) and ((close - open) / (0.001 + high - low) > 0.6)) 707 | // bullCandleSmall = ((close > open) and ((high - low) > (3 * (close - open)))) 708 | 709 | // bearCandle = open < close 710 | // bearCandleLong = ((open > close) and ((open - close) / (0.001 + high - low) > 0.6)) 711 | // bearCandleSmall = ((open > close) and ((high - low) > (3 * (open - close)))) 712 | 713 | // // Marubozu 714 | // bullMarubozu = (close > open) and (high == close) and (open == low) 715 | // bearMarubozu = (open > close) and (high == open) and (close == low) 716 | 717 | // if bullMarubozu and stochrsi_RSIBottom 718 | // var ttBullishMarubozuWhite = "Marubozu White\nA Marubozu White Candle is a candlestick that does not have a shadow that extends from its candle body at either the open or the close. Marubozu is Japanese for “close-cropped” or “close-cut.” Other sources may call it a Bald or Shaven Head Candle." 719 | // label.new(bar_index, patternLabelPosLow, text="MW", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishMarubozuWhite) 720 | 721 | // if bullMarubozu and stochrsi_RSITop 722 | // var ttBearishMarubozuBlack = "Marubozu Black\nThis is a candlestick that has no shadow, which extends from the red-bodied candle at the open, the close, or even at both. In Japanese, the name means “close-cropped” or “close-cut.” The candlestick can also be referred to as Bald or Shaven Head." 723 | // label.new(bar_index, patternLabelPosHigh, text="MB", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishMarubozuBlack) 724 | 725 | // // Doji 726 | // doji = (open == close) 727 | 728 | // if doji 729 | // var ttDoji = "Doji\nWhen the open and close of a security are essentially equal to each other, a doji candle forms. The length of both upper and lower shadows may vary, causing the candlestick you are left with to either resemble a cross, an inverted cross, or a plus sign. Doji candles show the playout of buyer-seller indecision in a tug-of-war of sorts. As price moves either above or below the opening level during the session, the close is either at or near the opening level." 730 | // label.new(bar_index, patternLabelPosLow, text="D", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttDoji) 731 | 732 | // /// Reversal patterns 733 | 734 | // // TODO: Dragonfly Doji 735 | // bullDragonflyDoji = ((abs(open - close) <= 0.02 * (high - low)) and ((high - close) <= 0.3 * (high - low)) and ((high - low) >= (avgh10 - avgl10)) and ( high > low) and (low == minl10)) 736 | // bullDragonflyDoji2 = (((high - low) > 3 * abs(open - close) and (close - low) > 0.8 * (high - low)) and ((open - close) > 0.8 * (high - low))) 737 | // bearDragonflyDoji = ((abs(open - close) <= 0.02 * (high - low)) and ((high - close) <= 0.3 * (high - low)) and ((high - low) >= (avgh10 - avgl10)) and ( high > low) and (high == maxh10)) 738 | 739 | // if bullDragonflyDoji or bullDragonflyDoji2 740 | // var ttBullishDragonflyDoji = "Dragonfly Doji\nSimilar to other Doji days, this particular Doji also regularly appears at pivotal market moments. This is a specific Doji where both the open and close price are at the high of a given day." 741 | // label.new(bar_index, patternLabelPosLow, text="DD", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishDragonflyDoji) 742 | 743 | // if bearDragonflyDoji 744 | // var ttBearishDragonflyDoji = "Dragonfly Doji\nSimilar to other Doji days, this particular Doji also regularly appears at pivotal market moments. This is a specific Doji where both the open and close price are at the high of a given day." 745 | // label.new(bar_index, patternLabelPosLow, text="DD", style=label.style_label_up, color = color.red, textcolor=color.white, tooltip = ttBearishDragonflyDoji) 746 | 747 | // // Gravestone Doji 748 | // // bullGravestoneDoji = (abs(open - close) <= 0.01 * (high - low)) and ((high - close) >= 0.95 * (high - low)) and (high > low) and (low <= low[1] + 0.3 * (high[1] - low[1])) and ((high - low) >= (avgh10 - avgl10)) 749 | // bearGravestoneDoji = (abs(open - close) <= 0.01 * (high - low)) and ((high - close) >= 0.95 * (high - low)) and (high > low) and (high == maxh10) and ((high - low) >= (avgh10 - avgl10)) 750 | // bearGravestoneDoji2 = (abs(close - open) < (high - low) / 3) and (open > close[1]) and ((((close + open) / 2) - low) < 0.4 * (high - low)) and (high == maxh10) 751 | 752 | // if bearGravestoneDoji or bearGravestoneDoji2 753 | // var ttBearishGravestoneDoji = "Gravestone Doji\nWhen a doji is at or is close to the day’s low point, a doji line will develop." 754 | // label.new(bar_index, patternLabelPosHigh, text="GD", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishGravestoneDoji) 755 | 756 | // // Spinning Tops 757 | // bullSpinningTop = (close > open) and ((high - low) > (3 * (close - open)) and (((high - close) / (0.001 + high - low)) < 0.4) and (((open - low) / (0.001 + high - low)) < 0.4)) 758 | // bearSpinningTop = (open > close) and ((high - low) > (3 * (open - close)) and (((high - open) / (0.001 + high - low)) < 0.4) and (((close - low)/(0.001 + high - low)) < 0.4)) 759 | 760 | // if bullSpinningTop 761 | // var ttSpinningTopWhite = "Spinning Top White\nWhite spinning tops are candlestick lines that are small, green-bodied, and possess shadows (upper and lower) that end up exceeding the length of candle bodies. They often signal indecision between buyer and seller." 762 | // label.new(bar_index, patternLabelPosLow, text="STW", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttSpinningTopWhite) 763 | 764 | // if bearSpinningTop 765 | // var ttSpinningTopBlack = "Spinning Top Black\nBlack spinning tops are candlestick lines that are small, red-bodied, and possess shadows (upper and lower) that end up exceeding the length of candle bodies. They often signal indecision." 766 | // label.new(bar_index, patternLabelPosLow, text="STB", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttSpinningTopBlack) 767 | 768 | // // Hammer 769 | // hammer = (((high - low) > 3 * (open - close)) and ((close - low) / (0.001 + high - low) > 0.6) and ((open - low) / (0.001 + high - low) > 0.6)) 770 | 771 | // if hammer and stochrsi_RSIBottom 772 | // var ttBullishHammer = "Hammer\nHammer candlesticks form when a security moves lower after the open, but continues to rally into close above the intraday low. The candlestick that you are left with will look like a square attached to a long stick-like figure. This candlestick is called a Hammer if it happens to form during a decline." 773 | // label.new(bar_index, patternLabelPosLow, text="H", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishHammer) 774 | 775 | // // Hanging Man 776 | // hangingMan = (((high - low) > 4 * (open - close)) and ((close - low) / (0.001 + high - low) >= 0.75) and ((open - low) / (0.001 + high - low) >= 0.75)) 777 | 778 | // if hangingMan and stochrsi_RSITop 779 | // var ttBearishHangingMan = "Hanging Man\nWhen a specified security notably moves lower after the open, but continues to rally to close above the intraday low, a Hanging Man candlestick will form. The candlestick will resemble a square, attached to a long stick-like figure. It is referred to as a Hanging Man if the candlestick forms during an advance." 780 | // label.new(bar_index, patternLabelPosHigh, text="HM", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishHangingMan) 781 | 782 | // // TODO: Belt Hold 783 | // bullBeltHold = (open == mino10) and (open < low[1]) and (close - open) >= 0.7 * (high - low) and (high - low) >= 1.2 * (avgh10 - avgl10) and (open - low) <= 0.01 * (high - low) and (close <= high[1] - 0.5 * (high[1] - low[1])) and (high[1] > low[1]) and (high > low) and (close[1] < close[2]) and (close[2] < close[3]) 784 | // bearBeltHold = (open == maxo10) and (open > high[1]) and (open - close) >= 0.7 * (high - low) and (high - low) >= 1.2 * (avgh10 - avgl10) and (high - open) <= 0.01 * (high - low) and (close >= high[1] - 0.5 * (high[1] - low[1])) and (high[1] > low[1]) and (high > low) and (close[1] > close[2]) and (close[2] < close[3]) 785 | 786 | // // Inverted Hammer 787 | // invertedHammer = (((high - low) > 3 * (open - close)) and ((high - close) / (0.001 + high - low) > 0.6) and ((high - low) / (0.001 + high - low) > 0.6)) 788 | 789 | // if invertedHammer and stochrsi_RSIBottom 790 | // var ttBullishInvertedHammer = "Inverted Hammer\nIf in a downtrend, then the open is lower. When it eventually trades higher, but closes near its open, it will look like an inverted version of the Hammer Candlestick. This is a one-day bullish reversal pattern." 791 | // label.new(bar_index, patternLabelPosLow, text="IH", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishInvertedHammer) 792 | 793 | // // Shooting Star 794 | // shootingStar = (((high - low) > 4 * (open - close)) and ((high - close) / (0.001 + high - low) >= 0.75) and ((high - open) / (0.001 + high - low) >= 0.75)) 795 | 796 | // if shootingStar 797 | // var ttBearishShootingStar = "Shooting Star\nThis single day pattern can appear during an uptrend and opens high, while it closes near its open. It trades much higher as well. It is bearish in nature, but looks like an Inverted Hammer." 798 | // label.new(bar_index, patternLabelPosHigh, text="SS", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishShootingStar) 799 | 800 | // // Evening Star 801 | // eveningStar = ((close[2] > open[2]) and ((close[2] - open[2]) / (0.001 + high[2] - low[2]) > 0.6) and (close[2] < open[1]) and (close[1] > open[1]) and ((high[1] - low[1]) > (3 * (close[1] - open[1]))) and (open > close) and (open < open[1])) 802 | 803 | // if eveningStar 804 | // var ttBearishEveningStar = "Evening Star\nThis candlestick pattern is bearish and continues an uptrend with a long-bodied, green candle day. It is then followed by a gapped and small-bodied candle day, and concludes with a downward close. The close would be below the first day’s midpoint." 805 | // label.new(bar_index, patternLabelPosHigh, text="ES", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishEveningStar) 806 | 807 | // // Morning Star 808 | // morningStar = ((open[2] > close[2]) and ((open[2] - close[2]) / (0.001 + high[2] - low[2]) > 0.6) and (close[2] > open[1]) and (open[1] > close[1]) and ((high[1] - low[1]) > (3 * (close[1] - open[1]))) and (close > open) and (open > open[1])) 809 | 810 | // if morningStar 811 | // var ttBullishMorningStar = "Morning Star\nA three-day bullish reversal pattern, which consists of three candlesticks will look something like this: The first being a long-bodied red candle that extends the current downtrend. Next comes a short, middle candle that gaps down on the open. After comes a long-bodied green candle, which gaps up on the open and closes above the midpoint of the body of the first day." 812 | // label.new(bar_index, patternLabelPosLow, text="MS", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishMorningStar) 813 | 814 | // // Abandoned Baby 815 | // bullAbandonedBaby = ((close[1] == open[1]) and (open[2] > close[2]) and (close > open) and (low[2] > high[1]) and (low > high[1])) 816 | // bearAbandonedBaby = ((close[1] == open[1]) and (close[2] > open[2]) and (open > close) and (low[1] > high[2]) and (low[1] > high)) 817 | 818 | // if bullAbandonedBaby 819 | // var ttBullishAbandonedBaby = "Abandoned Baby\nThis candlestick pattern is quite rare as far as reversal patterns go. The first of the pattern is a large down candle. Next comes a doji candle that gaps below the candle before it. The doji candle is then followed by another candle that opens even higher and swiftly moves to the upside." 820 | // label.new(bar_index, patternLabelPosLow, text="AB", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishAbandonedBaby) 821 | 822 | // if bearAbandonedBaby 823 | // var ttBearishAbandonedBaby = "Abandoned Baby\nA bearish abandoned baby is a specific candlestick pattern that often signals a downward reversal trend in terms of security price. It is formed when a gap appears between the lowest price of a doji-like candle and the candlestick of the day before. The earlier candlestick is green, tall, and has small shadows. The doji candle is also tailed by a gap between its lowest price point and the highest price point of the candle that comes next, which is red, tall and also has small shadows. The doji candle shadows must completely gap either below or above the shadows of the first and third day in order to have the abandoned baby pattern effect." 824 | // label.new(bar_index, patternLabelPosHigh, text="AB", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishAbandonedBaby) 825 | 826 | // // Engulfing 827 | // bullEngulfing = ((open[1] > close[1]) and (close > open) and (close >= open[1]) and (close[1] >= open) and ((close - open) > (open[1] - close[1]))) 828 | // bearEngulfing = ((close[1] > open[1]) and (open > close) and (open >= close[1]) and (open[1] >= close) and ((open - close) > (close[1] - open[1]))) 829 | 830 | // if bullEngulfing and stochrsi_RSIBottom 831 | // var ttBullishEngulfing = "Engulfing\nAt the end of a given downward trend, there will most likely be a reversal pattern. To distinguish the first day, this candlestick pattern uses a small body, followed by a day where the candle body fully overtakes the body from the day before, and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to completely overtake the range (high to low), rather only the open and the close." 832 | // label.new(bar_index, patternLabelPosLow, text="BE", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishEngulfing) 833 | 834 | // if bearEngulfing and stochrsi_RSITop 835 | // var ttBearishEngulfing = "Engulfing\nAt the end of a given uptrend, a reversal pattern will most likely appear. During the first day, this candlestick pattern uses a small body. It is then followed by a day where the candle body fully overtakes the body from the day before it and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to fully overtake the range (high to low), rather only the open and the close." 836 | // label.new(bar_index, patternLabelPosHigh, text="BE", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishEngulfing) 837 | 838 | // // Harami 839 | // bullHarami = ((open[1] > close[1]) and (close > open) and (close <= open[1]) and (close[1] <= open) and ((close - open) < (open[1] - close[1]))) 840 | // bearHarami = ((close[1] > open[1]) and (open > close) and (open <= close[1]) and (open[1] <= close) and ((open - close) < (close[1] - open[1]))) 841 | 842 | // if bullHarami and stochrsi_RSIBottom 843 | // var ttBullishHarami = "Harami\nThis two-day candlestick pattern consists of a small-bodied green candle that is entirely encompassed within the body of what was once a red-bodied candle." 844 | // label.new(bar_index, patternLabelPosLow, text="BH", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishHarami) 845 | 846 | // if bearHarami and stochrsi_RSITop 847 | // var ttBearishHarami = "Harami\nThis is a two-day candlestick pattern with a small, red-bodied candle that is entirely encompassed within the body that was once a green-bodied candle." 848 | // label.new(bar_index, patternLabelPosHigh, text="BH", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishHarami) 849 | -------------------------------------------------------------------------------- /CandleReconUltimateOld.pscript: -------------------------------------------------------------------------------- 1 | // © KrustyHack 2 | 3 | //@version=4 4 | study("Candle Recon Ultimate", shorttitle="CRU", overlay=true) 5 | 6 | // START misc. options 7 | // 10 days high price moving average 8 | avgh10 = high[1] + high[2] + high[3] + high[4] + high[5] + high[6] + high[7] + high[8] + high[9] + high[10] / 10 9 | 10 | // 10 days low price moving average 11 | avgl10 = low[1] + low[2] + low[3] + low[4] + low[5] + low[6] + low[7] + low[8] + low[9] + low[10] / 10 12 | 13 | // Lowest low over 10 past periods 14 | minl10 = lowest(low, 10) 15 | 16 | // Highest high over 10 past periods 17 | maxh10 = highest(high, 10) 18 | 19 | // Lowest open price over 10 past periods 20 | mino10 = lowest(open, 10) 21 | 22 | // Highest open price over 10 past periods 23 | maxo10 = highest(open, 10) 24 | 25 | C_DownTrend = true 26 | C_UpTrend = true 27 | var trendRule1 = "SMA50" 28 | var trendRule2 = "SMA50, SMA200" 29 | var trendRule = input(trendRule1, "Detect Trend Based On", options=[trendRule1, trendRule2, "No detection"]) 30 | 31 | if trendRule == trendRule1 32 | priceAvg = sma(close, 50) 33 | C_DownTrend := close < priceAvg 34 | C_UpTrend := close > priceAvg 35 | 36 | if trendRule == trendRule2 37 | sma200 = sma(close, 200) 38 | sma50 = sma(close, 50) 39 | C_DownTrend := close < sma50 and sma50 < sma200 40 | C_UpTrend := close > sma50 and sma50 > sma200 41 | C_Len = 14 // ema depth for bodyAvg 42 | C_ShadowPercent = 5.0 // size of shadows 43 | C_ShadowEqualsPercent = 100.0 44 | C_DojiBodyPercent = 5.0 45 | C_Factor = 2.0 // shows the number of times the shadow dominates the candlestick body 46 | 47 | C_BodyHi = max(close, open) 48 | C_BodyLo = min(close, open) 49 | C_Body = C_BodyHi - C_BodyLo 50 | C_BodyAvg = ema(C_Body, C_Len) 51 | C_SmallBody = C_Body < C_BodyAvg 52 | C_LongBody = C_Body > C_BodyAvg 53 | C_UpShadow = high - C_BodyHi 54 | C_DnShadow = C_BodyLo - low 55 | C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body 56 | C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body 57 | C_WhiteBody = open < close 58 | C_BlackBody = open > close 59 | C_Range = high-low 60 | C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo 61 | C_BodyMiddle = C_Body / 2 + C_BodyLo 62 | C_ShadowEquals = C_UpShadow == C_DnShadow or (abs(C_UpShadow - C_DnShadow) / C_DnShadow * 100) < C_ShadowEqualsPercent and (abs(C_DnShadow - C_UpShadow) / C_UpShadow * 100) < C_ShadowEqualsPercent 63 | C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100 64 | C_Doji = C_IsDojiBody and C_ShadowEquals 65 | 66 | patternLabelPosLow = low - (atr(30) * 0.6) 67 | patternLabelPosHigh = high + (atr(30) * 0.6) 68 | 69 | // END misc. options 70 | 71 | // START Stochastic RSI 72 | stochrsi_smoothK = input(3, minval=1) 73 | stochrsi_smoothD = input(3, minval=1) 74 | stochrsi_lengthRSI = input(14, minval=1) 75 | stochrsi_lengthStoch = input(14, minval=1) 76 | stochrsi_src = input(close, title="RSI Source") 77 | 78 | stochrsi_rsi1 = rsi(stochrsi_src, stochrsi_lengthRSI) 79 | stochrsi_k = sma(stoch(stochrsi_rsi1, stochrsi_rsi1, stochrsi_rsi1, stochrsi_lengthStoch), stochrsi_smoothK) 80 | stochrsi_d = sma(stochrsi_k, stochrsi_smoothD) 81 | // plot(k, color=blue) 82 | // plot(d, color=orange) 83 | // stochrsi_h0 = hline(80) 84 | // stochrsi_h1 = hline(20) 85 | // fill(h0, h1, color=purple, transp=80) 86 | 87 | stochrsi_RSIComingDown = crossunder(stochrsi_k, stochrsi_d) and stochrsi_k >= 80 88 | stochrsi_RSITop = stochrsi_k > 80 89 | stochrsi_RSIComingUp = crossover(stochrsi_k, stochrsi_d) and stochrsi_k <= 30 90 | stochrsi_RSIBottom = stochrsi_k < 30 91 | // END Stochastic RSI 92 | 93 | // START Ichimoku 94 | tenkanSenPeriods = 9 95 | kijunSenPeriods = 26 96 | chikouSpanPeriods = 52 97 | displacement = 26 98 | donchian(len) => avg(lowest(len), highest(len)) 99 | tenkanSen = donchian(tenkanSenPeriods) 100 | kijunSen = donchian(kijunSenPeriods) 101 | senkouSpanA = avg(tenkanSen, kijunSen) 102 | senkouSpanB = donchian(chikouSpanPeriods) 103 | 104 | ichimokuUpTrend = (senkouSpanA > senkouSpanB) and (close > close[26]) 105 | ichimokuDownTrend = (senkouSpanA < senkouSpanB) and (close < close[26]) 106 | 107 | plot(tenkanSen, color=#2196f3, title="Tenkan Sen", linewidth=1, transp=50) 108 | plot(kijunSen, color=#b71c1c, title="Kijun Sen", linewidth=1, transp=50) 109 | plot(close, offset = -displacement + 1, color=#FFFFFF, title="Chikou Span", linewidth=1, transp=50) 110 | 111 | p1 = plot(senkouSpanA, offset = displacement - 1, color=color.green, 112 | title="Senkou Span A", transp=100) 113 | p2 = plot(senkouSpanB, offset = displacement - 1, color=color.red, 114 | title="Senkou Span B", transp=100, linewidth=2) 115 | fill(p1, p2, color = senkouSpanA > senkouSpanB ? color.green : color.red, transp=85) 116 | 117 | // END Ichimoku 118 | 119 | 120 | // Bearish Engulfing 121 | C_EngulfingBearishNumberOfCandles = 2 122 | C_EngulfingBearish_1 = C_BlackBody and C_LongBody and C_WhiteBody[1] and C_SmallBody[1] and close <= open[1] and open >= close[1] and ( close < open[1] or open > close[1] ) 123 | C_EngulfingBearish_2 = ((close[1] > open[1]) and (open > close) and (open >= close[1]) and (open[1] >= close) and ((open - close) > (close[1] - open[1]))) 124 | C_EngulfingBearish = (ichimokuUpTrend and stochrsi_RSITop) and (C_EngulfingBearish_1 or C_EngulfingBearish_2) 125 | 126 | alertcondition(C_EngulfingBearish, title = "Engulfing", message = "New Engulfing - Bearish pattern detected.") 127 | 128 | if C_EngulfingBearish 129 | var ttBearishEngulfing = "Engulfing\nAt the end of a given uptrend, a reversal pattern will most likely appear. During the first day, this candlestick pattern uses a small body. It is then followed by a day where the candle body fully overtakes the body from the day before it and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to fully overtake the range (high to low), rather only the open and the close." 130 | label.new(bar_index, patternLabelPosHigh, text="BE", style=label.style_label_down, size = size.tiny, color = color.red, textcolor=color.black, tooltip = ttBearishEngulfing) 131 | 132 | 133 | // Bullish Engulfing 134 | C_EngulfingBullishNumberOfCandles = 2 135 | C_EngulfingBullish_1 = C_WhiteBody and C_LongBody and C_BlackBody[1] and C_SmallBody[1] and close >= open[1] and open <= close[1] and ( close > open[1] or open < close[1] ) 136 | C_EngulfingBullish_2 = ((open[1] > close[1]) and (close > open) and (close >= open[1]) and (close[1] >= open) and ((close - open) > (open[1] - close[1]))) 137 | C_EngulfingBullish = (ichimokuDownTrend and stochrsi_RSIBottom) and (C_EngulfingBullish_1 or C_EngulfingBullish_2) 138 | 139 | alertcondition(C_EngulfingBullish, title = "Engulfing", message = "New Engulfing - Bullish pattern detected.") 140 | 141 | if C_EngulfingBullish 142 | var ttBullishEngulfing = "Engulfing\nAt the end of a given downward trend, there will most likely be a reversal pattern. To distinguish the first day, this candlestick pattern uses a small body, followed by a day where the candle body fully overtakes the body from the day before, and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to completely overtake the range (high to low), rather only the open and the close." 143 | label.new(bar_index, patternLabelPosLow, text="BE", style=label.style_label_up, size = size.tiny, color = color.blue, textcolor=color.white, tooltip = ttBullishEngulfing) 144 | 145 | 146 | // Bullish Hammer 147 | C_HammerBullishNumberOfCandles = 1 148 | C_HammerBullish_1 = C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body 149 | C_HammerBullish_2 = (((high - low) > 3 * (open - close)) and ((close - low) / (0.001 + high - low) > 0.6) and ((open - low) / (0.001 + high - low) > 0.6)) 150 | C_HammerBullish = (ichimokuDownTrend and stochrsi_RSIBottom) and (C_HammerBullish_1 or C_HammerBullish_2) 151 | 152 | alertcondition(C_HammerBullish, title = "Hammer", message = "New Hammer - Bullish pattern detected.") 153 | 154 | if C_HammerBullish 155 | var ttBullishHammer = "Hammer\nHammer candlesticks form when a security moves lower after the open, but continues to rally into close above the intraday low. The candlestick that you are left with will look like a square attached to a long stick-like figure. This candlestick is called a Hammer if it happens to form during a decline." 156 | label.new(bar_index, patternLabelPosLow, text="H", style=label.style_label_up, size = size.tiny, color = color.blue, textcolor=color.white, tooltip = ttBullishHammer) 157 | 158 | 159 | // Bearish Hanging Man 160 | C_HangingManBearishNumberOfCandles = 1 161 | C_HangingManBearish_1 = C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body 162 | C_HangingManBearish_2 = (((high - low) > 4 * (open - close)) and ((close - low) / (0.001 + high - low) >= 0.75) and ((open - low) / (0.001 + high - low) >= 0.75)) 163 | C_HangingManBearish = (ichimokuUpTrend and stochrsi_RSITop) and (C_HangingManBearish_2) 164 | 165 | alertcondition(C_HangingManBearish, title = "Hanging Man", message = "New Hanging Man - Bearish pattern detected.") 166 | 167 | if C_HangingManBearish 168 | var ttBearishHangingMan = "Hanging Man\nWhen a specified security notably moves lower after the open, but continues to rally to close above the intraday low, a Hanging Man candlestick will form. The candlestick will resemble a square, attached to a long stick-like figure. It is referred to as a Hanging Man if the candlestick forms during an advance." 169 | label.new(bar_index, patternLabelPosHigh, text="HM", style=label.style_label_down, size = size.tiny, color = color.red, textcolor=color.black, tooltip = ttBearishHangingMan) 170 | 171 | 172 | // Bullish Inverted Hammer 173 | C_InvertedHammerBullishNumberOfCandles = 1 174 | C_InvertedHammerBullish_1 = C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow 175 | // TODO: seems broken 176 | // C_InvertedHammerBullish_2 = (((high - low) > 3 * (open - close)) and ((high - close) / (0.001 + high - low) > 0.6) and ((high - low) / (0.001 + high - low) > 0.6)) 177 | C_InvertedHammerBullish = (ichimokuDownTrend and stochrsi_RSIBottom) and (C_InvertedHammerBullish_1) 178 | 179 | alertcondition(C_InvertedHammerBullish, title = "Inverted Hammer", message = "New Inverted Hammer - Bullish pattern detected.") 180 | 181 | if C_InvertedHammerBullish 182 | var ttBullishInvertedHammer = "Inverted Hammer\nIf in a downtrend, then the open is lower. When it eventually trades higher, but closes near its open, it will look like an inverted version of the Hammer Candlestick. This is a one-day bullish reversal pattern." 183 | label.new(bar_index, patternLabelPosLow, text="IH", style=label.style_label_up, size = size.tiny, color = color.blue, textcolor=color.white, tooltip = ttBullishInvertedHammer) 184 | 185 | 186 | // Bearish Shooting Star 187 | C_ShootingStarBearishNumberOfCandles = 1 188 | C_ShootingStarBearish_1 = C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body 189 | C_ShootingStarBearish_2 = (((high - low) > 4 * (open - close)) and ((high - close) / (0.001 + high - low) >= 0.75) and ((high - open) / (0.001 + high - low) >= 0.75)) 190 | C_ShootingStarBearish = (stochrsi_RSITop) and (C_ShootingStarBearish_2) 191 | 192 | alertcondition(C_ShootingStarBearish, title = "Shooting Star", message = "New Shooting Star - Bearish pattern detected.") 193 | 194 | if C_ShootingStarBearish 195 | var ttBearishShootingStar = "Shooting Star\nThis single day pattern can appear during an uptrend and opens high, while it closes near its open. It trades much higher as well. It is bearish in nature, but looks like an Inverted Hammer." 196 | label.new(bar_index, patternLabelPosHigh, text="SS", style=label.style_label_down, size = size.tiny, color = color.red, textcolor=color.black, tooltip = ttBearishShootingStar) 197 | // AbandonedBabyInput = input(title = "Abandoned Baby" ,defval=false) 198 | 199 | // DarkCloudCoverInput = input(title = "Dark Cloud Cover" ,defval=false) 200 | 201 | // DojiInput = input(title = "Doji" ,defval=false) 202 | 203 | // DojiStarInput = input(title = "Doji Star" ,defval=false) 204 | 205 | // DownsideTasukiGapInput = input(title = "Downside Tasuki Gap" ,defval=false) 206 | 207 | // DragonflyDojiInput = input(title = "Dragonfly Doji" ,defval=false) 208 | 209 | // EveningDojiStarInput = input(title = "Evening Doji Star" ,defval=false) 210 | 211 | // EveningStarInput = input(title = "Evening Star" ,defval=true) 212 | 213 | // FallingThreeMethodsInput = input(title = "Falling Three Methods" ,defval=false) 214 | 215 | // FallingWindowInput = input(title = "Falling Window" ,defval=false) 216 | 217 | // GravestoneDojiInput = input(title = "Gravestone Doji" ,defval=false) 218 | 219 | // HaramiCrossInput = input(title = "Harami Cross" ,defval=false) 220 | 221 | // HaramiInput = input(title = "Harami" ,defval=false) 222 | 223 | // KickingInput = input(title = "Kicking" ,defval=false) 224 | 225 | // LongLowerShadowInput = input(title = "Long Lower Shadow" ,defval=false) 226 | 227 | // LongUpperShadowInput = input(title = "Long Upper Shadow" ,defval=false) 228 | 229 | // MarubozuBlackInput = input(title = "Marubozu Black" ,defval=false) 230 | 231 | // MarubozuWhiteInput = input(title = "Marubozu White" ,defval=false) 232 | 233 | // MorningDojiStarInput = input(title = "Morning Doji Star" ,defval=false) 234 | 235 | // MorningStarInput = input(title = "Morning Star" ,defval=true) 236 | 237 | // OnNeckInput = input(title = "On Neck" ,defval=false) 238 | 239 | // PiercingInput = input(title = "Piercing" ,defval=false) 240 | 241 | // RisingThreeMethodsInput = input(title = "Rising Three Methods" ,defval=false) 242 | 243 | // RisingWindowInput = input(title = "Rising Window" ,defval=false) 244 | 245 | // SpinningTopBlackInput = input(title = "Spinning Top Black" ,defval=false) 246 | 247 | // SpinningTopWhiteInput = input(title = "Spinning Top White" ,defval=false) 248 | 249 | // ThreeBlackCrowsInput = input(title = "Three Black Crows" ,defval=false) 250 | 251 | // ThreeWhiteSoldiersInput = input(title = "Three White Soldiers" ,defval=false) 252 | 253 | // TriStarInput = input(title = "Tri-Star" ,defval=false) 254 | 255 | // TweezerBottomInput = input(title = "Tweezer Bottom" ,defval=false) 256 | 257 | // TweezerTopInput = input(title = "Tweezer Top" ,defval=false) 258 | 259 | // UpsideTasukiGapInput = input(title = "Upside Tasuki Gap" ,defval=false) 260 | 261 | // C_OnNeckBearishNumberOfCandles = 2 262 | // C_OnNeckBearish = false 263 | // if C_DownTrend and C_BlackBody[1] and C_LongBody[1] and C_WhiteBody and open < close[1] and C_SmallBody and C_Range!=0 and abs(close-low[1])<=C_BodyAvg*0.05 264 | // C_OnNeckBearish := true 265 | // alertcondition(C_OnNeckBearish, title = "On Neck", message = "New On Neck - Bearish pattern detected.") 266 | // if C_OnNeckBearish and OnNeckInput and (("Bearish" == CandleType) or CandleType == "Both") 267 | 268 | // var ttBearishOnNeck = "On Neck\nOn Neck is a two-line continuation pattern found in a downtrend. The first candle is long and red, the second candle is short and has a green body. The closing price of the second candle is close or equal to the first candle's low price. The pattern hints at a continuation of a downtrend, and penetrating the low of the green candlestick is sometimes considered a confirmation. " 269 | // label.new(bar_index, patternLabelPosHigh, text="ON", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishOnNeck) 270 | // C_RisingWindowBullishNumberOfCandles = 2 271 | // C_RisingWindowBullish = false 272 | // if C_UpTrend[1] and (C_Range!=0 and C_Range[1]!=0) and low > high[1] 273 | // C_RisingWindowBullish := true 274 | // alertcondition(C_RisingWindowBullish, title = "Rising Window", message = "New Rising Window - Bullish pattern detected.") 275 | // if C_RisingWindowBullish and RisingWindowInput and (("Bullish" == CandleType) or CandleType == "Both") 276 | 277 | // var ttBullishRisingWindow = "Rising Window\nRising Window is a two-candle bullish continuation pattern that forms during an uptrend. Both candles in the pattern can be of any type with the exception of the Four-Price Doji. The most important characteristic of the pattern is a price gap between the first candle's high and the second candle's low. That gap (window) between two bars signifies support against the selling pressure." 278 | // label.new(bar_index, patternLabelPosLow, text="RW", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishRisingWindow) 279 | // C_FallingWindowBearishNumberOfCandles = 2 280 | // C_FallingWindowBearish = false 281 | // if C_DownTrend[1] and (C_Range!=0 and C_Range[1]!=0) and high < low[1] 282 | // C_FallingWindowBearish := true 283 | // alertcondition(C_FallingWindowBearish, title = "Falling Window", message = "New Falling Window - Bearish pattern detected.") 284 | // if C_FallingWindowBearish and FallingWindowInput and (("Bearish" == CandleType) or CandleType == "Both") 285 | 286 | // var ttBearishFallingWindow = "Falling Window\nFalling Window is a two-candle bearish continuation pattern that forms during a downtrend. Both candles in the pattern can be of any type, with the exception of the Four-Price Doji. The most important characteristic of the pattern is a price gap between the first candle's low and the second candle's high. The existence of this gap (window) means that the bearish trend is expected to continue." 287 | // label.new(bar_index, patternLabelPosHigh, text="FW", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishFallingWindow) 288 | // C_FallingThreeMethodsBearishNumberOfCandles = 5 289 | // C_FallingThreeMethodsBearish = false 290 | // if C_DownTrend[4] and (C_LongBody[4] and C_BlackBody[4]) and (C_SmallBody[3] and C_WhiteBody[3] and open[3]>low[4] and close[3]low[4] and close[2]low[4] and close[1]low[4]) and (C_SmallBody[2] and C_BlackBody[2] and open[2]low[4]) and (C_SmallBody[1] and C_BlackBody[1] and open[1]low[4]) and (C_LongBody and C_WhiteBody and close>close[4]) 300 | // C_RisingThreeMethodsBullish := true 301 | // alertcondition(C_RisingThreeMethodsBullish, title = "Rising Three Methods", message = "New Rising Three Methods - Bullish pattern detected.") 302 | // if C_RisingThreeMethodsBullish and RisingThreeMethodsInput and (("Bullish" == CandleType) or CandleType == "Both") 303 | 304 | // var ttBullishRisingThreeMethods = "Rising Three Methods\nRising Three Methods is a five-candle bullish pattern that signifies a continuation of an existing uptrend. The first candle is long and green, followed by three short red candles with bodies inside the range of the first candle. The last candle is also green and long and it closes above the close of the first candle. This decisive fifth strongly bullish candle hints that bears could not reverse the prior uptrend and that bulls have regained control of the market." 305 | // label.new(bar_index, patternLabelPosLow, text="RTM", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishRisingThreeMethods) 306 | // C_TweezerTopBearishNumberOfCandles = 2 307 | // C_TweezerTopBearish = false 308 | // if C_UpTrend[1] and (not C_IsDojiBody or (C_HasUpShadow and C_HasDnShadow)) and abs(high-high[1]) <= C_BodyAvg*0.05 and C_WhiteBody[1] and C_BlackBody and C_LongBody[1] 309 | // C_TweezerTopBearish := true 310 | // alertcondition(C_TweezerTopBearish, title = "Tweezer Top", message = "New Tweezer Top - Bearish pattern detected.") 311 | // if C_TweezerTopBearish and TweezerTopInput and (("Bearish" == CandleType) or CandleType == "Both") 312 | 313 | // var ttBearishTweezerTop = "Tweezer Top\nTweezer Top is a two-candle pattern that signifies a potential bearish reversal. The pattern is found during an uptrend. The first candle is long and green, the second candle is red, and its high is nearly identical to the high of the previous candle. The virtually identical highs, together with the inverted directions, hint that bears might be taking over the market." 314 | // label.new(bar_index, patternLabelPosHigh, text="TT", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishTweezerTop) 315 | // C_TweezerBottomBullishNumberOfCandles = 2 316 | // C_TweezerBottomBullish = false 317 | // if C_UpTrend[1] and (not C_IsDojiBody or (C_HasUpShadow and C_HasDnShadow)) and abs(low-low[1]) <= C_BodyAvg*0.05 and C_BlackBody[1] and C_WhiteBody and C_LongBody[1] 318 | // C_TweezerBottomBullish := true 319 | // alertcondition(C_TweezerBottomBullish, title = "Tweezer Bottom", message = "New Tweezer Bottom - Bullish pattern detected.") 320 | // if C_TweezerBottomBullish and TweezerBottomInput and (("Bullish" == CandleType) or CandleType == "Both") 321 | 322 | // var ttBullishTweezerBottom = "Tweezer Bottom\nTweezer Bottom is a two-candle pattern that signifies a potential bullish reversal. The pattern is found during a downtrend. The first candle is long and red, the second candle is green, its lows nearly identical to the low of the previous candle. The virtually identical lows together with the inverted directions hint that bulls might be taking over the market." 323 | // label.new(bar_index, patternLabelPosLow, text="TB", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishTweezerBottom) 324 | // C_DarkCloudCoverBearishNumberOfCandles = 2 325 | // C_DarkCloudCoverBearish = false 326 | // if (C_UpTrend[1] and C_WhiteBody[1] and C_LongBody[1]) and (C_BlackBody and open >= high[1] and close < C_BodyMiddle[1] and close > open[1]) 327 | // C_DarkCloudCoverBearish := true 328 | // alertcondition(C_DarkCloudCoverBearish, title = "Dark Cloud Cover", message = "New Dark Cloud Cover - Bearish pattern detected.") 329 | // if C_DarkCloudCoverBearish and DarkCloudCoverInput and (("Bearish" == CandleType) or CandleType == "Both") 330 | 331 | // var ttBearishDarkCloudCover = "Dark Cloud Cover\nDark Cloud Cover is a two-candle bearish reversal candlestick pattern found in an uptrend. The first candle is green and has a larger than average body. The second candle is red and opens above the high of the prior candle, creating a gap, and then closes below the midpoint of the first candle. The pattern shows a possible shift in the momentum from the upside to the downside, indicating that a reversal might happen soon." 332 | // label.new(bar_index, patternLabelPosHigh, text="DCC", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishDarkCloudCover) 333 | // C_DownsideTasukiGapBearishNumberOfCandles = 3 334 | // C_DownsideTasukiGapBearish = false 335 | // if C_LongBody[2] and C_SmallBody[1] and C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] and C_BlackBody[1] and C_WhiteBody and C_BodyHi <= C_BodyLo[2] and C_BodyHi >= C_BodyHi[1] 336 | // C_DownsideTasukiGapBearish := true 337 | // alertcondition(C_DownsideTasukiGapBearish, title = "Downside Tasuki Gap", message = "New Downside Tasuki Gap - Bearish pattern detected.") 338 | // if C_DownsideTasukiGapBearish and DownsideTasukiGapInput and (("Bearish" == CandleType) or CandleType == "Both") 339 | 340 | // var ttBearishDownsideTasukiGap = "Downside Tasuki Gap\nDownside Tasuki Gap is a three-candle pattern found in a downtrend that usually hints at the continuation of the downtrend. The first candle is long and red, followed by a smaller red candle with its opening price that gaps below the body of the previous candle. The third candle is green and it closes inside the gap created by the first two candles, unable to close it fully. The bull’s inability to close that gap hints that the downtrend might continue." 341 | // label.new(bar_index, patternLabelPosHigh, text="DTG", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishDownsideTasukiGap) 342 | // C_UpsideTasukiGapBullishNumberOfCandles = 3 343 | // C_UpsideTasukiGapBullish = false 344 | // if C_LongBody[2] and C_SmallBody[1] and C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_WhiteBody[1] and C_BlackBody and C_BodyLo >= C_BodyHi[2] and C_BodyLo <= C_BodyLo[1] 345 | // C_UpsideTasukiGapBullish := true 346 | // alertcondition(C_UpsideTasukiGapBullish, title = "Upside Tasuki Gap", message = "New Upside Tasuki Gap - Bullish pattern detected.") 347 | // if C_UpsideTasukiGapBullish and UpsideTasukiGapInput and (("Bullish" == CandleType) or CandleType == "Both") 348 | 349 | // var ttBullishUpsideTasukiGap = "Upside Tasuki Gap\nUpside Tasuki Gap is a three-candle pattern found in an uptrend that usually hints at the continuation of the uptrend. The first candle is long and green, followed by a smaller green candle with its opening price that gaps above the body of the previous candle. The third candle is red and it closes inside the gap created by the first two candles, unable to close it fully. The bear’s inability to close the gap hints that the uptrend might continue." 350 | // label.new(bar_index, patternLabelPosLow, text="UTG", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishUpsideTasukiGap) 351 | // C_EveningDojiStarBearishNumberOfCandles = 3 352 | // C_EveningDojiStarBearish = false 353 | // if C_LongBody[2] and C_IsDojiBody[1] and C_LongBody and C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_BlackBody and C_BodyLo <= C_BodyMiddle[2] and C_BodyLo > C_BodyLo[2] and C_BodyLo[1] > C_BodyHi 354 | // C_EveningDojiStarBearish := true 355 | // alertcondition(C_EveningDojiStarBearish, title = "Evening Doji Star", message = "New Evening Doji Star - Bearish pattern detected.") 356 | // if C_EveningDojiStarBearish and EveningDojiStarInput and (("Bearish" == CandleType) or CandleType == "Both") 357 | 358 | // var ttBearishEveningDojiStar = "Evening Doji Star\nThis candlestick pattern is a variation of the Evening Star pattern. It is bearish and continues an uptrend with a long-bodied, green candle day. It is then followed by a gap and a Doji candle and concludes with a downward close. The close would be below the first day’s midpoint. It is more bearish than the regular evening star pattern because of the existence of the Doji." 359 | // label.new(bar_index, patternLabelPosHigh, text="EDS", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishEveningDojiStar) 360 | // C_DojiStarBearishNumberOfCandles = 2 361 | // C_DojiStarBearish = false 362 | // if C_UpTrend and C_WhiteBody[1] and C_LongBody[1] and C_IsDojiBody and C_BodyLo > C_BodyHi[1] 363 | // C_DojiStarBearish := true 364 | // alertcondition(C_DojiStarBearish, title = "Doji Star", message = "New Doji Star - Bearish pattern detected.") 365 | // if C_DojiStarBearish and DojiStarInput and (("Bearish" == CandleType) or CandleType == "Both") 366 | 367 | // var ttBearishDojiStar = "Doji Star\nThis is a bearish reversal candlestick pattern that is found in an uptrend and consists of two candles. First comes a long green candle, followed by a Doji candle (except 4-Price Doji) that opens above the body of the first one, creating a gap. It is considered a reversal signal with confirmation during the next trading day." 368 | // label.new(bar_index, patternLabelPosHigh, text="DS", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishDojiStar) 369 | // C_DojiStarBullishNumberOfCandles = 2 370 | // C_DojiStarBullish = false 371 | // if C_DownTrend and C_BlackBody[1] and C_LongBody[1] and C_IsDojiBody and C_BodyHi < C_BodyLo[1] 372 | // C_DojiStarBullish := true 373 | // alertcondition(C_DojiStarBullish, title = "Doji Star", message = "New Doji Star - Bullish pattern detected.") 374 | // if C_DojiStarBullish and DojiStarInput and (("Bullish" == CandleType) or CandleType == "Both") 375 | 376 | // var ttBullishDojiStar = "Doji Star\nThis is a bullish reversal candlestick pattern that is found in a downtrend and consists of two candles. First comes a long red candle, followed by a Doji candle (except 4-Price Doji) that opens below the body of the first one, creating a gap. It is considered a reversal signal with confirmation during the next trading day." 377 | // label.new(bar_index, patternLabelPosLow, text="DS", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishDojiStar) 378 | // C_MorningDojiStarBullishNumberOfCandles = 3 379 | // C_MorningDojiStarBullish = false 380 | // if C_LongBody[2] and C_IsDojiBody[1] and C_LongBody and C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] and C_WhiteBody and C_BodyHi >= C_BodyMiddle[2] and C_BodyHi < C_BodyHi[2] and C_BodyHi[1] < C_BodyLo 381 | // C_MorningDojiStarBullish := true 382 | // alertcondition(C_MorningDojiStarBullish, title = "Morning Doji Star", message = "New Morning Doji Star - Bullish pattern detected.") 383 | // if C_MorningDojiStarBullish and MorningDojiStarInput and (("Bullish" == CandleType) or CandleType == "Both") 384 | 385 | // var ttBullishMorningDojiStar = "Morning Doji Star\nThis candlestick pattern is a variation of the Morning Star pattern. A three-day bullish reversal pattern, which consists of three candlesticks will look something like this: The first being a long-bodied red candle that extends the current downtrend. Next comes a Doji that gaps down on the open. After that comes a long-bodied green candle, which gaps up on the open and closes above the midpoint of the body of the first day. It is more bullish than the regular morning star pattern because of the existence of the Doji." 386 | // label.new(bar_index, patternLabelPosLow, text="MDS", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishMorningDojiStar) 387 | // C_PiercingBullishNumberOfCandles = 2 388 | // C_PiercingBullish = false 389 | // if (C_DownTrend[1] and C_BlackBody[1] and C_LongBody[1]) and (C_WhiteBody and open <= low[1] and close > C_BodyMiddle[1] and close < open[1]) 390 | // C_PiercingBullish := true 391 | // alertcondition(C_PiercingBullish, title = "Piercing", message = "New Piercing - Bullish pattern detected.") 392 | // if C_PiercingBullish and PiercingInput and (("Bullish" == CandleType) or CandleType == "Both") 393 | 394 | // var ttBullishPiercing = "Piercing\nPiercing is a two-candle bullish reversal candlestick pattern found in a downtrend. The first candle is red and has a larger than average body. The second candle is green and opens below the low of the prior candle, creating a gap, and then closes above the midpoint of the first candle. The pattern shows a possible shift in the momentum from the downside to the upside, indicating that a reversal might happen soon." 395 | // label.new(bar_index, patternLabelPosLow, text="P", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishPiercing) 396 | // C_HammerBullishNumberOfCandles = 1 397 | // // C_HammerBullish = C_DownTrend and C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow 398 | // C_HammerBullish = stochrsi_RSIBottom and C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow 399 | 400 | // alertcondition(C_HammerBullish, title = "Hammer", message = "New Hammer - Bullish pattern detected.") 401 | // if C_HammerBullish and HammerInput and (("Bullish" == CandleType) or CandleType == "Both") 402 | 403 | // var ttBullishHammer = "Hammer\nHammer candlesticks form when a security moves lower after the open, but continues to rally into close above the intraday low. The candlestick that you are left with will look like a square attached to a long stick-like figure. This candlestick is called a Hammer if it happens to form during a decline." 404 | // label.new(bar_index, patternLabelPosLow, text="H", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishHammer) 405 | // C_HangingManBearishNumberOfCandles = 1 406 | // // C_HangingManBearish = C_UpTrend and C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow 407 | // C_HangingManBearish = stochrsi_RSITop and C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow 408 | 409 | // alertcondition(C_HangingManBearish, title = "Hanging Man", message = "New Hanging Man - Bearish pattern detected.") 410 | // if C_HangingManBearish and HangingManInput and (("Bearish" == CandleType) or CandleType == "Both") 411 | 412 | // var ttBearishHangingMan = "Hanging Man\nWhen a specified security notably moves lower after the open, but continues to rally to close above the intraday low, a Hanging Man candlestick will form. The candlestick will resemble a square, attached to a long stick-like figure. It is referred to as a Hanging Man if the candlestick forms during an advance." 413 | // label.new(bar_index, patternLabelPosHigh, text="HM", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishHangingMan) 414 | 415 | 416 | // C_ShootingStarBearishNumberOfCandles = 1 417 | // // C_ShootingStarBearish = C_UpTrend and C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow 418 | // C_ShootingStarBearish = C_UpTrend and stochrsi_RSIBottom and C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow 419 | 420 | // alertcondition(C_ShootingStarBearish, title = "Shooting Star", message = "New Shooting Star - Bearish pattern detected.") 421 | // if C_ShootingStarBearish and ShootingStarInput and (("Bearish" == CandleType) or CandleType == "Both") 422 | 423 | // var ttBearishShootingStar = "Shooting Star\nThis single day pattern can appear during an uptrend and opens high, while it closes near its open. It trades much higher as well. It is bearish in nature, but looks like an Inverted Hammer." 424 | // label.new(bar_index, patternLabelPosHigh, text="SS", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishShootingStar) 425 | 426 | 427 | // C_InvertedHammerBullishNumberOfCandles = 1 428 | // // C_InvertedHammerBullish = C_DownTrend and C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow 429 | // C_InvertedHammerBullish = stochrsi_RSITop and C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow 430 | 431 | // alertcondition(C_InvertedHammerBullish, title = "Inverted Hammer", message = "New Inverted Hammer - Bullish pattern detected.") 432 | // if C_InvertedHammerBullish and InvertedHammerInput and (("Bullish" == CandleType) or CandleType == "Both") 433 | 434 | // var ttBullishInvertedHammer = "Inverted Hammer\nIf in a downtrend, then the open is lower. When it eventually trades higher, but closes near its open, it will look like an inverted version of the Hammer Candlestick. This is a one-day bullish reversal pattern." 435 | // label.new(bar_index, patternLabelPosLow, text="IH", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishInvertedHammer) 436 | 437 | 438 | // C_MorningStarBullishNumberOfCandles = 3 439 | // C_MorningStarBullish = C_LongBody[2] and C_SmallBody[1] and C_LongBody and C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] and C_WhiteBody and C_BodyHi >= C_BodyMiddle[2] and C_BodyHi < C_BodyHi[2] and C_BodyHi[1] < C_BodyLo 440 | 441 | // alertcondition(C_MorningStarBullish, title = "Morning Star", message = "New Morning Star - Bullish pattern detected.") 442 | // if C_MorningStarBullish and MorningStarInput and (("Bullish" == CandleType) or CandleType == "Both") 443 | 444 | // var ttBullishMorningStar = "Morning Star\nA three-day bullish reversal pattern, which consists of three candlesticks will look something like this: The first being a long-bodied red candle that extends the current downtrend. Next comes a short, middle candle that gaps down on the open. After comes a long-bodied green candle, which gaps up on the open and closes above the midpoint of the body of the first day." 445 | // label.new(bar_index, patternLabelPosLow, text="MS", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishMorningStar) 446 | // C_EveningStarBearishNumberOfCandles = 3 447 | // C_EveningStarBearish = false 448 | // if C_LongBody[2] and C_SmallBody[1] and C_LongBody 449 | // if C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_BlackBody and C_BodyLo <= C_BodyMiddle[2] and C_BodyLo > C_BodyLo[2] and C_BodyLo[1] > C_BodyHi 450 | // C_EveningStarBearish := true 451 | // alertcondition(C_EveningStarBearish, title = "Evening Star", message = "New Evening Star - Bearish pattern detected.") 452 | // if C_EveningStarBearish and EveningStarInput and (("Bearish" == CandleType) or CandleType == "Both") 453 | 454 | // var ttBearishEveningStar = "Evening Star\nThis candlestick pattern is bearish and continues an uptrend with a long-bodied, green candle day. It is then followed by a gapped and small-bodied candle day, and concludes with a downward close. The close would be below the first day’s midpoint." 455 | // label.new(bar_index, patternLabelPosHigh, text="ES", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishEveningStar) 456 | // C_MarubozuWhiteBullishNumberOfCandles = 1 457 | // C_MarubozuShadowPercentWhite = 5.0 458 | // C_MarubozuWhiteBullish = C_WhiteBody and C_LongBody and C_UpShadow <= C_MarubozuShadowPercentWhite/100*C_Body and C_DnShadow <= C_MarubozuShadowPercentWhite/100*C_Body and C_WhiteBody 459 | // alertcondition(C_MarubozuWhiteBullish, title = "Marubozu White", message = "New Marubozu White - Bullish pattern detected.") 460 | // if C_MarubozuWhiteBullish and MarubozuWhiteInput and (("Bullish" == CandleType) or CandleType == "Both") 461 | 462 | // var ttBullishMarubozuWhite = "Marubozu White\nA Marubozu White Candle is a candlestick that does not have a shadow that extends from its candle body at either the open or the close. Marubozu is Japanese for “close-cropped” or “close-cut.” Other sources may call it a Bald or Shaven Head Candle." 463 | // label.new(bar_index, patternLabelPosLow, text="MW", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishMarubozuWhite) 464 | // C_MarubozuBlackBearishNumberOfCandles = 1 465 | // C_MarubozuShadowPercentBearish = 5.0 466 | // C_MarubozuBlackBearish = C_BlackBody and C_LongBody and C_UpShadow <= C_MarubozuShadowPercentBearish/100*C_Body and C_DnShadow <= C_MarubozuShadowPercentBearish/100*C_Body and C_BlackBody 467 | // alertcondition(C_MarubozuBlackBearish, title = "Marubozu Black", message = "New Marubozu Black - Bearish pattern detected.") 468 | // if C_MarubozuBlackBearish and MarubozuBlackInput and (("Bearish" == CandleType) or CandleType == "Both") 469 | 470 | // var ttBearishMarubozuBlack = "Marubozu Black\nThis is a candlestick that has no shadow, which extends from the red-bodied candle at the open, the close, or even at both. In Japanese, the name means “close-cropped” or “close-cut.” The candlestick can also be referred to as Bald or Shaven Head." 471 | // label.new(bar_index, patternLabelPosHigh, text="MB", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishMarubozuBlack) 472 | // C_DojiNumberOfCandles = 1 473 | // C_DragonflyDoji = C_IsDojiBody and C_UpShadow <= C_Body 474 | // C_GravestoneDojiOne = C_IsDojiBody and C_DnShadow <= C_Body 475 | // alertcondition(C_Doji and not C_DragonflyDoji and not C_GravestoneDojiOne, title = "Doji", message = "New Doji pattern detected.") 476 | // if C_Doji and not C_DragonflyDoji and not C_GravestoneDojiOne and DojiInput 477 | // var ttDoji = "Doji\nWhen the open and close of a security are essentially equal to each other, a doji candle forms. The length of both upper and lower shadows may vary, causing the candlestick you are left with to either resemble a cross, an inverted cross, or a plus sign. Doji candles show the playout of buyer-seller indecision in a tug-of-war of sorts. As price moves either above or below the opening level during the session, the close is either at or near the opening level." 478 | // label.new(bar_index, patternLabelPosLow, text="D", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttDoji) 479 | // C_GravestoneDojiBearishNumberOfCandles = 1 480 | // C_GravestoneDojiBearish = C_IsDojiBody and C_DnShadow <= C_Body 481 | // alertcondition(C_GravestoneDojiBearish, title = "Gravestone Doji", message = "New Gravestone Doji - Bearish pattern detected.") 482 | // if C_GravestoneDojiBearish and GravestoneDojiInput and (("Bearish" == CandleType) or CandleType == "Both") 483 | 484 | // var ttBearishGravestoneDoji = "Gravestone Doji\nWhen a doji is at or is close to the day’s low point, a doji line will develop." 485 | // label.new(bar_index, patternLabelPosHigh, text="GD", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishGravestoneDoji) 486 | // C_DragonflyDojiBullishNumberOfCandles = 1 487 | // C_DragonflyDojiBullish = C_IsDojiBody and C_UpShadow <= C_Body 488 | // alertcondition(C_DragonflyDojiBullish, title = "Dragonfly Doji", message = "New Dragonfly Doji - Bullish pattern detected.") 489 | // if C_DragonflyDojiBullish and DragonflyDojiInput and (("Bullish" == CandleType) or CandleType == "Both") 490 | 491 | // var ttBullishDragonflyDoji = "Dragonfly Doji\nSimilar to other Doji days, this particular Doji also regularly appears at pivotal market moments. This is a specific Doji where both the open and close price are at the high of a given day." 492 | // label.new(bar_index, patternLabelPosLow, text="DD", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishDragonflyDoji) 493 | // C_HaramiCrossBullishNumberOfCandles = 2 494 | // C_HaramiCrossBullish = C_LongBody[1] and C_BlackBody[1] and C_DownTrend[1] and C_IsDojiBody and high <= C_BodyHi[1] and low >= C_BodyLo[1] 495 | // alertcondition(C_HaramiCrossBullish, title = "Harami Cross", message = "New Harami Cross - Bullish pattern detected.") 496 | // if C_HaramiCrossBullish and HaramiCrossInput and (("Bullish" == CandleType) or CandleType == "Both") 497 | 498 | // var ttBullishHaramiCross = "Harami Cross\nThis candlestick pattern is a variation of the Harami Bullish pattern. It is found during a downtrend. The two-day candlestick pattern consists of a Doji candle that is entirely encompassed within the body of what was once a red-bodied candle." 499 | // label.new(bar_index, patternLabelPosLow, text="HC", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishHaramiCross) 500 | // C_HaramiCrossBearishNumberOfCandles = 2 501 | // C_HaramiCrossBearish = C_LongBody[1] and C_WhiteBody[1] and C_UpTrend[1] and C_IsDojiBody and high <= C_BodyHi[1] and low >= C_BodyLo[1] 502 | // alertcondition(C_HaramiCrossBearish, title = "Harami Cross", message = "New Harami Cross - Bearish pattern detected.") 503 | // if C_HaramiCrossBearish and HaramiCrossInput and (("Bearish" == CandleType) or CandleType == "Both") 504 | 505 | // var ttBearishHaramiCross = "Harami Cross\nThis candlestick pattern is a variation of the Harami Bearish pattern. It is found during an uptrend. This is a two-day candlestick pattern with a Doji candle that is entirely encompassed within the body that was once a green-bodied candle. The Doji shows that some indecision has entered the minds of sellers, and the pattern hints that the trend might reverse." 506 | // label.new(bar_index, patternLabelPosHigh, text="HC", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishHaramiCross) 507 | // C_HaramiBullishNumberOfCandles = 2 508 | // C_HaramiBullish = C_LongBody[1] and C_BlackBody[1] and C_DownTrend[1] and C_WhiteBody and C_SmallBody and high <= C_BodyHi[1] and low >= C_BodyLo[1] 509 | // alertcondition(C_HaramiBullish, title = "Harami", message = "New Harami - Bullish pattern detected.") 510 | // if C_HaramiBullish and HaramiInput and (("Bullish" == CandleType) or CandleType == "Both") 511 | 512 | // var ttBullishHarami = "Harami\nThis two-day candlestick pattern consists of a small-bodied green candle that is entirely encompassed within the body of what was once a red-bodied candle." 513 | // label.new(bar_index, patternLabelPosLow, text="BH", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishHarami) 514 | // C_HaramiBearishNumberOfCandles = 2 515 | // C_HaramiBearish = C_LongBody[1] and C_WhiteBody[1] and C_UpTrend[1] and C_BlackBody and C_SmallBody and high <= C_BodyHi[1] and low >= C_BodyLo[1] 516 | // alertcondition(C_HaramiBearish, title = "Harami", message = "New Harami - Bearish pattern detected.") 517 | // if C_HaramiBearish and HaramiInput and (("Bearish" == CandleType) or CandleType == "Both") 518 | 519 | // var ttBearishHarami = "Harami\nThis is a two-day candlestick pattern with a small, red-bodied candle that is entirely encompassed within the body that was once a green-bodied candle." 520 | // label.new(bar_index, patternLabelPosHigh, text="BH", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishHarami) 521 | // C_LongLowerShadowBullishNumberOfCandles = 1 522 | // C_LongLowerShadowPercent = 75.0 523 | // C_LongLowerShadowBullish = C_DnShadow > C_Range/100*C_LongLowerShadowPercent 524 | // alertcondition(C_LongLowerShadowBullish, title = "Long Lower Shadow", message = "New Long Lower Shadow - Bullish pattern detected.") 525 | // if C_LongLowerShadowBullish and LongLowerShadowInput and (("Bullish" == CandleType) or CandleType == "Both") 526 | 527 | // var ttBullishLongLowerShadow = "Long Lower Shadow\nTo indicate seller domination of the first part of a session, candlesticks will present with long lower shadows and short upper shadows, consequently lowering prices." 528 | // label.new(bar_index, patternLabelPosLow, text="LLS", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishLongLowerShadow) 529 | // C_LongUpperShadowBearishNumberOfCandles = 1 530 | // C_LongShadowPercent = 75.0 531 | // C_LongUpperShadowBearish = C_UpShadow > C_Range/100*C_LongShadowPercent 532 | // alertcondition(C_LongUpperShadowBearish, title = "Long Upper Shadow", message = "New Long Upper Shadow - Bearish pattern detected.") 533 | // if C_LongUpperShadowBearish and LongUpperShadowInput and (("Bearish" == CandleType) or CandleType == "Both") 534 | 535 | // var ttBearishLongUpperShadow = "Long Upper Shadow\nTo indicate buyer domination of the first part of a session, candlesticks will present with long upper shadows, as well as short lower shadows, consequently raising bidding prices." 536 | // label.new(bar_index, patternLabelPosHigh, text="LUS", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishLongUpperShadow) 537 | // C_SpinningTopWhiteNumberOfCandles = 1 538 | // C_SpinningTopWhitePercent = 34.0 539 | // C_IsSpinningTopWhite = C_DnShadow >= C_Range / 100 * C_SpinningTopWhitePercent and C_UpShadow >= C_Range / 100 * C_SpinningTopWhitePercent and not C_IsDojiBody 540 | // C_SpinningTopWhite = C_IsSpinningTopWhite and C_WhiteBody 541 | // alertcondition(C_SpinningTopWhite, title = "Spinning Top White", message = "New Spinning Top White pattern detected.") 542 | // if C_SpinningTopWhite and SpinningTopWhiteInput 543 | // var ttSpinningTopWhite = "Spinning Top White\nWhite spinning tops are candlestick lines that are small, green-bodied, and possess shadows (upper and lower) that end up exceeding the length of candle bodies. They often signal indecision between buyer and seller." 544 | // label.new(bar_index, patternLabelPosLow, text="STW", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttSpinningTopWhite) 545 | // C_SpinningTopBlackNumberOfCandles = 1 546 | // C_SpinningTopBlackPercent = 34.0 547 | // C_IsSpinningTop = C_DnShadow >= C_Range / 100 * C_SpinningTopBlackPercent and C_UpShadow >= C_Range / 100 * C_SpinningTopBlackPercent and not C_IsDojiBody 548 | // C_SpinningTopBlack = C_IsSpinningTop and C_BlackBody 549 | // alertcondition(C_SpinningTopBlack, title = "Spinning Top Black", message = "New Spinning Top Black pattern detected.") 550 | // if C_SpinningTopBlack and SpinningTopBlackInput 551 | // var ttSpinningTopBlack = "Spinning Top Black\nBlack spinning tops are candlestick lines that are small, red-bodied, and possess shadows (upper and lower) that end up exceeding the length of candle bodies. They often signal indecision." 552 | // label.new(bar_index, patternLabelPosLow, text="STB", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttSpinningTopBlack) 553 | // C_ThreeWhiteSoldiersBullishNumberOfCandles = 3 554 | // C_3WSld_ShadowPercent = 5.0 555 | // C_3WSld_HaveNotUpShadow = C_Range * C_3WSld_ShadowPercent / 100 > C_UpShadow 556 | // C_ThreeWhiteSoldiersBullish = false 557 | // if C_LongBody and C_LongBody[1] and C_LongBody[2] 558 | // if C_WhiteBody and C_WhiteBody[1] and C_WhiteBody[2] 559 | // C_ThreeWhiteSoldiersBullish := close > close[1] and close[1] > close[2] and open < close[1] and open > open[1] and open[1] < close[2] and open[1] > open[2] and C_3WSld_HaveNotUpShadow and C_3WSld_HaveNotUpShadow[1] and C_3WSld_HaveNotUpShadow[2] 560 | // alertcondition(C_ThreeWhiteSoldiersBullish, title = "Three White Soldiers", message = "New Three White Soldiers - Bullish pattern detected.") 561 | // if C_ThreeWhiteSoldiersBullish and ThreeWhiteSoldiersInput and (("Bullish" == CandleType) or CandleType == "Both") 562 | 563 | // var ttBullishThreeWhiteSoldiers = "Three White Soldiers\nThis bullish reversal pattern is made up of three long-bodied, green candles in immediate succession. Each one opens within the body before it and the close is near to the daily high." 564 | // label.new(bar_index, patternLabelPosLow, text="3WS", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishThreeWhiteSoldiers) 565 | // C_ThreeBlackCrowsBearishNumberOfCandles = 3 566 | // C_3BCrw_ShadowPercent = 5.0 567 | // C_3BCrw_HaveNotDnShadow = C_Range * C_3BCrw_ShadowPercent / 100 > C_DnShadow 568 | // C_ThreeBlackCrowsBearish = false 569 | // if C_LongBody and C_LongBody[1] and C_LongBody[2] 570 | // if C_BlackBody and C_BlackBody[1] and C_BlackBody[2] 571 | // C_ThreeBlackCrowsBearish := close < close[1] and close[1] < close[2] and open > close[1] and open < open[1] and open[1] > close[2] and open[1] < open[2] and C_3BCrw_HaveNotDnShadow and C_3BCrw_HaveNotDnShadow[1] and C_3BCrw_HaveNotDnShadow[2] 572 | // alertcondition(C_ThreeBlackCrowsBearish, title = "Three Black Crows", message = "New Three Black Crows - Bearish pattern detected.") 573 | // if C_ThreeBlackCrowsBearish and ThreeBlackCrowsInput and (("Bearish" == CandleType) or CandleType == "Both") 574 | 575 | // var ttBearishThreeBlackCrows = "Three Black Crows\nThis is a bearish reversal pattern that consists of three long, red-bodied candles in immediate succession. For each of these candles, each day opens within the body of the day before and closes either at or near its low." 576 | // label.new(bar_index, patternLabelPosHigh, text="3BC", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishThreeBlackCrows) 577 | // C_EngulfingBullishNumberOfCandles = 2 578 | // // C_EngulfingBullish = C_DownTrend and C_WhiteBody and C_LongBody and C_BlackBody[1] and C_SmallBody[1] and close >= open[1] and open <= close[1] and ( close > open[1] or open < close[1] ) 579 | // C_EngulfingBullish = C_DownTrend and stochrsi_RSIBottom and C_WhiteBody and C_LongBody and C_BlackBody[1] and C_SmallBody[1] and close >= open[1] and open <= close[1] and ( close > open[1] or open < close[1] ) 580 | // alertcondition(C_EngulfingBullish, title = "Engulfing", message = "New Engulfing - Bullish pattern detected.") 581 | // if C_EngulfingBullish and EngulfingInput and (("Bullish" == CandleType) or CandleType == "Both") 582 | 583 | // var ttBullishEngulfing = "Engulfing\nAt the end of a given downward trend, there will most likely be a reversal pattern. To distinguish the first day, this candlestick pattern uses a small body, followed by a day where the candle body fully overtakes the body from the day before, and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to completely overtake the range (high to low), rather only the open and the close." 584 | // label.new(bar_index, patternLabelPosLow, text="BE", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishEngulfing) 585 | // C_EngulfingBearishNumberOfCandles = 2 586 | // C_EngulfingBearish_1 = C_BlackBody and C_LongBody and C_WhiteBody[1] and C_SmallBody[1] and close <= open[1] and open >= close[1] and ( close < open[1] or open > close[1] ) 587 | // C_EngulfingBearish_2 = ((close[1] > open[1]) and (open > close) and (open >= close[1]) and (open[1] >= close) and ((open - close) > (close[1] - open[1]))) 588 | // // C_EngulfingBearish = C_UpTrend and C_BlackBody and C_LongBody and C_WhiteBody[1] and C_SmallBody[1] and close <= open[1] and open >= close[1] and ( close < open[1] or open > close[1] ) 589 | // C_EngulfingBearish = (C_UpTrend and stochrsi_RSITop) and (C_EngulfingBearish_1 or C_EngulfingBearish_2) 590 | // alertcondition(C_EngulfingBearish, title = "Engulfing", message = "New Engulfing - Bearish pattern detected.") 591 | // if C_EngulfingBearish and EngulfingInput and (("Bearish" == CandleType) or CandleType == "Both") 592 | 593 | // var ttBearishEngulfing = "Engulfing\nAt the end of a given uptrend, a reversal pattern will most likely appear. During the first day, this candlestick pattern uses a small body. It is then followed by a day where the candle body fully overtakes the body from the day before it and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to fully overtake the range (high to low), rather only the open and the close." 594 | // label.new(bar_index, patternLabelPosHigh, text="BE", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishEngulfing) 595 | // C_AbandonedBabyBullishNumberOfCandles = 3 596 | // C_AbandonedBabyBullish = C_DownTrend[2] and C_BlackBody[2] and C_IsDojiBody[1] and low[2] > high[1] and C_WhiteBody and high[1] < low 597 | // alertcondition(C_AbandonedBabyBullish, title = "Abandoned Baby", message = "New Abandoned Baby - Bullish pattern detected.") 598 | // if C_AbandonedBabyBullish and AbandonedBabyInput and (("Bullish" == CandleType) or CandleType == "Both") 599 | 600 | // var ttBullishAbandonedBaby = "Abandoned Baby\nThis candlestick pattern is quite rare as far as reversal patterns go. The first of the pattern is a large down candle. Next comes a doji candle that gaps below the candle before it. The doji candle is then followed by another candle that opens even higher and swiftly moves to the upside." 601 | // label.new(bar_index, patternLabelPosLow, text="AB", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishAbandonedBaby) 602 | // C_AbandonedBabyBearishNumberOfCandles = 3 603 | // C_AbandonedBabyBearish = C_UpTrend[2] and C_WhiteBody[2] and C_IsDojiBody[1] and high[2] < low[1] and C_BlackBody and low[1] > high 604 | // alertcondition(C_AbandonedBabyBearish, title = "Abandoned Baby", message = "New Abandoned Baby - Bearish pattern detected.") 605 | // if C_AbandonedBabyBearish and AbandonedBabyInput and (("Bearish" == CandleType) or CandleType == "Both") 606 | 607 | // var ttBearishAbandonedBaby = "Abandoned Baby\nA bearish abandoned baby is a specific candlestick pattern that often signals a downward reversal trend in terms of security price. It is formed when a gap appears between the lowest price of a doji-like candle and the candlestick of the day before. The earlier candlestick is green, tall, and has small shadows. The doji candle is also tailed by a gap between its lowest price point and the highest price point of the candle that comes next, which is red, tall and also has small shadows. The doji candle shadows must completely gap either below or above the shadows of the first and third day in order to have the abandoned baby pattern effect." 608 | // label.new(bar_index, patternLabelPosHigh, text="AB", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishAbandonedBaby) 609 | // C_TriStarBullishNumberOfCandles = 3 610 | // C_3DojisBullish = C_Doji[2] and C_Doji[1] and C_Doji 611 | // C_BodyGapUpBullish = C_BodyHi[1] < C_BodyLo 612 | // C_BodyGapDnBullish = C_BodyLo[1] > C_BodyHi 613 | // C_TriStarBullish = C_3DojisBullish and C_DownTrend[2] and C_BodyGapDnBullish[1] and C_BodyGapUpBullish 614 | // alertcondition(C_TriStarBullish, title = "Tri-Star", message = "New Tri-Star - Bullish pattern detected.") 615 | // if C_TriStarBullish and TriStarInput and (("Bullish" == CandleType) or CandleType == "Both") 616 | 617 | // var ttBullishTriStar = "Tri-Star\nA bullish TriStar candlestick pattern can form when three doji candlesticks materialize in immediate succession at the tail-end of an extended downtrend. The first doji candle marks indecision between bull and bear. The second doji gaps in the direction of the leading trend. The third changes the attitude of the market once the candlestick opens in the direction opposite to the trend. Each doji candle has a shadow, all comparatively shallow, which signify an interim cutback in volatility." 618 | // label.new(bar_index, patternLabelPosLow, text="3S", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishTriStar) 619 | // C_TriStarBearishNumberOfCandles = 3 620 | // C_3Dojis = C_Doji[2] and C_Doji[1] and C_Doji 621 | // C_BodyGapUp = C_BodyHi[1] < C_BodyLo 622 | // C_BodyGapDn = C_BodyLo[1] > C_BodyHi 623 | // C_TriStarBearish = C_3Dojis and C_UpTrend[2] and C_BodyGapUp[1] and C_BodyGapDn 624 | // alertcondition(C_TriStarBearish, title = "Tri-Star", message = "New Tri-Star - Bearish pattern detected.") 625 | // if C_TriStarBearish and TriStarInput and (("Bearish" == CandleType) or CandleType == "Both") 626 | 627 | // var ttBearishTriStar = "Tri-Star\nThis particular pattern can form when three doji candlesticks appear in immediate succession at the end of an extended uptrend. The first doji candle marks indecision between bull and bear. The second doji gaps in the direction of the leading trend. The third changes the attitude of the market once the candlestick opens in the direction opposite to the trend. Each doji candle has a shadow, all comparatively shallow, which signify an interim cutback in volatility." 628 | // label.new(bar_index, patternLabelPosHigh, text="3S", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishTriStar) 629 | // C_KickingBullishNumberOfCandles = 2 630 | // C_MarubozuShadowPercent = 5.0 631 | // C_Marubozu = C_LongBody and C_UpShadow <= C_MarubozuShadowPercent/100*C_Body and C_DnShadow <= C_MarubozuShadowPercent/100*C_Body 632 | // C_MarubozuWhiteBullishKicking = C_Marubozu and C_WhiteBody 633 | // C_MarubozuBlackBullish = C_Marubozu and C_BlackBody 634 | // C_KickingBullish = C_MarubozuBlackBullish[1] and C_MarubozuWhiteBullishKicking and high[1] < low 635 | // alertcondition(C_KickingBullish, title = "Kicking", message = "New Kicking - Bullish pattern detected.") 636 | // if C_KickingBullish and KickingInput and (("Bullish" == CandleType) or CandleType == "Both") 637 | 638 | // var ttBullishKicking = "Kicking\nThe first day candlestick is a bearish marubozu candlestick with next to no upper or lower shadow and where the price opens at the day’s high and closes at the day’s low. The second day is a bullish marubozu pattern, with next to no upper or lower shadow and where the price opens at the day’s low and closes at the day’s high. Additionally, the second day gaps up extensively and opens above the opening price of the day before. This gap or window, as the Japanese call it, lies between day one and day two’s bullish candlesticks." 639 | // label.new(bar_index, patternLabelPosLow, text="K", style=label.style_label_up, color = color.blue, textcolor=color.white, tooltip = ttBullishKicking) 640 | // C_KickingBearishNumberOfCandles = 2 641 | // C_MarubozuBullishShadowPercent = 5.0 642 | // C_MarubozuBearishKicking = C_LongBody and C_UpShadow <= C_MarubozuBullishShadowPercent/100*C_Body and C_DnShadow <= C_MarubozuBullishShadowPercent/100*C_Body 643 | // C_MarubozuWhiteBearish = C_MarubozuBearishKicking and C_WhiteBody 644 | // C_MarubozuBlackBearishKicking = C_MarubozuBearishKicking and C_BlackBody 645 | // C_KickingBearish = C_MarubozuWhiteBearish[1] and C_MarubozuBlackBearishKicking and low[1] > high 646 | // alertcondition(C_KickingBearish, title = "Kicking", message = "New Kicking - Bearish pattern detected.") 647 | // if C_KickingBearish and KickingInput and (("Bearish" == CandleType) or CandleType == "Both") 648 | 649 | // var ttBearishKicking = "Kicking\nA bearish kicking pattern will occur, subsequently signaling a reversal for a new downtrend. The first day candlestick is a bullish marubozu. The second day gaps down extensively and opens below the opening price of the day before. There is a gap between day one and two’s bearish candlesticks." 650 | // label.new(bar_index, patternLabelPosHigh, text="K", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishKicking) 651 | // var ttAllCandlestickPatterns = "All Candlestick Patterns\n" 652 | // label.new(bar_index, patternLabelPosLow, text="Collection", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttAllCandlestickPatterns) 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | // /// Classic 662 | // bullCandle = (close > open) 663 | // bullCandleLong = ((close > open) and ((close - open) / (0.001 + high - low) > 0.6)) 664 | // bullCandleSmall = ((close > open) and ((high - low) > (3 * (close - open)))) 665 | 666 | // bearCandle = open < close 667 | // bearCandleLong = ((open > close) and ((open - close) / (0.001 + high - low) > 0.6)) 668 | // bearCandleSmall = ((open > close) and ((high - low) > (3 * (open - close)))) 669 | 670 | // // Marubozu 671 | // bullMarubozu = (close > open) and (high == close) and (open == low) 672 | // bearMarubozu = (open > close) and (high == open) and (close == low) 673 | 674 | // if bullMarubozu and stochrsi_RSIBottom 675 | // var ttBullishMarubozuWhite = "Marubozu White\nA Marubozu White Candle is a candlestick that does not have a shadow that extends from its candle body at either the open or the close. Marubozu is Japanese for “close-cropped” or “close-cut.” Other sources may call it a Bald or Shaven Head Candle." 676 | // label.new(bar_index, patternLabelPosLow, text="MW", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishMarubozuWhite) 677 | 678 | // if bullMarubozu and stochrsi_RSITop 679 | // var ttBearishMarubozuBlack = "Marubozu Black\nThis is a candlestick that has no shadow, which extends from the red-bodied candle at the open, the close, or even at both. In Japanese, the name means “close-cropped” or “close-cut.” The candlestick can also be referred to as Bald or Shaven Head." 680 | // label.new(bar_index, patternLabelPosHigh, text="MB", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishMarubozuBlack) 681 | 682 | // // Doji 683 | // doji = (open == close) 684 | 685 | // if doji 686 | // var ttDoji = "Doji\nWhen the open and close of a security are essentially equal to each other, a doji candle forms. The length of both upper and lower shadows may vary, causing the candlestick you are left with to either resemble a cross, an inverted cross, or a plus sign. Doji candles show the playout of buyer-seller indecision in a tug-of-war of sorts. As price moves either above or below the opening level during the session, the close is either at or near the opening level." 687 | // label.new(bar_index, patternLabelPosLow, text="D", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttDoji) 688 | 689 | // /// Reversal patterns 690 | 691 | // // TODO: Dragonfly Doji 692 | // bullDragonflyDoji = ((abs(open - close) <= 0.02 * (high - low)) and ((high - close) <= 0.3 * (high - low)) and ((high - low) >= (avgh10 - avgl10)) and ( high > low) and (low == minl10)) 693 | // bullDragonflyDoji2 = (((high - low) > 3 * abs(open - close) and (close - low) > 0.8 * (high - low)) and ((open - close) > 0.8 * (high - low))) 694 | // bearDragonflyDoji = ((abs(open - close) <= 0.02 * (high - low)) and ((high - close) <= 0.3 * (high - low)) and ((high - low) >= (avgh10 - avgl10)) and ( high > low) and (high == maxh10)) 695 | 696 | // if bullDragonflyDoji or bullDragonflyDoji2 697 | // var ttBullishDragonflyDoji = "Dragonfly Doji\nSimilar to other Doji days, this particular Doji also regularly appears at pivotal market moments. This is a specific Doji where both the open and close price are at the high of a given day." 698 | // label.new(bar_index, patternLabelPosLow, text="DD", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishDragonflyDoji) 699 | 700 | // if bearDragonflyDoji 701 | // var ttBearishDragonflyDoji = "Dragonfly Doji\nSimilar to other Doji days, this particular Doji also regularly appears at pivotal market moments. This is a specific Doji where both the open and close price are at the high of a given day." 702 | // label.new(bar_index, patternLabelPosLow, text="DD", style=label.style_label_up, color = color.red, textcolor=color.white, tooltip = ttBearishDragonflyDoji) 703 | 704 | // // Gravestone Doji 705 | // // bullGravestoneDoji = (abs(open - close) <= 0.01 * (high - low)) and ((high - close) >= 0.95 * (high - low)) and (high > low) and (low <= low[1] + 0.3 * (high[1] - low[1])) and ((high - low) >= (avgh10 - avgl10)) 706 | // bearGravestoneDoji = (abs(open - close) <= 0.01 * (high - low)) and ((high - close) >= 0.95 * (high - low)) and (high > low) and (high == maxh10) and ((high - low) >= (avgh10 - avgl10)) 707 | // bearGravestoneDoji2 = (abs(close - open) < (high - low) / 3) and (open > close[1]) and ((((close + open) / 2) - low) < 0.4 * (high - low)) and (high == maxh10) 708 | 709 | // if bearGravestoneDoji or bearGravestoneDoji2 710 | // var ttBearishGravestoneDoji = "Gravestone Doji\nWhen a doji is at or is close to the day’s low point, a doji line will develop." 711 | // label.new(bar_index, patternLabelPosHigh, text="GD", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishGravestoneDoji) 712 | 713 | // // Spinning Tops 714 | // bullSpinningTop = (close > open) and ((high - low) > (3 * (close - open)) and (((high - close) / (0.001 + high - low)) < 0.4) and (((open - low) / (0.001 + high - low)) < 0.4)) 715 | // bearSpinningTop = (open > close) and ((high - low) > (3 * (open - close)) and (((high - open) / (0.001 + high - low)) < 0.4) and (((close - low)/(0.001 + high - low)) < 0.4)) 716 | 717 | // if bullSpinningTop 718 | // var ttSpinningTopWhite = "Spinning Top White\nWhite spinning tops are candlestick lines that are small, green-bodied, and possess shadows (upper and lower) that end up exceeding the length of candle bodies. They often signal indecision between buyer and seller." 719 | // label.new(bar_index, patternLabelPosLow, text="STW", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttSpinningTopWhite) 720 | 721 | // if bearSpinningTop 722 | // var ttSpinningTopBlack = "Spinning Top Black\nBlack spinning tops are candlestick lines that are small, red-bodied, and possess shadows (upper and lower) that end up exceeding the length of candle bodies. They often signal indecision." 723 | // label.new(bar_index, patternLabelPosLow, text="STB", style=label.style_label_up, color = color.gray, textcolor=color.white, tooltip = ttSpinningTopBlack) 724 | 725 | // // Hammer 726 | // hammer = (((high - low) > 3 * (open - close)) and ((close - low) / (0.001 + high - low) > 0.6) and ((open - low) / (0.001 + high - low) > 0.6)) 727 | 728 | // if hammer and stochrsi_RSIBottom 729 | // var ttBullishHammer = "Hammer\nHammer candlesticks form when a security moves lower after the open, but continues to rally into close above the intraday low. The candlestick that you are left with will look like a square attached to a long stick-like figure. This candlestick is called a Hammer if it happens to form during a decline." 730 | // label.new(bar_index, patternLabelPosLow, text="H", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishHammer) 731 | 732 | // // Hanging Man 733 | // hangingMan = (((high - low) > 4 * (open - close)) and ((close - low) / (0.001 + high - low) >= 0.75) and ((open - low) / (0.001 + high - low) >= 0.75)) 734 | 735 | // if hangingMan and stochrsi_RSITop 736 | // var ttBearishHangingMan = "Hanging Man\nWhen a specified security notably moves lower after the open, but continues to rally to close above the intraday low, a Hanging Man candlestick will form. The candlestick will resemble a square, attached to a long stick-like figure. It is referred to as a Hanging Man if the candlestick forms during an advance." 737 | // label.new(bar_index, patternLabelPosHigh, text="HM", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishHangingMan) 738 | 739 | // // TODO: Belt Hold 740 | // bullBeltHold = (open == mino10) and (open < low[1]) and (close - open) >= 0.7 * (high - low) and (high - low) >= 1.2 * (avgh10 - avgl10) and (open - low) <= 0.01 * (high - low) and (close <= high[1] - 0.5 * (high[1] - low[1])) and (high[1] > low[1]) and (high > low) and (close[1] < close[2]) and (close[2] < close[3]) 741 | // bearBeltHold = (open == maxo10) and (open > high[1]) and (open - close) >= 0.7 * (high - low) and (high - low) >= 1.2 * (avgh10 - avgl10) and (high - open) <= 0.01 * (high - low) and (close >= high[1] - 0.5 * (high[1] - low[1])) and (high[1] > low[1]) and (high > low) and (close[1] > close[2]) and (close[2] < close[3]) 742 | 743 | // // Inverted Hammer 744 | // invertedHammer = (((high - low) > 3 * (open - close)) and ((high - close) / (0.001 + high - low) > 0.6) and ((high - low) / (0.001 + high - low) > 0.6)) 745 | 746 | // if invertedHammer and stochrsi_RSIBottom 747 | // var ttBullishInvertedHammer = "Inverted Hammer\nIf in a downtrend, then the open is lower. When it eventually trades higher, but closes near its open, it will look like an inverted version of the Hammer Candlestick. This is a one-day bullish reversal pattern." 748 | // label.new(bar_index, patternLabelPosLow, text="IH", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishInvertedHammer) 749 | 750 | // // Shooting Star 751 | // shootingStar = (((high - low) > 4 * (open - close)) and ((high - close) / (0.001 + high - low) >= 0.75) and ((high - open) / (0.001 + high - low) >= 0.75)) 752 | 753 | // if shootingStar 754 | // var ttBearishShootingStar = "Shooting Star\nThis single day pattern can appear during an uptrend and opens high, while it closes near its open. It trades much higher as well. It is bearish in nature, but looks like an Inverted Hammer." 755 | // label.new(bar_index, patternLabelPosHigh, text="SS", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishShootingStar) 756 | 757 | // // Evening Star 758 | // eveningStar = ((close[2] > open[2]) and ((close[2] - open[2]) / (0.001 + high[2] - low[2]) > 0.6) and (close[2] < open[1]) and (close[1] > open[1]) and ((high[1] - low[1]) > (3 * (close[1] - open[1]))) and (open > close) and (open < open[1])) 759 | 760 | // if eveningStar 761 | // var ttBearishEveningStar = "Evening Star\nThis candlestick pattern is bearish and continues an uptrend with a long-bodied, green candle day. It is then followed by a gapped and small-bodied candle day, and concludes with a downward close. The close would be below the first day’s midpoint." 762 | // label.new(bar_index, patternLabelPosHigh, text="ES", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishEveningStar) 763 | 764 | // // Morning Star 765 | // morningStar = ((open[2] > close[2]) and ((open[2] - close[2]) / (0.001 + high[2] - low[2]) > 0.6) and (close[2] > open[1]) and (open[1] > close[1]) and ((high[1] - low[1]) > (3 * (close[1] - open[1]))) and (close > open) and (open > open[1])) 766 | 767 | // if morningStar 768 | // var ttBullishMorningStar = "Morning Star\nA three-day bullish reversal pattern, which consists of three candlesticks will look something like this: The first being a long-bodied red candle that extends the current downtrend. Next comes a short, middle candle that gaps down on the open. After comes a long-bodied green candle, which gaps up on the open and closes above the midpoint of the body of the first day." 769 | // label.new(bar_index, patternLabelPosLow, text="MS", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishMorningStar) 770 | 771 | // // Abandoned Baby 772 | // bullAbandonedBaby = ((close[1] == open[1]) and (open[2] > close[2]) and (close > open) and (low[2] > high[1]) and (low > high[1])) 773 | // bearAbandonedBaby = ((close[1] == open[1]) and (close[2] > open[2]) and (open > close) and (low[1] > high[2]) and (low[1] > high)) 774 | 775 | // if bullAbandonedBaby 776 | // var ttBullishAbandonedBaby = "Abandoned Baby\nThis candlestick pattern is quite rare as far as reversal patterns go. The first of the pattern is a large down candle. Next comes a doji candle that gaps below the candle before it. The doji candle is then followed by another candle that opens even higher and swiftly moves to the upside." 777 | // label.new(bar_index, patternLabelPosLow, text="AB", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishAbandonedBaby) 778 | 779 | // if bearAbandonedBaby 780 | // var ttBearishAbandonedBaby = "Abandoned Baby\nA bearish abandoned baby is a specific candlestick pattern that often signals a downward reversal trend in terms of security price. It is formed when a gap appears between the lowest price of a doji-like candle and the candlestick of the day before. The earlier candlestick is green, tall, and has small shadows. The doji candle is also tailed by a gap between its lowest price point and the highest price point of the candle that comes next, which is red, tall and also has small shadows. The doji candle shadows must completely gap either below or above the shadows of the first and third day in order to have the abandoned baby pattern effect." 781 | // label.new(bar_index, patternLabelPosHigh, text="AB", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishAbandonedBaby) 782 | 783 | // // Engulfing 784 | // bullEngulfing = ((open[1] > close[1]) and (close > open) and (close >= open[1]) and (close[1] >= open) and ((close - open) > (open[1] - close[1]))) 785 | // bearEngulfing = ((close[1] > open[1]) and (open > close) and (open >= close[1]) and (open[1] >= close) and ((open - close) > (close[1] - open[1]))) 786 | 787 | // if bullEngulfing and stochrsi_RSIBottom 788 | // var ttBullishEngulfing = "Engulfing\nAt the end of a given downward trend, there will most likely be a reversal pattern. To distinguish the first day, this candlestick pattern uses a small body, followed by a day where the candle body fully overtakes the body from the day before, and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to completely overtake the range (high to low), rather only the open and the close." 789 | // label.new(bar_index, patternLabelPosLow, text="BE", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishEngulfing) 790 | 791 | // if bearEngulfing and stochrsi_RSITop 792 | // var ttBearishEngulfing = "Engulfing\nAt the end of a given uptrend, a reversal pattern will most likely appear. During the first day, this candlestick pattern uses a small body. It is then followed by a day where the candle body fully overtakes the body from the day before it and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to fully overtake the range (high to low), rather only the open and the close." 793 | // label.new(bar_index, patternLabelPosHigh, text="BE", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishEngulfing) 794 | 795 | // // Harami 796 | // bullHarami = ((open[1] > close[1]) and (close > open) and (close <= open[1]) and (close[1] <= open) and ((close - open) < (open[1] - close[1]))) 797 | // bearHarami = ((close[1] > open[1]) and (open > close) and (open <= close[1]) and (open[1] <= close) and ((open - close) < (close[1] - open[1]))) 798 | 799 | // if bullHarami and stochrsi_RSIBottom 800 | // var ttBullishHarami = "Harami\nThis two-day candlestick pattern consists of a small-bodied green candle that is entirely encompassed within the body of what was once a red-bodied candle." 801 | // label.new(bar_index, patternLabelPosLow, text="BH", style=label.style_label_up, color = color.green, textcolor=color.white, tooltip = ttBullishHarami) 802 | 803 | // if bearHarami and stochrsi_RSITop 804 | // var ttBearishHarami = "Harami\nThis is a two-day candlestick pattern with a small, red-bodied candle that is entirely encompassed within the body that was once a green-bodied candle." 805 | // label.new(bar_index, patternLabelPosHigh, text="BH", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishHarami) 806 | -------------------------------------------------------------------------------- /Divergence-for-many-indicator-v3.pscript: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © LonesomeTheBlue 3 | // 4 | //@version=4 5 | study("Divergence for many indicator v3", overlay=true, max_bars_back = 4000) 6 | lb = input(5, title="Left Bars", minval=1) 7 | rb = input(5, title="Right Bars", minval=1) 8 | showhidden = input(false, title = "Show Hidden Divergences") 9 | chcut = input(false, title = "Check Cut-Through in indicators !") 10 | shownum = input(true, title="Show Divergence Number") 11 | showindis = input(false, title="Show Indicator Names") 12 | showpivot = input(false, title="Show Pivot Points") 13 | chwidth = input(true, title = "Change Width by Number of Divergence") 14 | showlimit = input(1, title="Minimum Number of Divergence", minval = 1, maxval = 11) 15 | calcmacd = input(true, title="MACD") 16 | calcmacda = input(true, title="MACD Histogram") 17 | calcrsi = input(true, title="RSI") 18 | calcstoc = input(true, title="Stochastic") 19 | calccci = input(true, title="CCI") 20 | calcmom = input(true, title="Momentum") 21 | calcobv = input(true, title="OBV") 22 | calcdi = input(true, title="Diosc") 23 | calcvwmacd = input(true, title="VWmacd") 24 | calccmf = input(true, title="Chaikin Money Flow") 25 | calcmfi = input(true, title="Money Flow Index") 26 | 27 | // RSI 28 | rsi = rsi(close, 14) 29 | // MACD 30 | [macd, signal, deltamacd] = macd(close, 12, 26, 9) 31 | // Momentum 32 | moment = mom(close, 10) 33 | // CCI 34 | cci = cci(close, 10) 35 | // OBV 36 | 37 | Obv = obv // cum(change(close) > 0 ? volume : change(close) < 0 ? -volume : 0 * volume) 38 | // Stoch 39 | stk = sma(stoch(close, high, low, 14), 3) 40 | // DIOSC 41 | DI = change(high) - (-change(low)) 42 | trur = rma(tr, 14) 43 | diosc = fixnan(100 * rma(DI, 14) / trur) 44 | // volume weighted macd 45 | maFast = vwma(close, 12) 46 | maSlow = vwma(close, 26) 47 | vwmacd = maFast - maSlow 48 | // Chaikin money flow 49 | Cmfm = ((close-low) - (high-close)) / (high - low) 50 | Cmfv = Cmfm * volume 51 | cmf = sma(Cmfv, 21) / sma(volume,21) 52 | // Moneyt Flow Index 53 | Mfi = mfi(close, 14) 54 | 55 | float top = na 56 | float bot = na 57 | top := pivothigh(lb, rb) 58 | bot := pivotlow(lb, rb) 59 | 60 | plotshape(top and showpivot, text="[PH]", style=shape.labeldown, color=color.white, textcolor=color.black, location=location.abovebar, transp=0, offset = -rb) 61 | plotshape(bot and showpivot, text="[PL]", style=shape.labeldown, color=color.white, textcolor=color.black, location=location.belowbar, transp=0, offset = -rb) 62 | 63 | topc = 0, botc = 0 64 | topc := top ? lb : nz(topc[1]) + 1 65 | botc := bot ? lb : nz(botc[1]) + 1 66 | 67 | // Negative Divergence or Hidden Positive Divergence 68 | newtop = pivothigh(lb, 0) // check only left side 69 | emptyh = true 70 | if not na(newtop) and ((newtop > high[topc] and not showhidden) or (newtop < high[topc] and showhidden)) // there must not close price higher than the line between last PH and current high 71 | diff = (newtop - high[topc]) / topc 72 | hline = newtop - diff // virtual line to check there is no close price higher than it 73 | for x = 1 to topc -1 74 | if close[x] > hline 75 | emptyh := false 76 | break 77 | hline := hline - diff 78 | else 79 | emptyh := false 80 | 81 | // check cut-through in indicators 82 | nocut1(indi, len)=> 83 | _ret = true 84 | diff = (indi - nz(indi[len])) / len 85 | ln = indi - diff 86 | for x = 1 to len -1 87 | if nz(indi[x]) > ln 88 | _ret := false 89 | break 90 | ln := ln - diff 91 | _ret 92 | 93 | rsiok = nocut1(rsi, topc) 94 | macdok = nocut1(macd, topc) 95 | deltamacdok = nocut1(deltamacd, topc) 96 | momentok = nocut1(moment, topc) 97 | cciok = nocut1(cci, topc) 98 | obvok = nocut1(obv, topc) 99 | stkok = nocut1(stk, topc) 100 | dioscok = nocut1(diosc, topc) 101 | vwmacdok = nocut1(vwmacd, topc) 102 | cmfok = nocut1(cmf, topc) 103 | mfiok = nocut1(Mfi, topc) 104 | 105 | negdivergence = 0 106 | negdivtxt = "" 107 | if emptyh and not na(newtop) and not showhidden 108 | if calcrsi and rsi[topc] > rsi and (not chcut or rsiok) 109 | negdivergence := negdivergence + 1 110 | negdivtxt := "RSI\n" 111 | if calcmacd and macd[topc] > macd and (not chcut or macdok) 112 | negdivergence := negdivergence + 1 113 | negdivtxt := negdivtxt + "MACD\n" 114 | if calcmacda and deltamacd[topc] > deltamacd and (not chcut or deltamacdok) 115 | negdivergence := negdivergence + 1 116 | negdivtxt := negdivtxt + "MACD Hist\n" 117 | if calcmom and moment[topc] > moment and (not chcut or momentok) 118 | negdivergence := negdivergence + 1 119 | negdivtxt := negdivtxt + "Momentum\n" 120 | if calccci and cci[topc] > cci and (not chcut or cciok) 121 | negdivergence := negdivergence + 1 122 | negdivtxt := negdivtxt + "CCI\n" 123 | if calcobv and Obv[topc] > Obv and (not chcut or obvok) 124 | negdivergence := negdivergence + 1 125 | negdivtxt := negdivtxt + "OBV\n" 126 | if calcstoc and stk[topc] > stk and (not chcut or stkok) 127 | negdivergence := negdivergence + 1 128 | negdivtxt := negdivtxt + "Stoch\n" 129 | if calcdi and diosc[topc] > diosc and (not chcut or dioscok) 130 | negdivergence := negdivergence + 1 131 | negdivtxt := negdivtxt + "Diosc\n" 132 | if calcvwmacd and vwmacd[topc] > vwmacd and (not chcut or vwmacdok) 133 | negdivergence := negdivergence + 1 134 | negdivtxt := negdivtxt + "VWMacd\n" 135 | if calccmf and cmf[topc] > cmf and (not chcut or cmfok) 136 | negdivergence := negdivergence + 1 137 | negdivtxt := negdivtxt + "CMF\n" 138 | if calcmfi and Mfi[topc] > Mfi and (not chcut or mfiok) 139 | negdivergence := negdivergence + 1 140 | negdivtxt := negdivtxt + "MFI\n" 141 | 142 | // Hidden divergence 143 | hposdivergence = 0 144 | hposdivtxt = "" 145 | if emptyh and not na(newtop) and showhidden 146 | if calcrsi and rsi[topc] < rsi and (not chcut or rsiok) 147 | hposdivergence := hposdivergence + 1 148 | hposdivtxt := "RSI\n" 149 | if calcmacd and macd[topc] < macd and (not chcut or macdok) 150 | hposdivergence := hposdivergence + 1 151 | hposdivtxt := hposdivtxt + "MACD\n" 152 | if calcmacda and deltamacd[topc] < deltamacd and (not chcut or deltamacdok) 153 | hposdivergence := hposdivergence + 1 154 | hposdivtxt := hposdivtxt + "MACD Hist\n" 155 | if calcmom and moment[topc] < moment and (not chcut or momentok) 156 | hposdivergence := hposdivergence + 1 157 | hposdivtxt := hposdivtxt + "Momentum\n" 158 | if calccci and cci[topc] < cci and (not chcut or cciok) 159 | hposdivergence := hposdivergence + 1 160 | hposdivtxt := hposdivtxt + "CCI\n" 161 | if calcobv and Obv[topc] < Obv and (not chcut or obvok) 162 | hposdivergence := hposdivergence + 1 163 | hposdivtxt := hposdivtxt + "OBV\n" 164 | if calcstoc and stk[topc] < stk and (not chcut or stkok) 165 | hposdivergence := hposdivergence + 1 166 | hposdivtxt := hposdivtxt + "Stoch\n" 167 | if calcdi and diosc[topc] < diosc and (not chcut or dioscok) 168 | hposdivergence := hposdivergence + 1 169 | hposdivtxt := hposdivtxt + "Diosc\n" 170 | if calcvwmacd and vwmacd[topc] < vwmacd and (not chcut or vwmacdok) 171 | hposdivergence := hposdivergence + 1 172 | hposdivtxt := hposdivtxt + "VWMacd\n" 173 | if calccmf and cmf[topc] < cmf and (not chcut or cmfok) 174 | hposdivergence := hposdivergence + 1 175 | hposdivtxt := hposdivtxt + "CMF\n" 176 | if calcmfi and Mfi[topc] < Mfi and (not chcut or mfiok) 177 | hposdivergence := hposdivergence + 1 178 | hposdivtxt := hposdivtxt + "MFI\n" 179 | 180 | newareah = false 181 | newareah := top ? false : nz(newareah[1], false) 182 | if negdivergence >= showlimit or hposdivergence >= showlimit 183 | var line divlh = na 184 | var label labh = na 185 | if newareah // we remove old line until It reaches new pivot point (like animation ;) 186 | line.delete(divlh) 187 | label.delete(labh) 188 | newwd = not showhidden ? 189 | (not chwidth ? 2 : 190 | negdivergence <= 2 ? 2 : 191 | negdivergence <= 5 ? 3 : 192 | negdivergence <= 8 ? 4 : 5) : 193 | (not chwidth ? 2 : 194 | hposdivergence <= 2 ? 2 : 195 | hposdivergence <= 5 ? 3 : 196 | hposdivergence <= 8 ? 4 : 5) 197 | 198 | divlh := line.new(bar_index - topc, high[topc], bar_index, high, color = color.red, width = newwd) 199 | if shownum or showindis 200 | txt = showindis ? showhidden ? hposdivtxt : negdivtxt : "" 201 | txt := txt + (shownum ? showhidden ? tostring(hposdivergence) : tostring(negdivergence) : "") 202 | labh := label.new(bar_index, na, text=txt, color= showhidden ? color.lime : color.red, textcolor = showhidden ? color.black : color.white, style= showhidden ? label.style_labelup : label.style_labeldown, yloc=yloc.abovebar) 203 | newareah := true 204 | 205 | // Positive or Hidden Negative Divergence 206 | newbot = pivotlow(lb, 0) // check only left side 207 | emptyl = true 208 | if not na(newbot) and ((newbot < low[botc] and not showhidden) or (newbot > low[botc] and showhidden)) // there must not close price lower than the line between last PL and current low 209 | diff = (newbot - low[botc]) / botc 210 | lline = newbot - diff // virtual line to check there is no close price lower than it 211 | for x = 1 to botc -1 212 | if close[x] < lline 213 | emptyl := false 214 | break 215 | lline := lline - diff 216 | else 217 | emptyl := false 218 | 219 | // check cut-through in indicators 220 | nocut2(indi, len)=> 221 | _ret = true 222 | diff = (indi - nz(indi[len])) / len 223 | ln = indi - diff 224 | for x = 1 to len -1 225 | if nz(indi[x]) < ln 226 | _ret := false 227 | break 228 | ln := ln - diff 229 | _ret 230 | 231 | rsiok := nocut2(rsi, botc) 232 | macdok := nocut2(macd, botc) 233 | deltamacdok := nocut2(deltamacd, botc) 234 | momentok := nocut2(moment, botc) 235 | cciok := nocut2(cci, botc) 236 | obvok := nocut2(obv, botc) 237 | stkok := nocut2(stk, botc) 238 | dioscok := nocut2(diosc, botc) 239 | vwmacdok := nocut2(vwmacd, botc) 240 | cmfok := nocut2(cmf, botc) 241 | mfiok := nocut2(Mfi, botc) 242 | 243 | posdivergence = 0 244 | posdivtxt = "" 245 | if emptyl and not na(newbot) and not showhidden 246 | if calcrsi and rsi[botc] < rsi and (not chcut or rsiok) 247 | posdivergence := 1 248 | posdivtxt := "RSI\n" 249 | if calcmacd and macd[botc] < macd and (not chcut or macdok) 250 | posdivergence := posdivergence + 1 251 | posdivtxt := posdivtxt + "MACD\n" 252 | if calcmacda and deltamacd[botc] < deltamacd and (not chcut or deltamacdok) 253 | posdivergence := posdivergence + 1 254 | posdivtxt := posdivtxt + "MACD Hist\n" 255 | if calcmom and moment[botc] < moment and (not chcut or momentok) 256 | posdivergence := posdivergence + 1 257 | posdivtxt := posdivtxt + "Momentum\n" 258 | if calccci and cci[botc] < cci and (not chcut or cciok) 259 | posdivergence := posdivergence + 1 260 | posdivtxt := posdivtxt + "CCI\n" 261 | if calcobv and Obv[botc] < Obv and (not chcut or obvok) 262 | posdivergence := posdivergence + 1 263 | posdivtxt := posdivtxt + "OBV\n" 264 | if calcstoc and stk[botc] < stk and (not chcut or stkok) 265 | posdivergence := posdivergence + 1 266 | posdivtxt := posdivtxt + "Stoch\n" 267 | if calcdi and diosc[botc] < diosc and (not chcut or dioscok) 268 | posdivergence := posdivergence + 1 269 | posdivtxt := posdivtxt + "Diosc\n" 270 | if calcvwmacd and vwmacd[botc] < vwmacd and (not chcut or vwmacdok) 271 | posdivergence := posdivergence + 1 272 | posdivtxt := posdivtxt + "VWMacd\n" 273 | if calccmf and cmf[botc] < cmf and (not chcut or cmfok) 274 | posdivergence := posdivergence + 1 275 | posdivtxt := posdivtxt + "CMF\n" 276 | if calcmfi and Mfi[botc] < Mfi and (not chcut or mfiok) 277 | posdivergence := posdivergence + 1 278 | posdivtxt := posdivtxt + "MFI\n" 279 | 280 | // Hidden Divergences 281 | hnegdivergence = 0 282 | hnegdivtxt = "" 283 | if emptyl and not na(newbot) and showhidden 284 | if calcrsi and rsi[botc] > rsi and (not chcut or rsiok) 285 | hnegdivergence := 1 286 | hnegdivtxt := "RSI\n" 287 | if calcmacd and macd[botc] > macd and (not chcut or macdok) 288 | hnegdivergence := hnegdivergence + 1 289 | hnegdivtxt := hnegdivtxt + "MACD\n" 290 | if calcmacda and deltamacd[botc] < deltamacd and (not chcut or deltamacdok) 291 | hnegdivergence := hnegdivergence + 1 292 | hnegdivtxt := hnegdivtxt + "MACD Hist\n" 293 | if calcmom and moment[botc] > moment and (not chcut or momentok) 294 | hnegdivergence := hnegdivergence + 1 295 | hnegdivtxt := hnegdivtxt + "Momentum\n" 296 | if calccci and cci[botc] > cci and (not chcut or cciok) 297 | hnegdivergence := hnegdivergence + 1 298 | hnegdivtxt := hnegdivtxt + "CCI\n" 299 | if calcobv and Obv[botc] > Obv and (not chcut or obvok) 300 | hnegdivergence := hnegdivergence + 1 301 | hnegdivtxt := hnegdivtxt + "OBV\n" 302 | if calcstoc and stk[botc] > stk and (not chcut or stkok) 303 | hnegdivergence := hnegdivergence + 1 304 | hnegdivtxt := hnegdivtxt + "Stoch\n" 305 | if calcdi and diosc[botc] > diosc and (not chcut or dioscok) 306 | hnegdivergence := hnegdivergence + 1 307 | hnegdivtxt := hnegdivtxt + "Diosc\n" 308 | if calcvwmacd and vwmacd[botc] > vwmacd and (not chcut or vwmacdok) 309 | hnegdivergence := hnegdivergence + 1 310 | hnegdivtxt := hnegdivtxt + "VWMacd\n" 311 | if calccmf and cmf[botc] > cmf and (not chcut or cmfok) 312 | hnegdivergence := hnegdivergence + 1 313 | hnegdivtxt := hnegdivtxt + "CMF\n" 314 | if calcmfi and Mfi[botc] > Mfi and (not chcut or mfiok) 315 | hnegdivergence := hnegdivergence + 1 316 | hnegdivtxt := hnegdivtxt + "MFI\n" 317 | 318 | newareal = false 319 | newareal := bot ? false : nz(newareal[1], false) 320 | if posdivergence >= showlimit or hnegdivergence >= showlimit 321 | var line divl = na 322 | var label lab = na 323 | if newareal // we remove old line until It reaches new pivot point (like animation ;) 324 | line.delete(divl) 325 | label.delete(lab) 326 | newwd = not showhidden ? 327 | (not chwidth ? 2 : 328 | posdivergence <= 2 ? 2 : 329 | posdivergence <= 5 ? 3 : 330 | posdivergence <= 8 ? 4 : 5) : 331 | (not chwidth ? 2 : 332 | hnegdivergence <= 2 ? 2 : 333 | hnegdivergence <= 5 ? 3 : 334 | hnegdivergence <= 8 ? 4 : 5) 335 | 336 | divl := line.new(bar_index - botc, low[botc], bar_index, low, color = color.lime, width = newwd) 337 | if shownum or showindis 338 | txt = showindis ? showhidden ? hnegdivtxt : posdivtxt : "" 339 | txt := txt + (shownum ? showhidden ? tostring(hnegdivergence) : tostring(posdivergence) : "") 340 | lab := label.new(bar_index, na, text=txt, color= showhidden ? color.olive : color.lime, textcolor = showhidden ? color.white : color.black, style = showhidden ? label.style_labeldown : label.style_labelup, yloc=yloc.belowbar) 341 | newareal := true 342 | 343 | alertcondition(posdivergence >= showlimit and not showhidden, title='Positive Divergence', message='Positive Divergence') 344 | alertcondition(negdivergence >= showlimit and not showhidden, title='Negative Divergence', message='Negative Divergence') 345 | alertcondition(hposdivergence >= showlimit and showhidden, title='Positive Hidden Divergence', message='Positive Hidden Divergence') 346 | alertcondition(hnegdivergence >= showlimit and showhidden, title='Negative Hidden Divergence', message='Negative Hidden Divergence') 347 | -------------------------------------------------------------------------------- /IchimokuTwistOnly.pscript: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © KrustyHack 3 | 4 | //@version=4 5 | study(title="Ichimoku Twist Only", shorttitle="Ichimoku Twist Only", overlay=true) 6 | conversionPeriods = input(9, minval=1, title="Conversion Line Length") 7 | basePeriods = input(26, minval=1, title="Base Line Length") 8 | laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Length") 9 | displacement = input(26, minval=1, title="Displacement") 10 | donchian(len) => avg(lowest(len), highest(len)) 11 | conversionLine = donchian(conversionPeriods) 12 | baseLine = donchian(basePeriods) 13 | leadLine1 = avg(conversionLine, baseLine) 14 | leadLine2 = donchian(laggingSpan2Periods) 15 | 16 | plotshape(cross(leadLine1, leadLine2) ? leadLine1 : na, style=shape.diamond, offset = displacement - 1, size = size.tiny, location = location.absolute) 17 | //bgcolor(color=cross(leadLine1, leadLine2) ? color.yellow : na, transp = 90, offset = displacement - 1) 18 | -------------------------------------------------------------------------------- /ImbalanceZoneFinder.pscript: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // @frozon : https://www.tradingview.com/u/frozon/ 3 | 4 | // Update 5 | // - update screenshot 6 | // - add alerts 7 | // - fix deletion of triggered zone 8 | // - update screenshot 9 | // - add mid lines to imbalanced boxes 10 | // - add color option for each box type 11 | 12 | //@version=5 13 | indicator(title='Imbalanced zone', overlay=true) 14 | 15 | penetrationRatio = input.float(defval=0.2, minval=0, maxval=1, step=0.1, title="Penetration Ratio") 16 | extendBoxes = input.bool(defval=true, title="Extend boxes") 17 | imbalancedDownColor = input.color(color.rgb(120,120,120,60), title="Box color", group="Imbalanced down") 18 | imbalancedDownMidLineColor = input.color(color.rgb(120,120,120), title="Mid line color", group="Imbalanced down") 19 | imbalancedUpColor = input.color(color.rgb(120,120,120,60), title="Box color", group="Imbalanced up") 20 | imbalancedUpMidLineColor = input.color(color.rgb(120,120,120), title="Mid line color", group="Imbalanced up") 21 | 22 | var box[] imbalancedDownBoxes = array.new_box() 23 | var box[] imbalancedUpBoxes = array.new_box() 24 | var line[] imbalancedDownMidLines = array.new_line() 25 | var line[] imbalancedUpMidLines = array.new_line() 26 | 27 | extension = extend.none 28 | if extendBoxes 29 | extension := extend.right 30 | 31 | if high[3] < low[1] 32 | array.push(imbalancedDownBoxes, box.new(left=bar_index - 2, bottom=high[3], right=bar_index + 20, top=low[1], bgcolor=imbalancedDownColor, border_color=imbalancedDownColor, extend=extension)) 33 | midPoint = (high[3]-low[1])/2+low[1] 34 | array.push(imbalancedDownMidLines, line.new(bar_index - 2, midPoint, bar_index+20, midPoint, style=line.style_dotted, extend=extension, color=imbalancedDownMidLineColor)) 35 | if low[3] > high[1] 36 | array.push(imbalancedUpBoxes, box.new(left=bar_index - 2, top=low[3], right=bar_index + 20, bottom=high[1], bgcolor=imbalancedUpColor, border_color=imbalancedUpColor, extend=extension)) 37 | midPoint = (high[1]-low[3])/2+low[3] 38 | array.push(imbalancedUpMidLines, line.new(bar_index - 2, midPoint, bar_index+20, midPoint, style=line.style_dotted, extend=extension, color=imbalancedUpMidLineColor)) 39 | 40 | if array.size(imbalancedUpBoxes) > 0 41 | for i = array.size(imbalancedUpBoxes) - 1 to 0 by 1 42 | imbalancedBox = array.get(imbalancedUpBoxes, i) 43 | top = box.get_top(imbalancedBox) 44 | bottom = box.get_bottom(imbalancedBox) 45 | invalidationLimit = (top - bottom) * penetrationRatio 46 | box.set_right(imbalancedBox, bar_index + 20) 47 | 48 | midLine = array.get(imbalancedUpMidLines, i) 49 | line.set_x2(midLine, bar_index + 20) 50 | 51 | if high >= bottom + invalidationLimit 52 | box.delete(imbalancedBox) 53 | array.remove(imbalancedUpBoxes, i) 54 | line.delete(midLine) 55 | array.remove(imbalancedUpMidLines, i) 56 | 57 | if array.size(imbalancedDownBoxes) > 0 58 | for i = array.size(imbalancedDownBoxes) - 1 to 0 by 1 59 | imbalancedBox = array.get(imbalancedDownBoxes, i) 60 | top = box.get_top(imbalancedBox) 61 | bottom = box.get_bottom(imbalancedBox) 62 | invalidationLimit = (top - bottom) * penetrationRatio 63 | box.set_right(imbalancedBox, bar_index + 20) 64 | 65 | midLine = array.get(imbalancedDownMidLines, i) 66 | line.set_x2(midLine, bar_index + 20) 67 | 68 | if low <= top - invalidationLimit 69 | box.delete(imbalancedBox) 70 | array.remove(imbalancedDownBoxes, i) 71 | line.delete(midLine) 72 | array.remove(imbalancedDownMidLines, i) 73 | 74 | // Alerts 75 | alertcondition(high[3] < low[1] or low[3] > high[1], title="New imbalanced candle") 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tradingview-scripts 2 | 3 | ## https://www.tradingview.com/u/KrustyHack/ 4 | 5 | * [WIP] Candle Recon Ultimate 6 | * [WIP] ADX and DI Improved 7 | 8 | ## https://fr.tradingview.com/u/LonesomeTheBlue 9 | 10 | * https://fr.tradingview.com/script/va09eWAp-Support-Resistance-Dynamic-v2/ 11 | * https://fr.tradingview.com/script/iN9FTv45-Divergence-for-many-indicator-v3/ 12 | 13 | ## https://www.tradingview.com/u/BarsStallone 14 | 15 | * https://www.tradingview.com/script/JAW0oW7R-Support-Resistance-V2-Indicator/ 16 | 17 | ## https://www.tradingview.com/u/frozon/ 18 | 19 | * https://www.tradingview.com/script/7GES9cXf-Imbalanced-zone/ 20 | -------------------------------------------------------------------------------- /Support-Resistance-Dynamic-v2.pscript: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © LonesomeTheBlue 3 | 4 | //@version=4 5 | study("Support Resistance - Dynamic v2", "SRv2", overlay = true) 6 | prd = input(defval = 10, title="Pivot Period", minval = 4, maxval = 30) 7 | ppsrc = input(defval = 'High/Low', title="Source", options = ['High/Low', 'Close/Open']) 8 | maxnumpp = input(defval = 20, title =" Maximum Number of Pivot", minval = 5, maxval = 100) 9 | ChannelW = input(10, title = "Maximum Channel Width %", minval = 1) 10 | maxnumsr = input(5, title =" Maximum Number of S/R", minval = 1, maxval = 10) 11 | min_strength = input(2, title =" Minimum Strength", minval = 1, maxval = 10) 12 | linestyle = input(defval = 'Dashed', title = "Line Style", options = ['Solid', 'Dotted', 'Dashed']) 13 | linewidth = input(defval = 2, title = "Line Width", minval = 1, maxval = 4) 14 | resistancecolor = input(defval = color.red, title = "Resistance Color", type = input.color) 15 | supportcolor = input(defval = color.lime, title = "Support Color", type = input.color) 16 | showpp = input(false, title = "Show Point Points") 17 | 18 | float ph = na, float pl = na 19 | float src1 = ppsrc == 'High/Low' ? high : max(close, open) 20 | float src2 = ppsrc == 'High/Low' ? low: min(close, open) 21 | ph := pivothigh(src1, prd, prd) 22 | pl := pivotlow(src2, prd, prd) 23 | 24 | plotshape(ph and showpp, text = "H", style = shape.labeldown, color = na, textcolor = color.red, location = location.abovebar, transp = 0, offset = -prd) 25 | plotshape(pl and showpp, text = "L", style = shape.labelup, color = na, textcolor = color.lime, location = location.belowbar, transp = 0, offset = -prd) 26 | 27 | //calculate maximum S/R channel zone width 28 | prdhighest = highest(300) 29 | prdlowest = lowest(300) 30 | cwidth = (prdhighest - prdlowest) * ChannelW / 100 31 | 32 | var pivotvals= array.new_float(0) 33 | 34 | if ph or pl 35 | array.unshift(pivotvals, ph ? ph : pl) 36 | if array.size(pivotvals) > maxnumpp // limit the array size 37 | array.pop(pivotvals) 38 | 39 | get_sr_vals(ind)=> 40 | float lo = array.get(pivotvals, ind) 41 | float hi = lo 42 | int numpp = 0 43 | for y = 0 to array.size(pivotvals) - 1 44 | float cpp = array.get(pivotvals, y) 45 | float wdth = cpp <= lo ? hi - cpp : cpp - lo 46 | if wdth <= cwidth // fits the max channel width? 47 | lo := cpp <= lo ? cpp : lo 48 | hi := cpp > lo ? cpp : hi 49 | numpp := numpp + 1 50 | [hi, lo, numpp] 51 | 52 | var sr_up_level = array.new_float(0) 53 | var sr_dn_level = array.new_float(0) 54 | sr_strength = array.new_float(0) 55 | 56 | find_loc(strength)=> 57 | ret = array.size(sr_strength) 58 | if ret > 0 59 | for i = array.size(sr_strength) - 1 to 0 60 | if strength <= array.get(sr_strength, i) 61 | break 62 | ret := i 63 | ret 64 | 65 | check_sr(hi, lo, strength)=> 66 | ret = true 67 | if array.size(sr_up_level) > 0 68 | for i = 0 to array.size(sr_up_level) - 1 69 | //included? 70 | if array.get(sr_up_level, i) >= lo and array.get(sr_up_level, i) <= hi or 71 | array.get(sr_dn_level, i) >= lo and array.get(sr_dn_level, i) <= hi 72 | if strength >= array.get(sr_strength, i) 73 | array.remove(sr_strength, i) 74 | array.remove(sr_up_level, i) 75 | array.remove(sr_dn_level, i) 76 | ret 77 | else 78 | ret := false 79 | break 80 | ret 81 | 82 | //get min time 83 | var int btime = time 84 | btime := na(time[1]) ? btime : min(btime, time - time[1]) 85 | 86 | round_it(value)=> 87 | round(value / syminfo.mintick) * syminfo.mintick 88 | 89 | draw_line(ycoor, Lstyle)=> 90 | line.new(x1 = bar_index, 91 | y1 = ycoor, 92 | x2 = bar_index - 1, 93 | y2 = ycoor, 94 | extend = extend.both, 95 | color = ycoor >= close ? resistancecolor : supportcolor, 96 | style = Lstyle, 97 | width = linewidth) 98 | 99 | draw_label(ycoor)=> 100 | label.new(x = time + btime * 30, 101 | y = ycoor, text = tostring(ycoor), 102 | color = ycoor >= close ? color.red : color.lime, 103 | textcolor = ycoor >= close ? color.white : color.black, 104 | style = label.style_labeldown, 105 | xloc = xloc.bar_time, 106 | yloc = yloc.price) 107 | 108 | set_lx(lab, lin)=> 109 | label.set_x(lab, x = time + btime * 30) 110 | label.set_color(lab, color = label.get_y(lab) >= close ? color.red : color.lime) 111 | label.set_textcolor(lab, textcolor = label.get_y(lab) >= close ? color.white : color.black) 112 | line.set_color(lin, color = line.get_y1(lin) >= close ? resistancecolor : supportcolor) 113 | 114 | var line l1 = na, var line l2 = na, var line l3 = na, var line l4 = na, var line l5 = na, var line l6 = na, var line l7 = na, var line l8 = na, var line l9 = na, var line l10 = na 115 | var label lb1 = na, var label lb2 = na, var label lb3 = na, var label lb4 = na, var label lb5 = na, var label lb6 = na, var label lb7 = na, var label lb8 = na, var label lb9 = na, var label lb10 = na 116 | 117 | set_lx(lb1, l1), set_lx(lb2, l2), set_lx(lb3, l3), set_lx(lb4, l4), set_lx(lb5, l5), set_lx(lb6, l6), set_lx(lb7, l7), set_lx(lb8, l8), set_lx(lb9, l9), set_lx(lb10, l10) 118 | 119 | if ph or pl 120 | //because of new calculation, remove old S/R levels 121 | array.clear(sr_up_level) 122 | array.clear(sr_dn_level) 123 | array.clear(sr_strength) 124 | //find S/R zones 125 | for x = 0 to array.size(pivotvals) - 1 126 | [hi, lo, strength] = get_sr_vals(x) 127 | if check_sr(hi, lo, strength) 128 | loc = find_loc(strength) 129 | // if strength is in first maxnumsr sr then insert it to the arrays 130 | if loc < maxnumsr and strength >= min_strength 131 | array.insert(sr_strength, loc, strength) 132 | array.insert(sr_up_level, loc, hi) 133 | array.insert(sr_dn_level, loc, lo) 134 | // keep size of the arrays = 5 135 | if array.size(sr_strength) > maxnumsr 136 | array.pop(sr_strength) 137 | array.pop(sr_up_level) 138 | array.pop(sr_dn_level) 139 | 140 | line.delete(l1), line.delete(l2), line.delete(l3), line.delete(l4), line.delete(l5), line.delete(l6), line.delete(l7), line.delete(l8), line.delete(l9), line.delete(l10) 141 | label.delete(lb1), label.delete(lb2), label.delete(lb3), label.delete(lb4), label.delete(lb5), label.delete(lb6), label.delete(lb7), label.delete(lb8), label.delete(lb9), label.delete(lb10) 142 | if array.size(sr_up_level) 143 | Lstyle = linestyle == 'Dashed' ? line.style_dashed : 144 | linestyle == 'Solid' ? line.style_solid : 145 | line.style_dotted 146 | for x = 0 to array.size(sr_up_level) - 1 147 | float mid = round_it((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2) 148 | if x == 0 149 | l1 := draw_line(mid, Lstyle) 150 | lb1 := draw_label(mid) 151 | if x == 1 152 | l2 := draw_line(mid, Lstyle) 153 | lb2 := draw_label(mid) 154 | if x == 2 155 | l3 := draw_line(mid, Lstyle) 156 | lb3 := draw_label(mid) 157 | if x == 3 158 | l4 := draw_line(mid, Lstyle) 159 | lb4 := draw_label(mid) 160 | if x == 4 161 | l5 := draw_line(mid, Lstyle) 162 | lb5 := draw_label(mid) 163 | if x == 5 164 | l6 := draw_line(mid, Lstyle) 165 | lb6 := draw_label(mid) 166 | if x == 6 167 | l7 := draw_line(mid, Lstyle) 168 | lb7 := draw_label(mid) 169 | if x == 7 170 | l8 := draw_line(mid, Lstyle) 171 | lb8 := draw_label(mid) 172 | if x == 8 173 | l9 := draw_line(mid, Lstyle) 174 | lb9 := draw_label(mid) 175 | if x == 9 176 | l10 := draw_line(mid, Lstyle) 177 | lb10 := draw_label(mid) 178 | 179 | f_crossed_over()=> 180 | ret = false 181 | if array.size(sr_up_level) > 0 182 | for x = 0 to array.size(sr_up_level) - 1 183 | float mid = round_it((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2) 184 | if close[1] <= mid and close > mid 185 | ret := true 186 | ret 187 | 188 | f_crossed_under()=> 189 | ret = false 190 | if array.size(sr_up_level) > 0 191 | for x = 0 to array.size(sr_up_level) - 1 192 | float mid = round_it((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2) 193 | if close[1] >= mid and close < mid 194 | ret := true 195 | ret 196 | 197 | alertcondition(f_crossed_over(), title='Resistance Broken', message='Resistance Broken') 198 | alertcondition(f_crossed_under(), title='Support Broken', message='Support Broken') 199 | -------------------------------------------------------------------------------- /Support-Resistance-V2-Indicator.pscript: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | //@version=4 3 | study("Support/Resistance", shorttitle="S/R", overlay=true, scale = scale.right, linktoseries = true) 4 | 5 | line_width = input(4, type = input.integer, title="SR Level line Width") 6 | level_min_lengh = input(4, type = input.integer, title="Set minimum number of bars from level start to qualify a level") 7 | y = input("Orange", "Line Color", options=["Red", "Lime", "Orange", "Teal", "Yellow", "White", "Black"]) 8 | line_extend = input(false, type = input.bool, title = "Extend Level line Right") ? extend.right : extend.none 9 | sr_tf = input("", type = input.resolution, title="SR Timeframe (Beta)") 10 | 11 | //color function 12 | colour(z) => z=="Red"?color.red:z=="Lime"?color.lime:z=="Orange"?color.orange:z=="Teal"? 13 | color.teal:z=="Yellow"?color.yellow:z=="Black"?color.black:color.white 14 | 15 | //Legacy RSI calc 16 | rsi_src = close, len = 9 17 | up1 = rma(max(change(rsi_src), 0), len) 18 | down1 = rma(-min(change(rsi_src), 0), len) 19 | legacy_rsi = down1 == 0 ? 100 : up1 == 0 ? 0 : 100 - (100 / (1 + up1 / down1)) 20 | 21 | //CMO based on HMA 22 | length = 1 23 | src1 = hma(open, 5)[1] // legacy hma(5) calculation gives a resul with one candel shift, thus use hma()[1] 24 | src2 = hma(close, 12) 25 | momm1 = change(src1) 26 | momm2 = change(src2) 27 | f1(m, n) => m >= n ? m : 0.0 28 | f2(m, n) => m >= n ? 0.0 : -m 29 | m1 = f1(momm1, momm2) 30 | m2 = f2(momm1, momm2) 31 | sm1 = sum(m1, length) 32 | sm2 = sum(m2, length) 33 | percent(nom, div) => 100 * nom / div 34 | cmo_new = percent(sm1-sm2, sm1+sm2) 35 | 36 | //Legacy Close Pivots calcs. 37 | len5 = 2 38 | h = highest(len5) 39 | h1 = dev(h, len5) ? na : h 40 | hpivot = fixnan(h1) 41 | l = lowest(len5) 42 | l1 = dev(l, len5) ? na : l 43 | lpivot = fixnan(l1) 44 | 45 | //Calc Values 46 | 47 | rsi_new = rsi(close,9) 48 | lpivot_new = lpivot // use legacy pivots calculation as integrated pivotlow/pivothigh functions give very different result 49 | hpivot_new = hpivot 50 | 51 | sup = rsi_new < 25 and cmo_new > 50 and lpivot_new 52 | res = rsi_new > 75 and cmo_new < -50 and hpivot_new 53 | calcXup() => 54 | var xup = 0.0 55 | xup := sup ? low : xup[1] 56 | calcXdown() => 57 | var xdown = 0.0 58 | xdown := res ? high : xdown[1] 59 | 60 | //Lines drawing variables 61 | tf1 = security(syminfo.tickerid, sr_tf, calcXup(), lookahead=barmerge.lookahead_on) 62 | tf2 = security(syminfo.tickerid, sr_tf, calcXdown(), lookahead=barmerge.lookahead_on) 63 | 64 | //SR Line plotting 65 | var tf1_line = line.new(0, 0, 0, 0) 66 | var tf1_bi_start = 0 67 | var tf1_bi_end = 0 68 | tf1_bi_start := change(tf1) ? bar_index : tf1_bi_start[1] 69 | tf1_bi_end := change(tf1) ? tf1_bi_start : bar_index 70 | if change(tf1) 71 | if (line.get_x2(tf1_line) - line.get_x1(tf1_line)) < level_min_lengh 72 | line.delete(tf1_line) 73 | tf1_line := line.new(tf1_bi_start, tf1, tf1_bi_end, tf1, color = colour(y), width = line_width, extend = line_extend) 74 | line.set_x2(tf1_line, tf1_bi_end) 75 | 76 | var tf2_line = line.new(0, 0, 0, 0) 77 | var tf2_bi_start = 0 78 | var tf2_bi_end = 0 79 | tf2_bi_start := change(tf2) ? bar_index : tf2_bi_start[1] 80 | tf2_bi_end := change(tf2) ? tf2_bi_start : bar_index 81 | if change(tf2) 82 | if (line.get_x2(tf2_line) - line.get_x1(tf2_line)) < level_min_lengh 83 | line.delete(tf2_line) 84 | tf2_line := line.new(tf2_bi_start, tf2, tf2_bi_end, tf2, color = colour(y), width = line_width, extend = line_extend) 85 | line.set_x2(tf2_line, tf2_bi_end) 86 | 87 | alertcondition(change(tf1) != 0 or change(tf2) != 0 , message = "New S/R line" ) 88 | -------------------------------------------------------------------------------- /TrendLinesImproved.pscript: -------------------------------------------------------------------------------- 1 | //@version=4 2 | //scripts taken from https://www.tradingview.com/script/mpeEgn5J-Trendlines-JD/ 3 | //https://www.tradingview.com/script/X6MMLa9E-Fibonacci-Pivot-Points-Alerts/ 4 | //https://www.tradingview.com/script/yrmJJmyI-Trend-Lines/ 5 | study("Trend Lines+++ Improved", overlay=true) 6 | // 7 | src = input(close) 8 | 9 | // 10 | 11 | mx = input(100, "Range", minval=1) 12 | mn = max(2, round(mx / 10) + 1) 13 | 14 | LN(B, CLR) => 15 | s1 = B == 1 ? highest(src, mx) : lowest(src, mx) 16 | s2 = B == 1 ? highest(src, mn) : lowest(src, mn) 17 | c1 = s1 == src 18 | c2 = s2 == src 19 | b1 = barssince(c1) 20 | b2 = barssince(c2) 21 | v1 = valuewhen(c1, s1, 0) 22 | v2 = valuewhen(c2, s2, 0) 23 | line.new(bar_index - b1, v1, bar_index - b2, v2, extend=extend.both, color=CLR, width=2) 24 | 25 | L1 = LN(1, #ff0088), line.delete(L1[1]) 26 | L2 = LN(0, #00ff88), line.delete(L2[1]) 27 | // 28 | // Input variables 29 | len=input(10,title="loockback length pivots") 30 | wicks=input(true,title="Draw lines from wicks (checked) or real bodies (unchecked)?") 31 | disp_select=input(true,title="Display only falling 'high' and rising 'low' trendlines?") 32 | do_mono=input(false,title="checked = monochrome lines, unchecked = direction colored lines?") 33 | limit_extension=input(1,title="Limit extensions of the lines? 0 = infinite, other values x 100 bars",minval=0) 34 | do_alerts=input(true,title="show trendline breaks") 35 | trendline_nr=input(10,title="number of past trendlines to check for breaks (max = 10)",minval=0,maxval=10) 36 | select_breaks=input(true,title="only display 'long' breaks on trendlines connecting 'highs' and 'short' for 'lows'") 37 | log_chart=input(false,title="USING A LOG CHART? MAKE SURE TO CHECK THIS BOX!!") 38 | plot_pivots = input(false, title="Plot pivots ?", type=input.bool) 39 | draw_broken = input(false, title="Draw broken trendlines ?", type=input.bool) 40 | 41 | 42 | // Calculating the 'time value' of one bar 43 | bar_time=time-time[1] 44 | 45 | // Initialising color scheme 46 | var color color_rising=do_mono?color.teal:color.lime 47 | var color color_falling=do_mono?color.teal:color.fuchsia 48 | 49 | 50 | /////// Function declarations /////// 51 | 52 | // Declaration of trendline function 53 | f_trendline(_input_function,_delay,_only_up,_extend) => 54 | // Calculate line coordinates (Ax,Ay) - (Bx,By) 55 | var int Ax = 0 56 | var int Bx = 0 57 | var float By = 0.0 58 | var float slope = 0.0 59 | Ay = fixnan(_input_function) 60 | if change(Ay)!=0 61 | Ax := time[_delay] 62 | By:= Ay[1] 63 | Bx := Ax[1] 64 | slope:=log_chart?((log(Ay)-log(By))/(Ax-Bx)):((Ay-By)/(Ax-Bx)) 65 | else 66 | Ax := Ax[1] 67 | Bx := Bx[1] 68 | By := By[1] 69 | // Draw trendlines 70 | var line trendline=na 71 | var int Axbis=0 72 | var float Aybis=0.0 73 | var bool _xtend=true 74 | extension_time = limit_extension*bar_time*100 75 | Axbis := Ax + extension_time 76 | Aybis := log_chart?(Ay*exp(extension_time*slope)):(Ay + extension_time*slope) 77 | if limit_extension!=0 78 | _xtend:=false 79 | if change(Ay)!=0 80 | line_color = slope*time<0?(_only_up?(disp_select?na:color_rising):color_rising):(_only_up?color_falling:(disp_select?na:color_falling)) 81 | if not na(line_color) and draw_broken 82 | trendline := line.new(Bx,By,Axbis, Aybis, xloc.bar_time, extend=_xtend?extend.right:extend.none, color=line_color, style=line.style_dotted, width=1) 83 | 84 | [Bx,By,Axbis,Aybis,slope] 85 | 86 | // Function to get trendline price for X bars ago ("0" = current value) 87 | line_get_price(_start_time,_start_price,_slope,_lookback_period,_log_chart) => 88 | var float current_price=0.0 89 | elapsed_time = (time-_start_time) 90 | current_price := _log_chart?(_start_price*exp((elapsed_time-(_lookback_period*bar_time))*_slope)):(_start_price + (elapsed_time-(_lookback_period*bar_time))*_slope) 91 | 92 | // Function to check for trendline crosses 93 | line_cross(_check_value,_start_time,_start_price,_slope,_log_chart) => 94 | var float current_value=0.0 95 | var float previous_value=0.0 96 | // Get current and previous price for the trendline 97 | current_value := line_get_price(_start_time,_start_price,_slope,0,_log_chart) 98 | previous_value := line_get_price(_start_time,_start_price,_slope,1,_log_chart) 99 | // Return 1 for crossover, -1 for crossunder and 0 for no cross detected 100 | cross = 101 | _check_value[1]current_value?1: 102 | _check_value[1]>previous_value and _check_valueopen?close:open),len,len/2) 109 | low_point=pivotlow(wicks?low:(close>open?open:close),len,len/2) 110 | 111 | // Call trendline function for high and low pivot points 112 | [phx1,phy1,phx2,phy2,slope_high]=f_trendline(high_point,len/2,false,true) 113 | [plx1,ply1,plx2,ply2,slope_low]=f_trendline(low_point,len/2,true,true) 114 | 115 | // Initialition of pseudo array to keep track of last 10 high and 10 low trendline values 116 | var int high_x0=0, var float high_y0=0.0, var float high_sl0=0.0 117 | var int high_x1=0, var float high_y1=0.0, var float high_sl1=0.0 118 | var int high_x2=0, var float high_y2=0.0, var float high_sl2=0.0 119 | var int high_x3=0, var float high_y3=0.0, var float high_sl3=0.0 120 | var int high_x4=0, var float high_y4=0.0, var float high_sl4=0.0 121 | var int high_x5=0, var float high_y5=0.0, var float high_sl5=0.0 122 | var int high_x6=0, var float high_y6=0.0, var float high_sl6=0.0 123 | var int high_x7=0, var float high_y7=0.0, var float high_sl7=0.0 124 | var int high_x8=0, var float high_y8=0.0, var float high_sl8=0.0 125 | var int high_x9=0, var float high_y9=0.0, var float high_sl9=0.0 126 | 127 | var int low_x0=0, var float low_y0=0.0, var float low_sl0=0.0 128 | var int low_x1=0, var float low_y1=0.0, var float low_sl1=0.0 129 | var int low_x2=0, var float low_y2=0.0, var float low_sl2=0.0 130 | var int low_x3=0, var float low_y3=0.0, var float low_sl3=0.0 131 | var int low_x4=0, var float low_y4=0.0, var float low_sl4=0.0 132 | var int low_x5=0, var float low_y5=0.0, var float low_sl5=0.0 133 | var int low_x6=0, var float low_y6=0.0, var float low_sl6=0.0 134 | var int low_x7=0, var float low_y7=0.0, var float low_sl7=0.0 135 | var int low_x8=0, var float low_y8=0.0, var float low_sl8=0.0 136 | var int low_x9=0, var float low_y9=0.0, var float low_sl9=0.0 137 | 138 | // If a new trendline is formed, shift all values in the array one place up and forget the last values 139 | if change(fixnan(high_point))!=0 140 | high_x9:=high_x8, high_y9:=high_y8, high_sl9:=high_sl8 141 | high_x8:=high_x7, high_y8:=high_y7, high_sl8:=high_sl7 142 | high_x7:=high_x6, high_y7:=high_y6, high_sl7:=high_sl6 143 | high_x6:=high_x5, high_y6:=high_y5, high_sl6:=high_sl5 144 | high_x5:=high_x4, high_y5:=high_y4, high_sl5:=high_sl4 145 | high_x4:=high_x3, high_y4:=high_y3, high_sl4:=high_sl3 146 | high_x3:=high_x2, high_y3:=high_y2, high_sl3:=high_sl2 147 | high_x2:=high_x1, high_y2:=high_y1, high_sl2:=high_sl1 148 | high_x1:=high_x0, high_y1:=high_y0, high_sl1:=high_sl0 149 | high_x0:=phx1, high_y0:=phy1, high_sl0:=slope_high 150 | if change(fixnan(low_point))!=0 151 | low_x9:=low_x8, low_y9:=low_y8, low_sl9:=low_sl8 152 | low_x8:=low_x7, low_y8:=low_y7, low_sl8:=low_sl7 153 | low_x7:=low_x6, low_y7:=low_y6, low_sl7:=low_sl6 154 | low_x6:=low_x5, low_y6:=low_y5, low_sl6:=low_sl5 155 | low_x5:=low_x4, low_y5:=low_y4, low_sl5:=low_sl4 156 | low_x4:=low_x3, low_y4:=low_y3, low_sl4:=low_sl3 157 | low_x3:=low_x2, low_y3:=low_y2, low_sl3:=low_sl2 158 | low_x2:=low_x1, low_y2:=low_y1, low_sl2:=low_sl1 159 | low_x1:=low_x0, low_y1:=low_y0, low_sl1:=low_sl0 160 | low_x0:=plx1, low_y0:=ply1, low_sl0:=slope_low 161 | 162 | // Check Trendline crosses for last X nr. of trendlines 163 | cross_high0= 164 | disp_select and high_sl0*time>0?0: 165 | line_cross(close,high_x0,high_y0,high_sl0,log_chart) 166 | cross_low0= 167 | disp_select and low_sl0*time<0?0: 168 | line_cross(close,low_x0,low_y0,low_sl0,log_chart) 169 | 170 | cross_high1= 171 | disp_select and high_sl1*time>0?0: 172 | line_cross(close,high_x1,high_y1,high_sl1,log_chart) 173 | cross_low1= 174 | disp_select and low_sl1*time<0?0: 175 | line_cross(close,low_x1,low_y1,low_sl1,log_chart) 176 | 177 | cross_high2= 178 | disp_select and high_sl2*time>0?0: 179 | line_cross(close,high_x2,high_y2,high_sl2,log_chart) 180 | cross_low2= 181 | disp_select and low_sl2*time<0?0: 182 | line_cross(close,low_x2,low_y2,low_sl2,log_chart) 183 | 184 | cross_high3= 185 | disp_select and high_sl3*time>0?0: 186 | line_cross(close,high_x3,high_y3,high_sl3,log_chart) 187 | cross_low3= 188 | disp_select and low_sl3*time<0?0: 189 | line_cross(close,low_x3,low_y3,low_sl3,log_chart) 190 | 191 | cross_high4= 192 | disp_select and high_sl4*time>0?0: 193 | line_cross(close,high_x4,high_y4,high_sl4,log_chart) 194 | cross_low4= 195 | disp_select and low_sl4*time<0?0: 196 | line_cross(close,low_x4,low_y4,low_sl4,log_chart) 197 | 198 | cross_high5= 199 | disp_select and high_sl5*time>0?0: 200 | line_cross(close,high_x5,high_y5,high_sl5,log_chart) 201 | cross_low5= 202 | disp_select and low_sl5*time<0?0: 203 | line_cross(close,low_x5,low_y5,low_sl5,log_chart) 204 | 205 | cross_high6= 206 | disp_select and high_sl6*time>0?0: 207 | line_cross(close,high_x6,high_y6,high_sl6,log_chart) 208 | cross_low6= 209 | disp_select and low_sl6*time<0?0: 210 | line_cross(close,low_x6,low_y6,low_sl6,log_chart) 211 | 212 | cross_high7= 213 | disp_select and high_sl7*time>0?0: 214 | line_cross(close,high_x7,high_y7,high_sl7,log_chart) 215 | cross_low7= 216 | disp_select and low_sl7*time<0?0: 217 | line_cross(close,low_x7,low_y7,low_sl7,log_chart) 218 | 219 | cross_high8= 220 | disp_select and high_sl8*time>0?0: 221 | line_cross(close,high_x8,high_y8,high_sl8,log_chart) 222 | cross_low8= 223 | disp_select and low_sl8*time<0?0: 224 | line_cross(close,low_x8,low_y8,low_sl8,log_chart) 225 | 226 | cross_high9= 227 | disp_select and high_sl9*time>0?0: 228 | line_cross(close,high_x9,high_y9,high_sl9,log_chart) 229 | cross_low9= 230 | disp_select and low_sl9*time<0?0: 231 | line_cross(close,low_x9,low_y9,low_sl9,log_chart) 232 | 233 | long_break= 234 | (trendline_nr>9?cross_high9==1 or (select_breaks?false:cross_low9==1):false) or 235 | (trendline_nr>8?cross_high8==1 or (select_breaks?false:cross_low8==1):false) or 236 | (trendline_nr>7?cross_high7==1 or (select_breaks?false:cross_low7==1):false) or 237 | (trendline_nr>6?cross_high6==1 or (select_breaks?false:cross_low6==1):false) or 238 | (trendline_nr>5?cross_high5==1 or (select_breaks?false:cross_low5==1):false) or 239 | (trendline_nr>4?cross_high4==1 or (select_breaks?false:cross_low4==1):false) or 240 | (trendline_nr>3?cross_high3==1 or (select_breaks?false:cross_low3==1):false) or 241 | (trendline_nr>2?cross_high2==1 or (select_breaks?false:cross_low2==1):false) or 242 | (trendline_nr>1?cross_high1==1 or (select_breaks?false:cross_low1==1):false) or 243 | cross_high0==1 or (select_breaks?false:cross_low0==1) 244 | 245 | short_break= 246 | (trendline_nr>9?(select_breaks?false:cross_high9==-1) or cross_low9==-1:false) or 247 | (trendline_nr>8?(select_breaks?false:cross_high8==-1) or cross_low8==-1:false) or 248 | (trendline_nr>7?(select_breaks?false:cross_high7==-1) or cross_low7==-1:false) or 249 | (trendline_nr>6?(select_breaks?false:cross_high6==-1) or cross_low6==-1:false) or 250 | (trendline_nr>5?(select_breaks?false:cross_high5==-1) or cross_low5==-1:false) or 251 | (trendline_nr>4?(select_breaks?false:cross_high4==-1) or cross_low4==-1:false) or 252 | (trendline_nr>3?(select_breaks?false:cross_high3==-1) or cross_low3==-1:false) or 253 | (trendline_nr>2?(select_breaks?false:cross_high2==-1) or cross_low2==-1:false) or 254 | (trendline_nr>1?(select_breaks?false:cross_high1==-1) or cross_low1==-1:false) or 255 | (select_breaks?false:cross_high0==-1) or cross_low0==-1 256 | 257 | // Plot and connect pivot points 258 | color_high=slope_high*time<0?color_rising:(disp_select?na:color_falling) 259 | color_low=slope_low*time>0?color_falling:(disp_select?na:color_rising) 260 | plot(high_point,color=color_high,offset=-len/2) 261 | plot(low_point,color=color_low,offset=-len/2) 262 | // 263 | // Function outputs 1 when it's the first bar of the D/W/M/Y 264 | is_newbar(res) => 265 | ch = 0 266 | if(res == 'Y') 267 | t = year(time('D')) 268 | ch := change(t) != 0 ? 1 : 0 269 | else 270 | t = time(res) 271 | ch := change(t) != 0 ? 1 : 0 272 | ch 273 | 274 | //////////// 275 | // INPUTS // 276 | //////////// 277 | 278 | pp_period = input(title = "Period", type=input.string, defval="Day", options = ['Day', 'Week', 'Month', 'Year']) 279 | 280 | pp_res = pp_period == 'Day' ? 'D' : pp_period == 'Week' ? 'W' : pp_period == 'Month' ? 'M' : 'Y' 281 | 282 | ///////////////////// 283 | // Get HLC from HT // 284 | 285 | // Calc High 286 | high_cur = 0.0 287 | high_cur := is_newbar(pp_res) ? high : max(high_cur[1], high) 288 | 289 | phigh = 0.0 290 | phigh := is_newbar(pp_res) ? high_cur[1] : phigh[1] 291 | 292 | // Calc Low 293 | low_cur = 0.0 294 | low_cur := is_newbar(pp_res) ? low : min(low_cur[1], low) 295 | 296 | plow = 0.0 297 | plow := is_newbar(pp_res) ? low_cur[1] : plow[1] 298 | 299 | // Calc Close 300 | pclose = 0.0 301 | pclose := is_newbar(pp_res) ? close[1] : pclose[1] 302 | 303 | //////////////////////////////// 304 | // CALCULATE fibonacci pivots // 305 | 306 | vPP = (phigh + plow + pclose) / 3 307 | vR1 = vPP + (phigh - plow) * 0.382 308 | vS1 = vPP - (phigh - plow) * 0.382 309 | vR2 = vPP + (phigh - plow) * 0.618 310 | vS2 = vPP - (phigh - plow) * 0.618 311 | vR3 = vPP + (phigh - plow) * 1.000 312 | vS3 = vPP - (phigh - plow) * 1.000 313 | 314 | ////////////// 315 | // PLOTTING // 316 | 317 | bars_sinse = 0 318 | bars_sinse := is_newbar(pp_res) ? 0 : bars_sinse[1] + 1 319 | 320 | //////////////////////// 321 | // PLOT PIVOTS LEVELS // 322 | var line vpp_p = na 323 | var line vs1_p = na 324 | var line vs2_p = na 325 | var line vs3_p = na 326 | var line vr1_p = na 327 | var line vr2_p = na 328 | var line vr3_p = na 329 | 330 | if plot_pivots 331 | vpp_p := line.new(bar_index[bars_sinse], vPP, bar_index, vPP, color=#f57f17, style = line.style_solid, extend = extend.right) 332 | vs1_p := line.new(bar_index[bars_sinse], vS1, bar_index, vS1, color=#f57f17, style = line.style_solid, extend = extend.right) 333 | vs2_p := line.new(bar_index[bars_sinse], vS2, bar_index, vS2, color=#f57f17, style = line.style_solid, extend = extend.right) 334 | vs3_p := line.new(bar_index[bars_sinse], vS3, bar_index, vS3, color=#f57f17, style = line.style_solid, extend = extend.right) 335 | vr1_p := line.new(bar_index[bars_sinse], vR1, bar_index, vR1, color=#f57f17, style = line.style_solid, extend = extend.right) 336 | vr2_p := line.new(bar_index[bars_sinse], vR2, bar_index, vR2, color=#f57f17, style = line.style_solid, extend = extend.right) 337 | vr3_p := line.new(bar_index[bars_sinse], vR3, bar_index, vR3, color=#f57f17, style = line.style_solid, extend = extend.right) 338 | 339 | // delete previous lines in the same period 340 | if (not is_newbar(pp_res)) 341 | line.delete(vpp_p[1]) 342 | line.delete(vs1_p[1]) 343 | line.delete(vs2_p[1]) 344 | line.delete(vs3_p[1]) 345 | line.delete(vr1_p[1]) 346 | line.delete(vr2_p[1]) 347 | line.delete(vr3_p[1]) 348 | 349 | // delete extend for the old lines 350 | if (is_newbar(pp_res)) 351 | line.set_extend(vpp_p[1], extend.none) 352 | line.set_extend(vs1_p[1], extend.none) 353 | line.set_extend(vs2_p[1], extend.none) 354 | line.set_extend(vs3_p[1], extend.none) 355 | line.set_extend(vr1_p[1], extend.none) 356 | line.set_extend(vr2_p[1], extend.none) 357 | line.set_extend(vr3_p[1], extend.none) 358 | 359 | // Add labels 360 | if (is_newbar(pp_res) and plot_pivots) 361 | label_vpp = label.new(bar_index, vPP, text="P", style= label.style_none) 362 | label_vs1 = label.new(bar_index, vS1, text="S1", style= label.style_none) 363 | label_vs2 = label.new(bar_index, vS2, text="S2", style= label.style_none) 364 | label_vs3 = label.new(bar_index, vS3, text="S3", style= label.style_none) 365 | label_vr1 = label.new(bar_index, vR1, text="R1", style= label.style_none) 366 | label_vr2 = label.new(bar_index, vR2, text="R2", style= label.style_none) 367 | label_vr3 = label.new(bar_index, vR3, text="R3", style= label.style_none) 368 | 369 | -------------------------------------------------------------------------------- /TrendLinesImproved2.pscript: -------------------------------------------------------------------------------- 1 | //@version=4 2 | //scripts taken from https://www.tradingview.com/script/mpeEgn5J-Trendlines-JD/ 3 | //https://www.tradingview.com/script/X6MMLa9E-Fibonacci-Pivot-Points-Alerts/ 4 | //https://www.tradingview.com/script/yrmJJmyI-Trend-Lines/ 5 | study("Trend Lines+++ Improved", overlay=true) 6 | // 7 | src = input(close) 8 | 9 | // 10 | 11 | mx = input(100, "Range", minval=1) 12 | mn = max(2, round(mx / 10) + 1) 13 | 14 | LN(B, CLR) => 15 | s1 = B == 1 ? highest(src, mx) : lowest(src, mx) 16 | s2 = B == 1 ? highest(src, mn) : lowest(src, mn) 17 | c1 = s1 == src 18 | c2 = s2 == src 19 | b1 = barssince(c1) 20 | b2 = barssince(c2) 21 | v1 = valuewhen(c1, s1, 0) 22 | v2 = valuewhen(c2, s2, 0) 23 | line.new(bar_index - b1, v1, bar_index - b2, v2, extend=extend.both, color=CLR, width=2) 24 | 25 | L1 = LN(1, #ff0088), line.delete(L1[1]) 26 | L2 = LN(0, #00ff88), line.delete(L2[1]) 27 | // 28 | // Input variables 29 | len=input(10,title="loockback length pivots") 30 | wicks=input(true,title="Draw lines from wicks (checked) or real bodies (unchecked)?") 31 | disp_select=input(true,title="Display only falling 'high' and rising 'low' trendlines?") 32 | do_mono=input(false,title="checked = monochrome lines, unchecked = direction colored lines?") 33 | limit_extension=input(1,title="Limit extensions of the lines? 0 = infinite, other values x 100 bars",minval=0) 34 | do_alerts=input(true,title="show trendline breaks") 35 | trendline_nr=input(10,title="number of past trendlines to check for breaks (max = 10)",minval=0,maxval=10) 36 | select_breaks=input(true,title="only display 'long' breaks on trendlines connecting 'highs' and 'short' for 'lows'") 37 | log_chart=input(false,title="USING A LOG CHART? MAKE SURE TO CHECK THIS BOX!!") 38 | plot_pivots = input(false, title="Plot pivots ?", type=input.bool) 39 | draw_broken = input(false, title="Draw broken trendlines ?", type=input.bool) 40 | 41 | 42 | // Calculating the 'time value' of one bar 43 | bar_time=time-time[1] 44 | 45 | // Initialising color scheme 46 | var color color_rising=do_mono?color.teal:color.lime 47 | var color color_falling=do_mono?color.teal:color.fuchsia 48 | 49 | 50 | /////// Function declarations /////// 51 | 52 | // Declaration of trendline function 53 | f_trendline(_input_function,_delay,_only_up,_extend) => 54 | // Calculate line coordinates (Ax,Ay) - (Bx,By) 55 | var int Ax = 0 56 | var int Bx = 0 57 | var float By = 0.0 58 | var float slope = 0.0 59 | Ay = fixnan(_input_function) 60 | if change(Ay)!=0 61 | Ax := time[_delay] 62 | By:= Ay[1] 63 | Bx := Ax[1] 64 | slope:=log_chart?((log(Ay)-log(By))/(Ax-Bx)):((Ay-By)/(Ax-Bx)) 65 | else 66 | Ax := Ax[1] 67 | Bx := Bx[1] 68 | By := By[1] 69 | // Draw trendlines 70 | var line trendline=na 71 | var int Axbis=0 72 | var float Aybis=0.0 73 | var bool _xtend=true 74 | extension_time = limit_extension*bar_time*100 75 | Axbis := Ax + extension_time 76 | Aybis := log_chart?(Ay*exp(extension_time*slope)):(Ay + extension_time*slope) 77 | if limit_extension!=0 78 | _xtend:=false 79 | if change(Ay)!=0 80 | line_color = slope*time<0?(_only_up?(disp_select?na:color_rising):color_rising):(_only_up?color_falling:(disp_select?na:color_falling)) 81 | if not na(line_color) and draw_broken 82 | trendline := line.new(Bx,By,Axbis, Aybis, xloc.bar_time, extend=_xtend?extend.right:extend.none, color=line_color, style=line.style_dotted, width=1) 83 | 84 | [Bx,By,Axbis,Aybis,slope] 85 | 86 | // Function to get trendline price for X bars ago ("0" = current value) 87 | line_get_price(_start_time,_start_price,_slope,_lookback_period,_log_chart) => 88 | var float current_price=0.0 89 | elapsed_time = (time-_start_time) 90 | current_price := _log_chart?(_start_price*exp((elapsed_time-(_lookback_period*bar_time))*_slope)):(_start_price + (elapsed_time-(_lookback_period*bar_time))*_slope) 91 | 92 | // Function to check for trendline crosses 93 | line_cross(_check_value,_start_time,_start_price,_slope,_log_chart) => 94 | var float current_value=0.0 95 | var float previous_value=0.0 96 | // Get current and previous price for the trendline 97 | current_value := line_get_price(_start_time,_start_price,_slope,0,_log_chart) 98 | previous_value := line_get_price(_start_time,_start_price,_slope,1,_log_chart) 99 | // Return 1 for crossover, -1 for crossunder and 0 for no cross detected 100 | cross = 101 | _check_value[1]current_value?1: 102 | _check_value[1]>previous_value and _check_valueopen?close:open),len,len/2) 109 | low_point=pivotlow(wicks?low:(close>open?open:close),len,len/2) 110 | 111 | // Call trendline function for high and low pivot points 112 | [phx1,phy1,phx2,phy2,slope_high]=f_trendline(high_point,len/2,false,true) 113 | [plx1,ply1,plx2,ply2,slope_low]=f_trendline(low_point,len/2,true,true) 114 | 115 | // Initialition of pseudo array to keep track of last 10 high and 10 low trendline values 116 | var int high_x0=0, var float high_y0=0.0, var float high_sl0=0.0 117 | var int high_x1=0, var float high_y1=0.0, var float high_sl1=0.0 118 | var int high_x2=0, var float high_y2=0.0, var float high_sl2=0.0 119 | var int high_x3=0, var float high_y3=0.0, var float high_sl3=0.0 120 | var int high_x4=0, var float high_y4=0.0, var float high_sl4=0.0 121 | var int high_x5=0, var float high_y5=0.0, var float high_sl5=0.0 122 | var int high_x6=0, var float high_y6=0.0, var float high_sl6=0.0 123 | var int high_x7=0, var float high_y7=0.0, var float high_sl7=0.0 124 | var int high_x8=0, var float high_y8=0.0, var float high_sl8=0.0 125 | var int high_x9=0, var float high_y9=0.0, var float high_sl9=0.0 126 | 127 | var int low_x0=0, var float low_y0=0.0, var float low_sl0=0.0 128 | var int low_x1=0, var float low_y1=0.0, var float low_sl1=0.0 129 | var int low_x2=0, var float low_y2=0.0, var float low_sl2=0.0 130 | var int low_x3=0, var float low_y3=0.0, var float low_sl3=0.0 131 | var int low_x4=0, var float low_y4=0.0, var float low_sl4=0.0 132 | var int low_x5=0, var float low_y5=0.0, var float low_sl5=0.0 133 | var int low_x6=0, var float low_y6=0.0, var float low_sl6=0.0 134 | var int low_x7=0, var float low_y7=0.0, var float low_sl7=0.0 135 | var int low_x8=0, var float low_y8=0.0, var float low_sl8=0.0 136 | var int low_x9=0, var float low_y9=0.0, var float low_sl9=0.0 137 | 138 | // If a new trendline is formed, shift all values in the array one place up and forget the last values 139 | if change(fixnan(high_point))!=0 140 | high_x9:=high_x8, high_y9:=high_y8, high_sl9:=high_sl8 141 | high_x8:=high_x7, high_y8:=high_y7, high_sl8:=high_sl7 142 | high_x7:=high_x6, high_y7:=high_y6, high_sl7:=high_sl6 143 | high_x6:=high_x5, high_y6:=high_y5, high_sl6:=high_sl5 144 | high_x5:=high_x4, high_y5:=high_y4, high_sl5:=high_sl4 145 | high_x4:=high_x3, high_y4:=high_y3, high_sl4:=high_sl3 146 | high_x3:=high_x2, high_y3:=high_y2, high_sl3:=high_sl2 147 | high_x2:=high_x1, high_y2:=high_y1, high_sl2:=high_sl1 148 | high_x1:=high_x0, high_y1:=high_y0, high_sl1:=high_sl0 149 | high_x0:=phx1, high_y0:=phy1, high_sl0:=slope_high 150 | if change(fixnan(low_point))!=0 151 | low_x9:=low_x8, low_y9:=low_y8, low_sl9:=low_sl8 152 | low_x8:=low_x7, low_y8:=low_y7, low_sl8:=low_sl7 153 | low_x7:=low_x6, low_y7:=low_y6, low_sl7:=low_sl6 154 | low_x6:=low_x5, low_y6:=low_y5, low_sl6:=low_sl5 155 | low_x5:=low_x4, low_y5:=low_y4, low_sl5:=low_sl4 156 | low_x4:=low_x3, low_y4:=low_y3, low_sl4:=low_sl3 157 | low_x3:=low_x2, low_y3:=low_y2, low_sl3:=low_sl2 158 | low_x2:=low_x1, low_y2:=low_y1, low_sl2:=low_sl1 159 | low_x1:=low_x0, low_y1:=low_y0, low_sl1:=low_sl0 160 | low_x0:=plx1, low_y0:=ply1, low_sl0:=slope_low 161 | 162 | // Check Trendline crosses for last X nr. of trendlines 163 | cross_high0= 164 | disp_select and high_sl0*time>0?0: 165 | line_cross(close,high_x0,high_y0,high_sl0,log_chart) 166 | cross_low0= 167 | disp_select and low_sl0*time<0?0: 168 | line_cross(close,low_x0,low_y0,low_sl0,log_chart) 169 | 170 | cross_high1= 171 | disp_select and high_sl1*time>0?0: 172 | line_cross(close,high_x1,high_y1,high_sl1,log_chart) 173 | cross_low1= 174 | disp_select and low_sl1*time<0?0: 175 | line_cross(close,low_x1,low_y1,low_sl1,log_chart) 176 | 177 | cross_high2= 178 | disp_select and high_sl2*time>0?0: 179 | line_cross(close,high_x2,high_y2,high_sl2,log_chart) 180 | cross_low2= 181 | disp_select and low_sl2*time<0?0: 182 | line_cross(close,low_x2,low_y2,low_sl2,log_chart) 183 | 184 | cross_high3= 185 | disp_select and high_sl3*time>0?0: 186 | line_cross(close,high_x3,high_y3,high_sl3,log_chart) 187 | cross_low3= 188 | disp_select and low_sl3*time<0?0: 189 | line_cross(close,low_x3,low_y3,low_sl3,log_chart) 190 | 191 | cross_high4= 192 | disp_select and high_sl4*time>0?0: 193 | line_cross(close,high_x4,high_y4,high_sl4,log_chart) 194 | cross_low4= 195 | disp_select and low_sl4*time<0?0: 196 | line_cross(close,low_x4,low_y4,low_sl4,log_chart) 197 | 198 | cross_high5= 199 | disp_select and high_sl5*time>0?0: 200 | line_cross(close,high_x5,high_y5,high_sl5,log_chart) 201 | cross_low5= 202 | disp_select and low_sl5*time<0?0: 203 | line_cross(close,low_x5,low_y5,low_sl5,log_chart) 204 | 205 | cross_high6= 206 | disp_select and high_sl6*time>0?0: 207 | line_cross(close,high_x6,high_y6,high_sl6,log_chart) 208 | cross_low6= 209 | disp_select and low_sl6*time<0?0: 210 | line_cross(close,low_x6,low_y6,low_sl6,log_chart) 211 | 212 | cross_high7= 213 | disp_select and high_sl7*time>0?0: 214 | line_cross(close,high_x7,high_y7,high_sl7,log_chart) 215 | cross_low7= 216 | disp_select and low_sl7*time<0?0: 217 | line_cross(close,low_x7,low_y7,low_sl7,log_chart) 218 | 219 | cross_high8= 220 | disp_select and high_sl8*time>0?0: 221 | line_cross(close,high_x8,high_y8,high_sl8,log_chart) 222 | cross_low8= 223 | disp_select and low_sl8*time<0?0: 224 | line_cross(close,low_x8,low_y8,low_sl8,log_chart) 225 | 226 | cross_high9= 227 | disp_select and high_sl9*time>0?0: 228 | line_cross(close,high_x9,high_y9,high_sl9,log_chart) 229 | cross_low9= 230 | disp_select and low_sl9*time<0?0: 231 | line_cross(close,low_x9,low_y9,low_sl9,log_chart) 232 | 233 | long_break= 234 | (trendline_nr>9?cross_high9==1 or (select_breaks?false:cross_low9==1):false) or 235 | (trendline_nr>8?cross_high8==1 or (select_breaks?false:cross_low8==1):false) or 236 | (trendline_nr>7?cross_high7==1 or (select_breaks?false:cross_low7==1):false) or 237 | (trendline_nr>6?cross_high6==1 or (select_breaks?false:cross_low6==1):false) or 238 | (trendline_nr>5?cross_high5==1 or (select_breaks?false:cross_low5==1):false) or 239 | (trendline_nr>4?cross_high4==1 or (select_breaks?false:cross_low4==1):false) or 240 | (trendline_nr>3?cross_high3==1 or (select_breaks?false:cross_low3==1):false) or 241 | (trendline_nr>2?cross_high2==1 or (select_breaks?false:cross_low2==1):false) or 242 | (trendline_nr>1?cross_high1==1 or (select_breaks?false:cross_low1==1):false) or 243 | cross_high0==1 or (select_breaks?false:cross_low0==1) 244 | 245 | short_break= 246 | (trendline_nr>9?(select_breaks?false:cross_high9==-1) or cross_low9==-1:false) or 247 | (trendline_nr>8?(select_breaks?false:cross_high8==-1) or cross_low8==-1:false) or 248 | (trendline_nr>7?(select_breaks?false:cross_high7==-1) or cross_low7==-1:false) or 249 | (trendline_nr>6?(select_breaks?false:cross_high6==-1) or cross_low6==-1:false) or 250 | (trendline_nr>5?(select_breaks?false:cross_high5==-1) or cross_low5==-1:false) or 251 | (trendline_nr>4?(select_breaks?false:cross_high4==-1) or cross_low4==-1:false) or 252 | (trendline_nr>3?(select_breaks?false:cross_high3==-1) or cross_low3==-1:false) or 253 | (trendline_nr>2?(select_breaks?false:cross_high2==-1) or cross_low2==-1:false) or 254 | (trendline_nr>1?(select_breaks?false:cross_high1==-1) or cross_low1==-1:false) or 255 | (select_breaks?false:cross_high0==-1) or cross_low0==-1 256 | 257 | // Plot and connect pivot points 258 | color_high=slope_high*time<0?color_rising:(disp_select?na:color_falling) 259 | color_low=slope_low*time>0?color_falling:(disp_select?na:color_rising) 260 | plot(high_point,color=color_high,offset=-len/2) 261 | plot(low_point,color=color_low,offset=-len/2) 262 | // 263 | // Function outputs 1 when it's the first bar of the D/W/M/Y 264 | is_newbar(res) => 265 | ch = 0 266 | if(res == 'Y') 267 | t = year(time('D')) 268 | ch := change(t) != 0 ? 1 : 0 269 | else 270 | t = time(res) 271 | ch := change(t) != 0 ? 1 : 0 272 | ch 273 | 274 | //////////// 275 | // INPUTS // 276 | //////////// 277 | 278 | pp_period = input(title = "Period", type=input.string, defval="Day", options = ['Day', 'Week', 'Month', 'Year']) 279 | 280 | pp_res = pp_period == 'Day' ? 'D' : pp_period == 'Week' ? 'W' : pp_period == 'Month' ? 'M' : 'Y' 281 | 282 | ///////////////////// 283 | // Get HLC from HT // 284 | 285 | // Calc High 286 | high_cur = 0.0 287 | high_cur := is_newbar(pp_res) ? high : max(high_cur[1], high) 288 | 289 | phigh = 0.0 290 | phigh := is_newbar(pp_res) ? high_cur[1] : phigh[1] 291 | 292 | // Calc Low 293 | low_cur = 0.0 294 | low_cur := is_newbar(pp_res) ? low : min(low_cur[1], low) 295 | 296 | plow = 0.0 297 | plow := is_newbar(pp_res) ? low_cur[1] : plow[1] 298 | 299 | // Calc Close 300 | pclose = 0.0 301 | pclose := is_newbar(pp_res) ? close[1] : pclose[1] 302 | 303 | //////////////////////////////// 304 | // CALCULATE fibonacci pivots // 305 | 306 | vPP = (phigh + plow + pclose) / 3 307 | vR1 = vPP + (phigh - plow) * 0.382 308 | vS1 = vPP - (phigh - plow) * 0.382 309 | vR2 = vPP + (phigh - plow) * 0.618 310 | vS2 = vPP - (phigh - plow) * 0.618 311 | vR3 = vPP + (phigh - plow) * 1.000 312 | vS3 = vPP - (phigh - plow) * 1.000 313 | 314 | ////////////// 315 | // PLOTTING // 316 | 317 | bars_sinse = 0 318 | bars_sinse := is_newbar(pp_res) ? 0 : bars_sinse[1] + 1 319 | 320 | //////////////////////// 321 | // PLOT PIVOTS LEVELS // 322 | var line vpp_p = na 323 | var line vs1_p = na 324 | var line vs2_p = na 325 | var line vs3_p = na 326 | var line vr1_p = na 327 | var line vr2_p = na 328 | var line vr3_p = na 329 | 330 | if plot_pivots 331 | vpp_p := line.new(bar_index[bars_sinse], vPP, bar_index, vPP, color=#f57f17, style = line.style_solid, extend = extend.right) 332 | vs1_p := line.new(bar_index[bars_sinse], vS1, bar_index, vS1, color=#f57f17, style = line.style_solid, extend = extend.right) 333 | vs2_p := line.new(bar_index[bars_sinse], vS2, bar_index, vS2, color=#f57f17, style = line.style_solid, extend = extend.right) 334 | vs3_p := line.new(bar_index[bars_sinse], vS3, bar_index, vS3, color=#f57f17, style = line.style_solid, extend = extend.right) 335 | vr1_p := line.new(bar_index[bars_sinse], vR1, bar_index, vR1, color=#f57f17, style = line.style_solid, extend = extend.right) 336 | vr2_p := line.new(bar_index[bars_sinse], vR2, bar_index, vR2, color=#f57f17, style = line.style_solid, extend = extend.right) 337 | vr3_p := line.new(bar_index[bars_sinse], vR3, bar_index, vR3, color=#f57f17, style = line.style_solid, extend = extend.right) 338 | 339 | // delete previous lines in the same period 340 | if (not is_newbar(pp_res)) 341 | line.delete(vpp_p[1]) 342 | line.delete(vs1_p[1]) 343 | line.delete(vs2_p[1]) 344 | line.delete(vs3_p[1]) 345 | line.delete(vr1_p[1]) 346 | line.delete(vr2_p[1]) 347 | line.delete(vr3_p[1]) 348 | 349 | // delete extend for the old lines 350 | if (is_newbar(pp_res)) 351 | line.set_extend(vpp_p[1], extend.none) 352 | line.set_extend(vs1_p[1], extend.none) 353 | line.set_extend(vs2_p[1], extend.none) 354 | line.set_extend(vs3_p[1], extend.none) 355 | line.set_extend(vr1_p[1], extend.none) 356 | line.set_extend(vr2_p[1], extend.none) 357 | line.set_extend(vr3_p[1], extend.none) 358 | 359 | // Add labels 360 | if (is_newbar(pp_res) and plot_pivots) 361 | label_vpp = label.new(bar_index, vPP, text="P", style= label.style_none) 362 | label_vs1 = label.new(bar_index, vS1, text="S1", style= label.style_none) 363 | label_vs2 = label.new(bar_index, vS2, text="S2", style= label.style_none) 364 | label_vs3 = label.new(bar_index, vS3, text="S3", style= label.style_none) 365 | label_vr1 = label.new(bar_index, vR1, text="R1", style= label.style_none) 366 | label_vr2 = label.new(bar_index, vR2, text="R2", style= label.style_none) 367 | label_vr3 = label.new(bar_index, vR3, text="R3", style= label.style_none) 368 | 369 | --------------------------------------------------------------------------------