Pattern_Hammer_Shooting Star1
Download scriptThis script is an automated technical analysis tool designed to identify specific candlestick patterns—namely Shooting Stars and Hammers—on a trading chart. It functions as a visual assistant that scans historical and real-time price data to highlight potential trend reversals for the user.
Core Functionality
The logic operates by constantly monitoring the "shape" of price candles. It looks for specific proportions between the candle's body (where the price stayed for most of the duration) and its "wicks" (the thin lines indicating the highest and lowest prices reached).
1. Pattern Recognition Logic
The script categorizes patterns into two main types:
- Bearish Patterns (Shooting Stars): The script identifies these when the price makes a significant upward push but fails to sustain it, resulting in a long upper wick and a small body at the bottom of the candle's range. It specifically checks if the high of the current candle is greater than the previous several candles to ensure the move has enough "momentum" to be considered significant.
- Bullish Patterns (Hammers): Conversely, the script looks for hammers during downward movements. These are identified by a long lower wick and a small body at the top, suggesting that while the price dropped significantly, buyers stepped in to push it back up before the candle closed.
2. Mathematical Validation
To avoid "false positives" (signals that look like patterns but aren't significant), the script applies several filters:
- Relative Proportions: It calculates the ratio between the upper and lower wicks. For example, it ensures the upper wick is at least twice, three, or four times larger than the body/lower wick, depending on the specific variation of the pattern.
- Average Range Comparison: It takes into account the volatility of the recent market by calculating an average price range over the last 10 candles.
- Minimum Size: It ensures the candle meets a minimum length requirement so that tiny, insignificant price flickers aren't flagged as major patterns.
Visual and Audible Feedback
When the script successfully identifies one of these patterns, it performs three actions:
- On-Chart Labeling: It places a text label directly on the chart (e.g., "SS 2" for Shooting Star or "HMR 3" for Hammer) so the user can see exactly where the pattern occurred in history.
- Visual Arrows: It draws directional arrows (Up or Down) to provide an immediate visual cue of the identified trend change.
- Real-Time Alerts: If enabled, the script will trigger a pop-up alert on the trading platform the moment a new pattern is detected on the current live candle. These alerts also include information about the specific timeframe (e.g., M15, H1, Daily) to give the user context.
Summary for the User
Essentially, this tool acts as an automated "scout." It sifts through the noise of price movements to find high-probability candlestick shapes that traditionally signal a change in market direction, marking them clearly on your screen and notifying you instantly when they appear.
//+------------------------------------------------------------------+
//| 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