Here is an indicator that detects bullish and bearish Pin Bar candlestick patterns on your ThinkorSwim chart.
Pin Bars are candlestick patterns characterized by a long wick and a small body. They indicate potential reversals in market sentiment.
The below version with RSI which takes overbought and oversold values into consideration can be used for confirmation.
Similar to the Engulfing candles with RSI, we added the overbought input to bearish and oversold input to bullish Pin Bar candles. That means a Pin Bar candle will only be generated when a stock is oversold or overbought according to the default RSI indicator. You can also set each value to your liking.
Hopefully that will help to reduce false signals.
P.S: I found the original code without any header on it so I can't give credit to the developer. If you know who created it please let me know.
Pin Bars are candlestick patterns characterized by a long wick and a small body. They indicate potential reversals in market sentiment.
The below version with RSI which takes overbought and oversold values into consideration can be used for confirmation.
thinkScript Code
Rich (BB code):
input LastBars = 0;
input MaxNoseBodySize = 0.33; #(default = 0.33) — maximum allowed body/length ratio for the Nose bar.
input NoseBodyPosition = 0.4; #(default = 0.4) — Nose body should be position in top (bottom for bearish pattern) part of the Nose bar.
input LeftEyeOppositeDirection = yes; #(default = true) — tells the indicator that the Left Eye bar should be bearish for bullish Pinbar, and bullish for bearish Pinbar.
input NoseSameDirection = yes; #(default = true) — tells the indicator that the Nose bar should be of the same direction as the pattern itself.
input NoseBodyInsideLeftEyeBody = no; #(default = false) — tells the indicator that the Nose body should be inside the Left Eye body.
input LeftEyeMinBodySize = 0.1; #(default = 0.1) — minimum size of the Left Eye body relative to the bar length.
input NoseProtruding = 0.5; #(default = 0.5) — minimum protrusion of the Nose bar relative to the bar length.
input NoseBodyToLeftEyeBody = 1; #(default = 1) — maximum size of the Nose body relative to the Left eye body.
input NoseLengthToLeftEyeLength = 0; #(default = 0) — minimum Nose length relative to the Left Eye length.
input LeftEyeDepth = 0.2; #(default = 0.2) — minimum depth of the Left Eye relative to its length. Depth is length of the part of the bar behind the Nose.
# Left Eye and Nose bars's paramaters
def NoseLength = High - Low;
def LeftEyeLength = High[1] - Low[1];
def NoseBody = Absvalue(Open - Close);
def LeftEyeBody = Absvalue(Open[1] - Close[1]);
# Bearish Pinbar
def BearSignalDown = if (High - High[1] >= NoseLength * NoseProtruding) and
(NoseBody / NoseLength <= MaxNoseBodySize) and
(1 - (High - Max(Open, Close)) / NoseLength < NoseBodyPosition) and
if LeftEyeOppositeDirection then (Close[1] > Open[1]) else 1 and
if NoseSameDirection then (Close < Open) else 1 and
(LeftEyeBody / LeftEyeLength >= LeftEyeMinBodySize) and
((Max(Open, Close) <= High[1]) && (Min(Open, Close) >= Low[1])) and
(NoseBody / LeftEyeBody <= NoseBodyToLeftEyeBody) and
(NoseLength / LeftEyeLength >= NoseLengthToLeftEyeLength) and
(Low - Low[1] >= LeftEyeLength * LeftEyeDepth) and
if NoseBodyInsideLeftEyeBody then ((Max(Open, Close) <= Max(Open[1], Close[1]))
&& (Min(Open, Close) >= Min(Open[1], Close[1]))) else 1
then yes
else no ;
def BullSignalUp = if (Low[1] - Low >= NoseLength * NoseProtruding) and
(NoseBody / NoseLength <= MaxNoseBodySize) and
(1 - (Min(Open, Close) - Low) / NoseLength < NoseBodyPosition) and
if LeftEyeOppositeDirection then (Close[1] < Open[1]) else 1 and
if NoseSameDirection then (Close > Open) else 1 and
(LeftEyeBody / LeftEyeLength >= LeftEyeMinBodySize) and
((Max(Open, Close) <= High[1]) && (Min(Open, Close) >= Low[1])) and
(NoseBody / LeftEyeBody <= NoseBodyToLeftEyeBody) and
(NoseLength / LeftEyeLength >= NoseLengthToLeftEyeLength) and
(High[1] - High >= LeftEyeLength * LeftEyeDepth) and
if NoseBodyInsideLeftEyeBody then ((Max(Open, Close) <= Max(Open[1], Close[1]))
&& (Min(Open, Close) >= Min(Open[1], Close[1]))) else 1
then yes
else no;
#defining the bullish / bearish signals
def bullish_signal = BullSignalup;
def bearish_signal = BearSignalDown;
#plotting the bullish / bearish signals
plot bullish = bullish_signal;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot bearish = bearish_signal;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Shareable Link
https://tos.mx/l2rtkPSimilar to the Engulfing candles with RSI, we added the overbought input to bearish and oversold input to bullish Pin Bar candles. That means a Pin Bar candle will only be generated when a stock is oversold or overbought according to the default RSI indicator. You can also set each value to your liking.
Hopefully that will help to reduce false signals.
Pin Bars with RSI
Rich (BB code):
input length = 14;
input over_Bought = 75;
input over_Sold = 25;
input price = close;
input averageType = AverageType.WEIGHTED;
input LastBars = 0;
input MaxNoseBodySize = 0.33; #(default = 0.33) — maximum allowed body/length ratio for the Nose bar.
input NoseBodyPosition = 0.4; #(default = 0.4) — Nose body should be position in top (bottom for bearish pattern) part of the Nose bar.
input LeftEyeOppositeDirection = yes; #(default = true) — tells the indicator that the Left Eye bar should be bearish for bullish Pinbar, and bullish for bearish Pinbar.
input NoseSameDirection = yes; #(default = true) — tells the indicator that the Nose bar should be of the same direction as the pattern itself.
input NoseBodyInsideLeftEyeBody = no; #(default = false) — tells the indicator that the Nose body should be inside the Left Eye body.
input LeftEyeMinBodySize = 0.1; #(default = 0.1) — minimum size of the Left Eye body relative to the bar length.
input NoseProtruding = 0.5; #(default = 0.5) — minimum protrusion of the Nose bar relative to the bar length.
input NoseBodyToLeftEyeBody = 1; #(default = 1) — maximum size of the Nose body relative to the Left eye body.
input NoseLengthToLeftEyeLength = 0; #(default = 0) — minimum Nose length relative to the Left Eye length.
input LeftEyeDepth = 0.2; #(default = 0.2) — minimum depth of the Left Eye relative to its length. Depth is length of the part of the bar behind the Nose.
# Left Eye and Nose bars's paramaters
def NoseLength = High - Low;
def LeftEyeLength = High[1] - Low[1];
def NoseBody = Absvalue(Open - Close);
def LeftEyeBody = Absvalue(Open[1] - Close[1]);
# Bearish Pinbar
def BearSignalDown = if (High - High[1] >= NoseLength * NoseProtruding) and
(NoseBody / NoseLength <= MaxNoseBodySize) and
(1 - (High - Max(Open, Close)) / NoseLength < NoseBodyPosition) and
if LeftEyeOppositeDirection then (Close[1] > Open[1]) else 1 and
if NoseSameDirection then (Close < Open) else 1 and
(LeftEyeBody / LeftEyeLength >= LeftEyeMinBodySize) and
((Max(Open, Close) <= High[1]) && (Min(Open, Close) >= Low[1])) and
(NoseBody / LeftEyeBody <= NoseBodyToLeftEyeBody) and
(NoseLength / LeftEyeLength >= NoseLengthToLeftEyeLength) and
(Low - Low[1] >= LeftEyeLength * LeftEyeDepth) and
if NoseBodyInsideLeftEyeBody then ((Max(Open, Close) <= Max(Open[1], Close[1]))
&& (Min(Open, Close) >= Min(Open[1], Close[1]))) else 1
then yes
else no ;
def BullSignalUp = if (Low[1] - Low >= NoseLength * NoseProtruding) and
(NoseBody / NoseLength <= MaxNoseBodySize) and
(1 - (Min(Open, Close) - Low) / NoseLength < NoseBodyPosition) and
if LeftEyeOppositeDirection then (Close[1] < Open[1]) else 1 and
if NoseSameDirection then (Close > Open) else 1 and
(LeftEyeBody / LeftEyeLength >= LeftEyeMinBodySize) and
((Max(Open, Close) <= High[1]) && (Min(Open, Close) >= Low[1])) and
(NoseBody / LeftEyeBody <= NoseBodyToLeftEyeBody) and
(NoseLength / LeftEyeLength >= NoseLengthToLeftEyeLength) and
(High[1] - High >= LeftEyeLength * LeftEyeDepth) and
if NoseBodyInsideLeftEyeBody then ((Max(Open, Close) <= Max(Open[1], Close[1]))
&& (Min(Open, Close) >= Min(Open[1], Close[1]))) else 1
then yes
else no;
#defining the bullish / bearish signals
def bullish_signal = RSI(length = length, averageType = averageType) < over_Sold and BullSignalup;
def bearish_signal = RSI(length = length, averageType = averageType) > over_Bought and BearSignalDown;
#plotting the bullish / bearish signals
plot bullish = bullish_signal;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot bearish = bearish_signal;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
P.S: I found the original code without any header on it so I can't give credit to the developer. If you know who created it please let me know.
Attachments
Last edited by a moderator: