Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("Combined Patterns with Filter", overlay=true)
- // Filter settings
- filter = input(true, title="Filter")
- filtercutoff = input(7, title="Filter Cutoff")
- // Morning and Evening Stars
- DojiSize = input(0.25, minval=0.01, title="Doji size")
- doji(i) => abs(open[i] - close[i]) <= (high[i] - low[i]) * DojiSize
- dojifilter = doji(1) and not doji(0) and not doji(2)
- bar = abs(open - close)
- bar_1 = abs(open[1] - close[1])
- bar_2 = abs(open[2] - close[2])
- highfilter = filter ? max(high, high[1], high[2]) >= highest(filtercutoff) : true
- lowfilter = filter ? min(low, low[1], low[2]) <= lowest(filtercutoff) : true
- morning_star = bar > bar_1 and bar_2 > bar_1 and close > close[1] and close > open[1] and open[2] > close[1] and bar > (bar_2 * 0.5)
- morning_detected = morning_star or (dojifilter and lowfilter and close[1] < open[1] and close > open[1])
- evening_star = bar > bar_1 and bar_2 > bar_1 and close < close[1] and close < open[1] and open[2] < close[1] and bar > (bar_2 * 0.5)
- evening_detected = evening_star or (dojifilter and highfilter and close[1] > open[1] and close < open[1])
- // Tweezer
- maxrate = input(1.5, title="Max Rate % Between Wick Sizes") / 100
- leveldiff = input(0.2, title="Max Difference in level %") / 100
- prd = input(3, title="Highest/Lowest Period")
- apartprd = input(12, title="Max Distance between Tweezers", minval=1)
- colup = input(color.lime, title="Color", inline="col")
- coldn = input(color.red, title="", inline="col")
- topwick = high - max(close, open)
- bottomwick = min(close, open) - low
- aparttweezers_top(len) =>
- ret = 0
- if topwick > 0
- for x = 1 to len
- if na(topwick[x]) == false
- break
- if (max(topwick, topwick[x]) / min(topwick, topwick[x]) <= maxrate and abs(high - high[x]) < max(topwick, topwick[x]) * leveldiff)
- ret := x
- break
- else
- if high[x] >= high
- ret := 0
- break
- ret
- aparttweezers_bottom(len) =>
- ret = 0
- if bottomwick > 0
- for x = 1 to len
- if na(bottomwick[x]) == false
- break
- if (max(bottomwick, bottomwick[x]) / min(bottomwick, bottomwick[x]) <= maxrate and abs(low - low[x]) < max(bottomwick, bottomwick[x]) * leveldiff)
- ret := x
- break
- else
- if low[x] <= low
- ret := 0
- break
- ret
- top_tweezer = aparttweezers_top(apartprd)
- bottom_tweezer = aparttweezers_bottom(apartprd)
- // Piercing and Railroad Patterns
- piercing_pattern = (close[1] < open[1]) and (close > open) and (close > ((open[1] + close[1]) / 2))
- railroad_pattern = (close[1] < open[1]) and (open > close[1]) and (close > open)
- significant_wick_threshold = input(50, title="Significant Wick Threshold (%)") / 100
- candle_range = high - low
- candle_body = abs(close - open)
- has_significant_wick = (candle_range - candle_body) / candle_range >= significant_wick_threshold
- pattern_detected = morning_detected or evening_detected or top_tweezer or bottom_tweezer or piercing_pattern or railroad_pattern
- barcolor(pattern_detected and not has_significant_wick ? color.blue : na)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement