Pivot Boss Candlestick Scanner.pine
Copy
//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pranjalchaubey
//Structural Pivots
study(title="[CP]Pivot Boss Candlestick Scanner", shorttitle="[CP]Pivot Boss Candlesticks", overlay=true, max_labels_count=500)
// Hack to Prevent Indicator Repainting
//==============================================================================
current_high = high[barstate.isrealtime ? 1 : 0]
current_low = low[barstate.isrealtime ? 1 : 0]
current_open = open[barstate.isrealtime ? 1 : 0]
current_close = close[barstate.isrealtime ? 1 : 0]
current_x = barstate.isrealtime ? bar_index-1 : bar_index
// General User Inputs
//==============================================================================
// Set the date range
startDate = input(title="Start Date", type=input.integer, defval=1, minval=1, maxval=31, group="General User Inputs")
startMonth = input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12, group="General User Inputs")
startYear = input(title="Start Year", type=input.integer, defval=2010, minval=1970, maxval=2100, group="General User Inputs")
endDate = input(title="End Date", type=input.integer, defval=31, minval=1, maxval=31, group="General User Inputs")
endMonth = input(title="End Month", type=input.integer, defval=12, minval=1, maxval=12, group="General User Inputs")
endYear = input(title="End Year", type=input.integer, defval=2012, minval=1970, maxval=2100, group="General User Inputs")
// Look if the current_close time of the current bar falls inside the date range
inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
date_range = input(false, title="Use the date range above to mark the Candlestick Setups?", group="General User Inputs")
mid_enable = input(true, title="Mark Candle Mid-Range on the signal candles?", group="General User Inputs")
// Candle Mid-range Calculation
//==============================================================================
mid_range = current_low + (current_high - current_low) / 2
// EXTREME REVERSAL SETUP
//==============================================================================
// Inputs
enable_extreme_reversal_setup = input(true, type=input.bool, title="Enable Extreme Reversal Setup", group="Extreme Reversal Setup")
lookback_period = input(3, type=input.integer, title="Lookback Bars", group="Extreme Reversal Setup")
trigger_bar_size = input(2.0, type=input.float, title="Trigger Bar Size compared to avg Lookback Bar Sizes", group="Extreme Reversal Setup")
trigger_bar_min_percent_cover = input(50, type=input.integer, maxval=80, title="Trigger Bar Minimum Body Coverage Percentage", group="Extreme Reversal Setup")
trigger_bar_max_percent_cover = input(85, type=input.integer, minval=50, maxval=95, title="Trigger Bar Maximum Body Coverage Percentage", group="Extreme Reversal Setup")
extreme_reversal_shape = input("Cross", options=["Circle", "Triangle", "Cross", "Diamond"], title="Extreme Reversal Marker", group="Extreme Reversal Setup")
bullish_extreme_marker_color = input(color.blue, type = input.color, title="Bullish Extreme Reversal Marker Color", group="Extreme Reversal Setup")
bearish_extreme_marker_color = input(color.blue, type = input.color, title="Bearish Extreme Reversal Marker Color", group="Extreme Reversal Setup")
// Extreme Reversal Setup Markers
bullish_extreme_reversal_marker = label.style_circle
bearish_extreme_reversal_marker = label.style_circle
if extreme_reversal_shape == "Triangle"
bullish_extreme_reversal_marker := label.style_triangleup
bearish_extreme_reversal_marker := label.style_triangledown
else if extreme_reversal_shape == "Cross"
bullish_extreme_reversal_marker := label.style_xcross
bearish_extreme_reversal_marker := label.style_xcross
else if extreme_reversal_shape == "Diamond"
bullish_extreme_reversal_marker := label.style_diamond
bearish_extreme_reversal_marker := label.style_diamond
// Calculations - We assume that we are standing on the second bar of this pattern
lookback_period_avg_range = sum(high - low, lookback_period)[2]/lookback_period // [2] as we will compare the avg range with the candle BEFORE the current candle
norepaint_lookback_period_avg_range = barstate.isrealtime ? lookback_period_avg_range[1] : lookback_period_avg_range // Fix Repainting
trigger_bar_body = abs(current_open[1] - current_close[1])
actual_bar_body_coverage = (trigger_bar_body/(current_high[1] - current_low[1])) * 100
// Logic
size_condition = trigger_bar_body > trigger_bar_size * norepaint_lookback_period_avg_range
bar_body_coverage_condition = actual_bar_body_coverage > trigger_bar_min_percent_cover and actual_bar_body_coverage < trigger_bar_max_percent_cover
bullish_bar_after_trigger_bar_condition = (current_close[1] < current_open[1]) and (current_close > current_open)
bearish_bar_after_trigger_bar_condition = (current_close[1] > current_open[1]) and (current_close < current_open)
bullish_extreme_reversal = size_condition and bar_body_coverage_condition and bullish_bar_after_trigger_bar_condition
bearish_extreme_reversal = size_condition and bar_body_coverage_condition and bearish_bar_after_trigger_bar_condition
// Plots
if not(date_range == true and inDateRange == false) // Plot only if the bar is in date range, or the feature has been turned off
if enable_extreme_reversal_setup == true // Plot only if the user wants to plot the Extreme Reversal Setups on the chart
if bullish_extreme_reversal == true // A bullish extreme reversal was found
label.new(x=current_x, y=low, yloc=yloc.belowbar, color=bullish_extreme_marker_color, style=bullish_extreme_reversal_marker, size=size.auto, tooltip="Bullish Extreme Reversal Setup")
if mid_enable == true // Plot the Signal Candle Mid-range
label.new(x=current_x, y=mid_range, yloc=yloc.price, color=bullish_extreme_marker_color, style= label.style_xcross, size=size.auto, tooltip="Signal Candle Mid-Range")
else if bearish_extreme_reversal == true // A bearish extreme reversal was found
label.new(x=current_x, y=high, yloc=yloc.abovebar, color=bearish_extreme_marker_color, style=bearish_extreme_reversal_marker, size=size.auto, tooltip="Bearish Extreme Reversal Setup")
if mid_enable == true // Plot the Signal Candle Mid-range
label.new(x=current_x, y=mid_range, yloc=yloc.price, color=bearish_extreme_marker_color, style= label.style_xcross, size=size.auto, tooltip="Signal Candle Mid-Range")
// Debugging
//==============================================================================
// plotchar(lookback_period_avg_range, "Avg Range", "", location = location.top, size=size.tiny, color=color.lime)
// OUTSIDE REVERSAL SETUP
//==============================================================================
// Inputs
enable_outside_reversal_setup = input(true, type=input.bool, title="Enable Outside Reversal Setup", group="Outside Reversal Setup")
outside_lookback_period = input(12, type=input.integer, title="Lookback Bars", group="Outside Reversal Setup")
engulfing_bar_size_factor = input(1.25, type=input.float, minval=1, title="Engulfing Bar Size compared to Average Bar Size", group="Outside Reversal Setup")
outside_reversal_shape = input("Diamond", options=["Circle", "Triangle", "Cross", "Diamond"], title="Outside Reversal Marker", group="Outside Reversal Setup")
bullish_outside_marker_color = input(color.yellow, type = input.color, title="Bullish Outside Reversal Marker Color", group="Outside Reversal Setup")
bearish_outside_marker_color = input(color.yellow, type = input.color, title="Bearish Outside Reversal Marker Color", group="Outside Reversal Setup")
// Outside Reversal Setup Markers
bullish_outside_reversal_marker = label.style_circle
bearish_outside_reversal_marker = label.style_circle
if outside_reversal_shape == "Triangle"
bullish_outside_reversal_marker := label.style_triangleup
bearish_outside_reversal_marker := label.style_triangledown
else if outside_reversal_shape == "Cross"
bullish_outside_reversal_marker := label.style_xcross
bearish_outside_reversal_marker := label.style_xcross
else if outside_reversal_shape == "Diamond"
bullish_outside_reversal_marker := label.style_diamond
bearish_outside_reversal_marker := label.style_diamond
// Calculations - We assume that we are standing on the engulfing bar of this pattern
outside_lookback_period_avg_range = sum(high - low, outside_lookback_period)[1]/outside_lookback_period // [1] as we will compare the avg range BEFORE the current candle
norepaint_outside_lookback_period_avg_range = barstate.isrealtime ? outside_lookback_period_avg_range[1] : outside_lookback_period_avg_range // Fix Repainting
engulfing_bar_body = current_high - current_low
// Logic
outside_size_condition = engulfing_bar_body >= engulfing_bar_size_factor * norepaint_outside_lookback_period_avg_range
bullish_outside_reversal = outside_size_condition and (current_low < current_low[1]) and (current_close > current_high[1])
bearish_outside_reversal = outside_size_condition and (current_high > current_high[1]) and (current_close < current_low[1])
// Plots
if not(date_range == true and inDateRange == false) // Plot only if the bar is in date range, or the feature has been turned off
if enable_outside_reversal_setup == true // Plot only if the user wants to plot the Outside Reversal Setups on the chart
if bullish_outside_reversal == true // A bullish outside reversal was found
label.new(x=current_x, y=low, yloc=yloc.belowbar, color=bullish_outside_marker_color, style=bullish_outside_reversal_marker, size=size.auto, tooltip="Bullish Outside Reversal Setup")
if mid_enable == true // Plot the Signal Candle Mid-range
label.new(x=current_x, y=mid_range, yloc=yloc.price, color=bullish_outside_marker_color, style=label.style_xcross, size=size.auto, tooltip="Signal Candle Mid-Range")
else if bearish_outside_reversal == true // A bearish outside reversal was found
label.new(x=current_x, y=high, yloc=yloc.abovebar, color=bearish_outside_marker_color, style=bearish_outside_reversal_marker, size=size.auto, tooltip="Bearish Outside Reversal Setup")
if mid_enable == true // Plot the Signal Candle Mid-range
label.new(x=current_x, y=mid_range, yloc=yloc.price, color=bearish_outside_marker_color, style=label.style_xcross, size=size.auto, tooltip="Signal Candle Mid-Range")
// DOJI REVERSAL SETUP
//==============================================================================
// Inputs
enable_doji_reversal_setup = input(true, type=input.bool, title="Enable Doji Reversal Setup", group="Doji Reversal Setup")
doji_sma_lookback_period = input(10, type=input.integer, title="Doji SMA Lookback Period", group="Doji Reversal Setup")
doji_bar_size = input(10, type=input.float, minval=1, title="Doji Body Coverage Percentage", group="Doji Reversal Setup")
doji_reversal_shape = input("Triangle", options=["Circle", "Triangle", "Cross", "Diamond"], title="Doji Reversal Marker", group="Doji Reversal Setup")
bullish_doji_marker_color = input(color.aqua, type = input.color, title="Bullish Doji Reversal Marker Color", group="Doji Reversal Setup")
bearish_doji_marker_color = input(color.aqua, type = input.color, title="Bearish Doji Reversal Marker Color", group="Doji Reversal Setup")
// Doji Reversal Setup Markers
bullish_doji_reversal_marker = label.style_circle
bearish_doji_reversal_marker = label.style_circle
if doji_reversal_shape == "Triangle"
bullish_doji_reversal_marker := label.style_triangleup
bearish_doji_reversal_marker := label.style_triangledown
else if doji_reversal_shape == "Cross"
bullish_doji_reversal_marker := label.style_xcross
bearish_doji_reversal_marker := label.style_xcross
else if doji_reversal_shape == "Diamond"
bullish_doji_reversal_marker := label.style_diamond
bearish_doji_reversal_marker := label.style_diamond
// Calculations
moving_average = sma(current_close, doji_sma_lookback_period)
// Logic
var bool bullish_doji_reversal = na
bullish_doji = (((abs(current_open - current_close)/(current_high - current_low)) * 100) <= doji_bar_size) and (current_high < moving_average)
bars_since_bullish_doji = barssince(bullish_doji)
bullish_doji_reversal := (bars_since_bullish_doji > 0) and (bars_since_bullish_doji <= 2) and (current_close > current_high[bars_since_bullish_doji == 1? 1:2]) and not bullish_doji_reversal[1]
var bool bearish_doji_reversal = na
bearish_doji = (((abs(current_open - current_close)/(current_high - current_low)) * 100) <= doji_bar_size) and (current_low > moving_average)
bars_since_bearish_doji = barssince(bearish_doji)
bearish_doji_reversal := (bars_since_bearish_doji > 0) and (bars_since_bearish_doji <= 2) and (current_close < current_low[bars_since_bearish_doji == 1? 1:2]) and not bearish_doji_reversal[1]
// Plots
if not(date_range == true and inDateRange == false) // Plot only if the bar is in date range, or the feature has been turned off
if enable_doji_reversal_setup == true // Plot only if the user wants to plot the Doji Reversal Setups on the chart
if bullish_doji_reversal == true // A bullish doji reversal was found
label.new(x=current_x, y=low, yloc=yloc.belowbar, color=bullish_doji_marker_color, style=bullish_doji_reversal_marker, size=size.auto, tooltip="Bullish Doji Reversal Setup")
if mid_enable == true // Plot the Signal Candle Mid-range
label.new(x=current_x, y=mid_range, yloc=yloc.price, color=bullish_doji_marker_color, style=label.style_xcross, size=size.auto, tooltip="Signal Candle Mid-Range")
else if bearish_doji_reversal == true // A bearish doji reversal was found
label.new(x=current_x, y=high, yloc=yloc.abovebar, color=bearish_doji_marker_color, style=bearish_doji_reversal_marker, size=size.auto, tooltip="Bearish Doji Reversal Setup")
if mid_enable == true // Plot the Signal Candle Mid-range
label.new(x=current_x, y=mid_range, yloc=yloc.price, color=bearish_doji_marker_color, style=label.style_xcross, size=size.auto, tooltip="Signal Candle Mid-Range")
// Debugging
//==============================================================================
// plotchar(prev_bar_doji, "Prev Doji", "", location = location.top, size=size.tiny, color=color.lime)
// plotchar(prev_prev_bar_doji, "Prev Prev Doji", "", location = location.top, size=size.tiny, color=color.lime)
// plotchar(bars_since_bullish_doji, "Since Bullish", "", location = location.top, size=size.tiny, color=color.lime)
// WICK REVERSAL SETUP
//==============================================================================
// Inputs
enable_wick_reversal_setup = input(true, type=input.bool, title="Enable Wick Reversal Setup", group="Wick Reversal Setup")
wick_reversal_shape = input("Circle", options=["Circle", "Triangle", "Cross", "Diamond"], title="Wick Reversal Marker", group="Wick Reversal Setup")
bullish_wick_marker_color = input(color.white, type = input.color, title="Bullish Wick Reversal Marker Color", group="Wick Reversal Setup")
bearish_wick_marker_color = input(color.white, type = input.color, title="Bearish Wick Reversal Marker Color", group="Wick Reversal Setup")
wick2bodyRatio = input(2.5, type=input.float, minval=1, maxval=5, title="Wick to Body Ratio" , group="Wick Reversal Setup")
closePercentage = input(35, type=input.integer, minval=1, maxval=99, title="Top and Bottom Bar Close Percentage" , group="Wick Reversal Setup")
// Wick Reversal Setup Markers
bullish_wick_reversal_marker = label.style_circle
bearish_wick_reversal_marker = label.style_circle
if wick_reversal_shape == "Triangle"
bullish_wick_reversal_marker := label.style_triangleup
bearish_wick_reversal_marker := label.style_triangledown
else if wick_reversal_shape == "Cross"
bullish_wick_reversal_marker := label.style_xcross
bearish_wick_reversal_marker := label.style_xcross
else if wick_reversal_shape == "Diamond"
bullish_wick_reversal_marker := label.style_diamond
bearish_wick_reversal_marker := label.style_diamond
// Calculations
actual_close_percentage = closePercentage / 100
bar_body = abs(current_open - current_close)
wick_length = (current_open - current_close) <= 0 ? (current_high - current_close) + (current_open - current_low) : (current_high - current_open) + (current_close - current_low)
actual_wick_to_body_ratio = wick_length / bar_body
bar_range = current_high - current_low
bull_close_percentage = (current_high - current_close)/bar_range
bear_close_percentage = 1 - bull_close_percentage
// Logic
close_bullish = actual_wick_to_body_ratio >= wick2bodyRatio and bull_close_percentage <= actual_close_percentage ? true : false
close_bearish = actual_wick_to_body_ratio >= wick2bodyRatio and bear_close_percentage <= actual_close_percentage ? true : false
// Plots
if not(date_range == true and inDateRange == false) // Plot only if the bar is in date range, or the feature has been turned off
if enable_wick_reversal_setup == true // Plot only if the user wants to plot the Wick Reversal Setups on the chart
if close_bullish == true // A bullish wick reversal was found
label.new(x=current_x, y=low, yloc=yloc.belowbar, color=bullish_wick_marker_color, style=bullish_wick_reversal_marker, size=size.auto, tooltip="Bullish Wick Reversal Setup")
if mid_enable == true // Plot the Signal Candle Mid-range
label.new(x=current_x, y=mid_range, yloc=yloc.price, color=bullish_wick_marker_color, style=label.style_xcross, size=size.auto, tooltip="Signal Candle Mid-Range")
else if close_bearish == true // A bearish wick reversal was found
label.new(x=current_x, y=high, yloc=yloc.abovebar, color=bearish_wick_marker_color, style=bearish_wick_reversal_marker, size=size.auto, tooltip="Bearish Wick Reversal Setup")
if mid_enable == true // Plot the Signal Candle Mid-range
label.new(x=current_x, y=mid_range, yloc=yloc.price, color=bearish_wick_marker_color, style=label.style_xcross, size=size.auto, tooltip="Signal Candle Mid-Range")
// Debugging
//==============================================================================
// plotchar(bar_body, "Bar Body", "", location = location.top, size=size.tiny, color=color.lime)
// plotchar(wick_length, "Wick Length", "", location = location.top, size=size.tiny, color=color.lime)
// plotchar(actual_wick_to_body_ratio, "Wick2Body", "", location = location.top, size=size.tiny, color=color.lime)
// plotchar(bull_close_percentage, "Bull %age", "", location = location.top, size=size.tiny, color=color.green)
// plotchar(bear_close_percentage, "Bear %age", "", location = location.top, size=size.tiny, color=color.red)
// plotchar(close_bullish, "Bull", "", location = location.top, size=size.tiny, color=color.yellow)
// plotchar(close_bearish, "Bear", "", location = location.top, size=size.tiny, color=color.yellow)
Show all 272 lines