Pattern_Hammer_Shooting_Star
Download scriptThis script is designed as an automated visual tool for traders to identify specific candlestick patterns—specifically Shooting Stars and Hammers—directly on their trading charts. By scanning historical price action, it highlights potential trend reversals or continuations using on-screen labels and arrows.
How the Logic Works
The script constantly monitors the price movement and analyzes the "geometry" of candles to determine if they meet specific structural criteria. Here is a breakdown of its core logic:
1. Contextual Awareness The tool doesn't just look at a single candle in isolation. It evaluates the current candle in relation to the preceding ones. It calculates the average range of recent price bars to ensure that the patterns it identifies are significant relative to the recent market volatility.
2. Pattern Identification Criteria The script looks for two specific types of candlestick formations:
- Shooting Stars (Bearish Signals): The logic searches for candles where the "upper wick" (the line sticking out above the body) is significantly longer than the "lower wick" and the body itself. Specifically, it looks for candles where the high point is higher than previous candles, and the upper wick is at least twice, three, or four times larger than the body's height (depending on the specific variation). This suggests that buyers pushed the price up aggressively but were ultimately rejected.
- Hammers (Bullish Signals): Conversely, the script looks for candles with a long lower wick and a small upper wick. It identifies these by checking if the current candle's low is lower than several previous candles. If the lower wick is significantly larger than the body and the upper wick, it marks it as a Hammer. This suggests that sellers pushed the price down but were met with strong buying interest.
3. Visual Feedback and Alerts Once the script identifies a valid pattern based on these mathematical rules:
- On-Chart Labeling: It places a text label (e.g., "SS" for Shooting Star or "HMR" for Hammer) and a colored arrow (Green for Bullish, Yellow/Orange for Bearish) directly on the chart.
- Dynamic Offsets: It uses specific "pointer offsets" to ensure these labels don't overlap with the actual price candles, keeping the chart clean and readable.
- Real-Time Notifications: If enabled in the settings, the script will trigger a pop-up alert on your trading platform the moment a new pattern is confirmed on the live candle. This allows traders to react quickly without having to watch the screen every second.
Summary for the User
Essentially, this script acts as an automated "pattern scout." It scans the price history and current action to find specific candle shapes that traditionally signal a change in momentum. When it finds one, it visually marks it on your chart and notifies you immediately, helping you identify potential entry or exit points more efficiently.
//+------------------------------------------------------------------+
//| Pattern Recognition v1.0 |
//| (complete rewrite and name change of pattern alert) |
//| |
//| Copyright © 2005, Jason Robinson |
//| (jasonrobinsonuk, jnrtrading) |
//| http://www.jnrtrading.co.uk |
//| |
//| This is still work in progress and needs LOTS of testing |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Jason Robinson (jnrtrading)."
#property link "http://www.jnrtrading.co.uk"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Yellow
extern bool Show_Alert = true;
extern int Pointer_Offset = 9;
extern int High_Offset = 10;
extern bool Display_ShootStar = true;
extern bool Show_ShootStar_Alert = true;
extern int Offset_ShootStar = 12;
extern color Color_ShootStar = Green;
extern int Text_ShootStar = 8;
extern bool Display_Hammer = true;
extern bool Show_Hammer_Alert = true;
extern int Offset_Hammer = 6;
extern color Color_Hammer = Green;
extern int Text_Hammer = 8;
extern double Candle_WickBody_Percent=0.90;
extern int CandleLength=12;
//---- buffers
double upArrow[];
double downArrow[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
//---- indicators
SetIndexStyle(0,DRAW_ARROW, EMPTY);
SetIndexArrow(0,72);
SetIndexBuffer(0, downArrow);
SetIndexStyle(1,DRAW_ARROW, EMPTY);
SetIndexArrow(1,71);
SetIndexBuffer(1, upArrow);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
ObjectsDeleteAll(0, OBJ_TEXT);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start(){
double Range, AvgRange;
int counter, setalert;
static datetime prevtime = 0;
int shift;
int shift1;
int shift2;
int shift3;
int shift4;
string pattern, period;
int setPattern = 0;
int alert = 0;
int arrowShift;
int textShift;
double O, O1, O2, C, C1, C2, C3, L, L1, L2, L3, H, H1, H2, H3;
double CL, CLmin, CL1, CL2, BL, BLa, BL90, BL1, BL2, UW, UWa, UW1, UW2, LW, LWa, LW1, LW2, BodyHigh, BodyLow;
BodyHigh = 0;
BodyLow = 0;
if(prevtime == Time[0]) {
return(0);
}
prevtime = Time[0];
switch (Period()) {
case 1:
period = "M1";
break;
case 5:
period = "M5";
break;
case 15:
period = "M15";
break;
case 30:
period = "M30";
break;
case 60:
period = "H1";
break;
case 240:
period = "H4";
break;
case 1440:
period = "D1";
break;
case 10080:
period = "W1";
break;
case 43200:
period = "MN";
break;
}
for (shift = 0; shift < Bars; shift++) {
setalert = 0;
counter=shift;
Range=0;
AvgRange=0;
for (counter=shift ;counter<=shift+9;counter++) {
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/10;
shift1 = shift + 1;
shift2 = shift + 2;
shift3 = shift + 3;
shift4 = shift + 4;
O = Open[shift1];
O1 = Open[shift2];
O2 = Open[shift3];
H = High[shift1];
H1 = High[shift2];
H2 = High[shift3];
H3 = High[shift4];
L = Low[shift1];
L1 = Low[shift2];
L2 = Low[shift3];
L3 = Low[shift4];
C = Close[shift1];
C1 = Close[shift2];
C2 = Close[shift3];
C3 = Close[shift4];
if (O>C) {
BodyHigh = O;
BodyLow = C; }
else {
BodyHigh = C;
BodyLow = O; }
CL = High[shift1]-Low[shift1];
CL1 = High[shift2]-Low[shift2];
CL2 = High[shift3]-Low[shift3];
BL = Open[shift1]-Close[shift1];
UW = High[shift1]-BodyHigh;
LW = BodyLow-Low[shift1];
BLa = MathAbs(BL);
BL90 = BLa*Candle_WickBody_Percent;
// Bearish Patterns
// Check for Bearish Shooting Star
if ((H>=H1)&&(H>H2)&&(H>H3)) {
if (((UW/2)>LW)&&(UW>(2*BL90))&&(CL>=(CandleLength*Point))&&(O!=C)/*&&(L>L1)&&(L>L2)*/) {
if (Display_ShootStar == true) {
ObjectCreate(GetName(shift), OBJ_TEXT, 0, Time[shift1], High[shift1] + (Pointer_Offset+Offset_ShootStar+High_Offset)*Point);
ObjectSetText(GetName(shift), "SS 2", Text_ShootStar, "Times New Roman", Color_ShootStar);
downArrow[shift1] = High[shift1] + (Pointer_Offset*Point);
}
}
if (Show_ShootStar_Alert) {
if (setalert == 0 && Show_Alert == true) {
pattern = "Shooting Star 2";
setalert = 1;
}
}
}
// Check for Bearish Shooting Star
if ((H>=H1)&&(H>H2)&&(H>H3)) {
if (((UW/3)>LW)&&(UW>(2*BL90))&&(CL>=(CandleLength*Point))&&(O!=C)/*&&(L>L1)&&(L>L2)*/) {
if (Display_ShootStar == true) {
ObjectCreate(GetName(shift), OBJ_TEXT, 0, Time[shift1], High[shift1] + (Pointer_Offset+Offset_ShootStar+High_Offset)*Point);
ObjectSetText(GetName(shift), "SS 3", Text_ShootStar, "Times New Roman", Color_ShootStar);
downArrow[shift1] = High[shift1] + (Pointer_Offset*Point);
}
}
if (Show_ShootStar_Alert) {
if (setalert == 0 && Show_Alert == true) {
pattern = "Shooting Star 3";
setalert = 1;
}
}
}
// Check for Bearish Shooting Star
if ((H>=H1)&&(H>H2)&&(H>H3)) {
if (((UW/4)>LW)&&(UW>(2*BL90))&&(CL>=(CandleLength*Point))&&(O!=C)/*&&(L>L1)&&(L>L2)*/) {
if (Display_ShootStar == true) {
ObjectCreate(GetName(shift), OBJ_TEXT, 0, Time[shift1], High[shift1] + (Pointer_Offset+Offset_ShootStar+High_Offset)*Point);
ObjectSetText(GetName(shift), "SS 4", Text_ShootStar, "Times New Roman", Color_ShootStar);
downArrow[shift1] = High[shift1] + (Pointer_Offset*Point);
}
}
if (Show_ShootStar_Alert) {
if (setalert == 0 && Show_Alert == true) {
pattern = "Shooting Star 4";
setalert = 1;
}
}
}
// End of Bearish Patterns
// Bullish Patterns
// Check for Bullish Hammer
if ((L<=L1)&&(L<L2)&&(L<L3)) {
if (((LW/2)>UW)&&(LW>BL90)&&(CL>=(CandleLength*Point))&&(O!=C)/*&&(H<H1)&&(H<H2)*/) {
if (Display_Hammer == true) {
ObjectCreate(GetName(shift), OBJ_TEXT, 0, Time[shift1], Low[shift1] - (Pointer_Offset+Offset_Hammer)*Point);
ObjectSetText(GetName(shift), "HMR 2", Text_Hammer, "Times New Roman", Color_Hammer);
upArrow[shift1] = Low[shift1] - (Pointer_Offset*Point);
}
}
if (Show_Hammer_Alert) {
if (setalert == 0 && Show_Alert == true) {
pattern = "Bullish Hammer 2";
setalert = 1;
}
}
}
// Check for Bullish Hammer
if ((L<=L1)&&(L<L2)&&(L<L3)) {
if (((LW/3)>UW)&&(LW>BL90)&&(CL>=(CandleLength*Point))&&(O!=C)/*&&(H<H1)&&(H<H2)*/) {
if (Display_Hammer == true) {
ObjectCreate(GetName(shift), OBJ_TEXT, 0, Time[shift1], Low[shift1] - (Pointer_Offset+Offset_Hammer)*Point);
ObjectSetText(GetName(shift), "HMR 3", Text_Hammer, "Times New Roman", Color_Hammer);
upArrow[shift1] = Low[shift1] - (Pointer_Offset*Point);
}
}
if (Show_Hammer_Alert) {
if (setalert == 0 && Show_Alert == true) {
pattern = "Bullish Hammer 3";
setalert = 1;
}
}
}
// Check for Bullish Hammer
if ((L<=L1)&&(L<L2)&&(L<L3)) {
if (((LW/4)>UW)&&(LW>BL90)&&(CL>=(CandleLength*Point))&&(O!=C)/*&&(H<H1)&&(H<H2)*/) {
if (Display_Hammer == true) {
ObjectCreate(GetName(shift), OBJ_TEXT, 0, Time[shift1], Low[shift1] - (Pointer_Offset+Offset_Hammer)*Point);
ObjectSetText(GetName(shift), "HMR 4", Text_Hammer, "Times New Roman", Color_Hammer);
upArrow[shift1] = Low[shift1] - (Pointer_Offset*Point);
}
}
if (Show_Hammer_Alert) {
if (setalert == 0 && Show_Alert == true) {
pattern = "Bullish Hammer 4";
setalert = 1;
}
}
}
// End of Bullish Patterns
if (setalert == 1 && shift == 0) {
Alert(Symbol(), " ", period, " ", pattern);
setalert = 0;
}
} // End of for loop
return(0);
}
//+------------------------------------------------------------------+
string GetName(int shift)
{
return(DoubleToStr(Time[shift],0));
}
Comments