Pattern Alert_v1
Download scriptThis script is a specialized technical analysis tool designed to automatically identify and highlight specific candlestick patterns on a trading chart. Instead of requiring you to manually scan every candle for potential price reversals, the software scans the historical data and live price action to detect these formations in real-time.
Core Functionality
The primary purpose of this script is to simplify technical analysis by "labeling" the chart. When it recognizes a specific pattern based on the relationship between previous candles (such as their opening, closing, high, and low prices), it performs three actions:
- Visual Labeling: It places a text label directly on the chart (e.g., "Bullish Engulfing") so you can see exactly what happened at that moment.
- Graphic Indicators: It places arrows on the chart to provide a clear visual cue of where a pattern was detected.
- Instant Alerts: When a new pattern completes on the most recent live candle, the script triggers an audible and visual alert, notifying you immediately so you can react without constantly staring at the screen.
Patterns Detected
The logic is programmed to look for several classic candlestick configurations:
- Engulfing Patterns: It identifies "Bullish Engulfing" and "Bearish Engulfing" setups, where a large candle completely overlaps the previous one, suggesting a strong shift in momentum.
- Dark Cloud Cover: A specific bearish reversal pattern that indicates selling pressure is beginning to outweigh buying pressure.
- Star Patterns: It tracks four distinct multi-candle sequences:
- Morning Star & Bullish Engulfing: Often seen as signals of a potential upward move.
- Evening Star & Bearish Engulfing: Often seen as signals of a potential downward move.
- Doji Stars: Specific patterns involving "Doji" candles (where open and close prices are nearly equal) used to identify indecision before a reversal.
- Tweezer Patterns: The script looks for "Tweezer Tops" and "Tweezer Bottoms," which occur when two consecutive candles have nearly identical highs or lows, often signaling that the price is hitting a significant ceiling or floor.
User Customization & Dynamics
The script includes several built-in features to improve the user experience:
- Toggleable Visibility: You can choose to turn specific patterns on or off in the settings (e.g., you can hide "Star Patterns" if you only want to see "Engulfing Patterns").
- Dynamic Spacing: The script automatically adjusts the position of the labels and arrows based on the timeframe you are viewing (e.g., it places labels differently on a 1-minute chart versus a Daily chart) to ensure the text remains readable and does not overlap with the price candles.
- Real-Time Monitoring: It is designed to run continuously, checking every new tick of data to ensure that as soon as a candle closes and confirms a pattern, you are notified.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| Pattern Alert v1.1 (Official) |
//| |
//| You may improve and add to this code but please send it back to |
//| me for an official release. Thanks. |
//| |
//| Copyright © 2005, Jason Robinson |
//| (jasonrobinsonuk, jnrtrading) |
//| http://www.jnrtrading.co.uk |
//| |
//| **THE ONLY OFFICIAL VERSION IS FROM MY WEBSITE** |
//| (unless it has been posted by me on a forum) |
//| |
//|Obviously this is still work in progress and needs LOTS of testing|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
extern bool Show_Text_Labels = true;
extern bool Show_Bearish_Engulfing_Patterns = true;
extern bool Show_Bullish_Engulfing_Patterns = true;
extern bool Show_Star_Patterns = true;
extern bool Show_Tweezer_Bottoms = true;
extern bool Show_Tweezer_Tops = true;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
string PatternText[2000];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
//---- indicators
for (int i = 0; i < Bars; i++) { // Clear buffer
//ExtMapBuffer1[i] = 0;
//ExtMapBuffer2[i] = 0;
}
for (int j = 0; j < Bars; j++) {
PatternText[j] = CharToStr(j);
}
SetIndexStyle(0,DRAW_ARROW, EMPTY);
SetIndexArrow(0,242);
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexStyle(1,DRAW_ARROW, EMPTY);
SetIndexArrow(1,241);
SetIndexBuffer(1, ExtMapBuffer2);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
ObjectsDeleteAll(0, OBJ_TEXT);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start(){
Comment("Pattern Alert v1.1 Official");
static datetime prevtime = 0;
int shift;
int shift1;
int shift2;
int shift3;
string pattern;
int setPattern = 0;
int alert = 0;
int arrowShift;
int textShift;
if(prevtime == Time[0]) {
return(0);
}
prevtime = Time[0];
// Code to determine a good place to put the text and arrow
switch (Period()) {
case 1:
arrowShift = 1;
textShift = 3;
break;
case 5:
arrowShift = 3;
textShift = 8;
break;
case 30:
arrowShift = 7;
textShift = 13;
break;
case 15:
arrowShift = 7;
textShift = 15;
break;
case 60:
arrowShift = 9;
textShift = 25;
break;
case 1440:
arrowShift = 3;
textShift = 7;
break;
case 10080:
arrowShift = 95;
textShift = 235;
break;
case 43200:
arrowShift = 150;
textShift = 260;
break;
}
for (int j = 0; j < Bars; j++) {
PatternText[j] = j;
}
for (shift = 0; shift < Bars; shift++) {
shift1 = shift + 1;
shift2 = shift + 2;
shift3 = shift + 3;
// Check for a Bearish Engulfing pattern
if (Show_Bearish_Engulfing_Patterns == true) {
if ((Close[shift2] > Open[shift2]) && (Open[shift1] > Close[shift2]) && (Close[shift1] < Open[shift2])) {
if (Show_Text_Labels) {
ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + (Point * textShift));
ObjectSetText(PatternText[shift], "Bearish Engulfing", 9, "Times New Roman", Red);
}
ExtMapBuffer1[shift1] = High[shift1] + (Point * arrowShift);
if (setPattern == 0) {
pattern="Bearish Engulfing Pattern";
setPattern = 1;
alert = 1;
}
continue;
}
}
// Check for a Bullish Engulfing pattern
if (Show_Bullish_Engulfing_Patterns == true) {
if ((Close[shift2] < Open[shift2]) && (Open[shift1] < Close[shift2]) && (Close[shift1] > Open[shift2])) {
if (Show_Text_Labels == true) {
ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + (Point * textShift));
ObjectSetText(PatternText[shift], "Bullish Engulfing", 9, "Times New Roman", Red);
}
ExtMapBuffer1[shift1] = High[shift1] + (Point * arrowShift);
if (setPattern == 0) {
pattern="Bullish Engulfing Pattern";
setPattern = 1;
alert = 1;
}
continue;
}
}
// Check for a Dark Cloud Cover pattern
if ((Close[2] > Open[2]) && (Open[1] > High[2]) && (Close[1] < ((Open[2] + Close[2]) / 2)) && (Close[1] > Open[2])) {
if (Show_Text_Labels == true) {
ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + (Point * textShift));
ObjectSetText(PatternText[shift], "Dark Cloud Cover", 9, "Times New Roman", Red);
}
ExtMapBuffer1[shift1] = High[shift1] + (Point * arrowShift);
if (setPattern == 0) {
pattern="Dark Cloud Cover";
setPattern = 1;
alert = 1;
}
continue;
}
if (Show_Star_Patterns == true) {
// Check for Evening Doji Star pattern
if (
(Close[3] > Open[3]) //Bullish candle
&& (Open[2] == Close[2]) && (Low[2] < Open[2]) && (High[2] > Open[2]) // Doji
&& (Low[2] >= Close[3]) // Doji close higher or equal to Bullish close
&& (High[1] <= Close[2]) && (Open[1] <= Low[2]) && (Open[1] >= Close[3]) &&
(Close[1] < ((Open[3] + Close[3]) / 2)) && (Close[1] > Open[3]) // Bearish candle in pattern
) {
if (Show_Text_Labels == true) {
ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + (Point * textShift));
ObjectSetText(PatternText[shift], "Evening Doji Star", 9, "Times New Roman", Red);
}
ExtMapBuffer1[shift1] = High[shift1] + (Point * arrowShift);
if (setPattern == 0) {
pattern = "Evening Doji Star";
setPattern = 1;
alert = 1;
}
continue;
}
// Check for Morning Doji Star pattern
if (
(Close[3] < Open[3]) //Bearish candle
&& (Open[2] == Close[2]) && (Low[2] < Open[2]) && (High[2] > Open[2]) // Doji
&& (High[2] <= Close[3]) // Doji close lower or equal to bearish close
&& (Low[1] >= Close[2]) && (Open[1] >= High[2]) && (Open[1] <= Close[3]) &&
(Close[1] > ((Open[3] + Close[3]) / 2)) && (Close[1] < Open[3]) // Bullish candle in pattern
) {
if (Show_Text_Labels == true) {
ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + (Point * textShift));
ObjectSetText(PatternText[shift], "Morning Doji Star", 9, "Times New Roman", Red);
}
ExtMapBuffer1[shift1] = High[shift1] + (Point * arrowShift);
if (setPattern == 0) {
pattern = "Morning Doji Star";
setPattern = 1;
alert = 1;
}
continue;
}
// Check for Evening Star pattern
if(
(Close[3] > Open[3]) //Bullish candle
&& (Open[2] > Close[2]) && (Low[2] < Open[2]) && (High[2] > Open[2]) // Second, small candle
&& (Low[2] > Close[3]) // small candle gaps up.
&& (High[1] < Close[2]) && (Open[1] <= Low[2]) && (Open[1] > Close[3]) &&
(Close[1] < ((Open[3] + Close[3]) / 2)) && (Close[1] > Open[3]) // Bearish candle in pattern
) {
if (Show_Text_Labels == true) {
ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + (Point * textShift));
ObjectSetText(PatternText[shift], "Evening Star", 9, "Times New Roman", Red);
}
ExtMapBuffer1[shift1] = High[shift1] + (Point * arrowShift);
if (setPattern == 0) {
pattern = "Evening Star";
setPattern = 1;
alert = 1;
}
continue;
}
// Check for Morning Star pattern
if (
(Close[3] < Open[3]) //Bearish candle
&& (Open[2] < Close[2]) && (Low[2] < Open[2]) && (High[2] > Open[2]) // Second, small candle
&& (High[2] < Close[3]) // Small candle gaps down
&& (Low[1] > Close[2]) && (Open[1] >= High[2]) && (Open[1] < Close[3]) &&
(Close[1] > ((Open[3] + Close[3]) / 2)) && (Close[1] < Open[3]) // Bullish candle in pattern
) {
if (Show_Text_Labels == true) {
ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + (Point * textShift));
ObjectSetText(PatternText[shift], "Morning Star", 9, "Times New Roman", Red);
}
ExtMapBuffer1[shift1] = High[shift1] + (Point * arrowShift);
if (setPattern == 0) {
pattern = "Morning Star";
setPattern = 1;
alert = 1;
}
continue;
}
} // End of Show_Star_Patterns condition
// Check for Tweezer Top
if (Show_Tweezer_Tops == true) {
if ((High[shift1] == High[shift2])) {
if (Show_Text_Labels == true) {
ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + (Point * textShift));
ObjectSetText(PatternText[shift], "Tweezer Top", 9, "Times New Roman", Red);
}
ExtMapBuffer1[shift1] = High[shift1] + (Point * arrowShift);
if (setPattern == 0) {
pattern = "Tweezer Top";
setPattern = 1;
alert = 1;
}
continue;
}
}
// Check for Tweezer Bottom
if (Show_Tweezer_Bottoms == true) {
if ((Low[shift1] == Low[shift2]))
{
if (Show_Text_Labels == true) {
ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] - (Point * textShift));
ObjectSetText(PatternText[shift], "Tweezer Bottom", 9, "Times New Roman", Red);
}
ExtMapBuffer2[shift1] = High[shift1] - (Point * (arrowShift + 7));
if (setPattern == 0) {
pattern = "Tweezer Bottom";
setPattern = 1;
alert = 1;
}
continue;
}
}
if (shift == 1 && alert == 1) {
Print(Symbol()," M", Period()," ", pattern);
Alert(Symbol()," M", Period()," ", pattern);
}
} // End of for loop
return(0);
}
//+------------------------------------------------------------------+
Comments