Pattern_v1
Download scriptThis tool is designed to automatically scan and identify specific Japanese candlestick patterns directly on your trading chart. Instead of requiring you to manually analyze every price movement, the script monitors historical and current price data to detect "signal" candles that often indicate a shift in market sentiment or a potential price reversal.
How the Logic Works
The script processes each candle by looking at its individual characteristics—such as its size (the range between the high and low), its body (the difference between the open and close), and how it relates to the candles immediately preceding it.
It evaluates these prices against a set of predefined mathematical rules to categorize the price action into specific recognized trading patterns, including:
- Reversal Signals: It identifies shapes like "Hammers," "Shooting Stars," and "Engulfing" candles, which suggest that buying or selling pressure is shifting.
- Continuation & Strength: It looks for patterns like "Marubozu" (full-bodied candles showing strong momentum) and "Three White Soldiers."
- Indecision Patterns: It detects "Dojis," where the opening and closing prices are nearly identical, signaling a pause in the market.
- Complex Formations: The logic is sophisticated enough to recognize multi-candle sequences, such as "Harami" (inside bars) and "Piercing" patterns, by comparing the relative positions of several consecutive candles at once.
Visual Output
When the script identifies a pattern that matches its internal criteria, it automatically places a text label directly on your chart. These labels appear in Yellow and are positioned above the specific candle where the pattern occurred. This allows you to quickly scroll through historical data or watch the live market to see where these significant price behaviors have surfaced without having to perform the manual calculations yourself.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
#property copyright "VMesquita"
#property indicator_chart_window // an indicator is drawn in the main chart window
#property indicator_buffers 1
int limit;
int init ()
{
//----
return(0);
}
int deinit()
{
return(0);
}
int start()
{
double O,C,H,L,O1,C1,H1,L1,O2,C2,H2,L2;
string text;
int counted_bars=IndicatorCounted();
limit=Bars-counted_bars;
//---- check for possible errors
if(counted_bars<0) {
Alert("No Bars..");
return(-1);
}
//---- last counted bar will be recounted
for(int i=1; i<limit; i++) {
O=iOpen(NULL,0,i);
C=iClose(NULL,0,i);
H=iHigh(NULL,0,i);
L=iLow(NULL,0,i);
O1=iOpen(NULL,0,i-1);
C1=iClose(NULL,0,i-1);
H1=iHigh(NULL,0,i-1);
L1=iLow(NULL,0,i-1);
O2=iOpen(NULL,0,i+1);
C2=iClose(NULL,0,i+1);
H2=iHigh(NULL,0,i+1);
L2=iLow(NULL,0,i+1);
text="";
if(((H-L)>4*(O-C))&&((C-L)/(0.001+H-L)>=0.75)&&((O-L)/
(0.001+H-L)>=0.75)) text="Hang";
if(((H-L)>3*(O-C))&&((C-L)/(0.001+H-L)>0.6)&&((O-L)/
(0.001+H-L)>0.6)) text="Hammer";
if(((H-L)>3*(O-C))&&((H-C)/(0.001+H-L)>0.6)&&((H-O)/
(0.001+H-L)>0.6)) text="IHammer";
if((O2>C2)&&((O2-C2)/(0.001+H2-L2)>0.6)&&(C2>O1)&&(O1>C1)&&
((H1-L1)>(3*(C1-O1)))&&(C>O)&&(O>O1)) text="MStar";
if((O>C)&&(H==O)&&(C==L)) text="LMarubozu";
if((C>O)&&(H==C)&&(O==L)) text="HMarubozu";
if((C1==O1)&&(C2>O2)&&(O>C)&&(L1>H2)&&(L1>H)) text="ABaby";
if((C1==O1)&&(O2>C2)&&(C>O)&&(L2>H1)&&(L>H1)) text="ABaby";
if((C2>O2)&&((C2-O2)/(0.001+H2-L2)>0.6)&&(C2<O1)&&(C1>O1)&&
((H1-L1)>(3*(C1-O1)))&&(O>C)&&(O<O1)) text="EStar";
if((C1>O1)&&(((C1+O1)/2)>C)&&(O>C)&&(O>C1)&&(C>O1)&&((O-C)/
(0.001+(H-L))>0.6)) text="DCloud";
if((C1>O1)&&(O>C)&&(O>=C1)&&(O1>=C)&&((O-C)>(C1-O1)))
text="Engulf";
if((O1>C1)&&(C>O)&&(C>=O1)&&(C1>=O)&&((C-O)>(O1-C1)))
text="Engulf";
if((O1>C1)&&(C>O)&&(C<=O1)&&(C1<=O)&&((C-O)<(O1-C1)))
text="Harami";
if((C1>O1)&&(O>C)&&(O<=C1)&&(O1<=C)&&((O-C)<(C1-O1)))
text="Harami";
if((C1<O1)&&(((O1+C1)/2)<C)&&(O<C)&&(O<C1)&&(C<O1)&&((C-O)/
(.001+(H-L))>0.6)) text="Piercing";
if((C>O*1.01)&&(C1>O1*1.01) &&(C2>O2*1.01) &&(C>C1) &&
(C1>C2) &&(O<C1&&O>O1) &&(O1<C2&&O1>O2) &&(((H-C)/(H-L))<0.2) &&(((H1-
C1)/(H1-L1))<0.2)&&(((H2-C2)/(H2-L2))<0.2)) text="Three White Soldiers";
if(((H-L)>4*(O-C))&&((H-C)/(0.001+H-L)>= 0.75)&&((H-O)/
(0.001+H-L)>=0.75)) text="SStar";
if(C==O) text="Doji";
//If we found a special candlem write in the Chart
if(text!="")
{
ObjectCreate(DoubleToStr(i,0)+" label", OBJ_TEXT, 0, Time
[i], H);
ObjectSetText(DoubleToStr(i,0)+" label", text, 10, "Arial",
Yellow);
}
}
}
Comments