Bheurekso_pattern

Author: ��������� �.�.
Bheurekso_pattern

This script is designed to automatically identify and highlight certain candlestick patterns on a trading chart. Candlestick patterns are visual formations on a price chart that traders use to predict future price movements. The script scans the recent price history (the "bars") and looks for specific combinations of price movements that match these patterns.

Here's a breakdown:

  1. Initialization: When the script starts, it sets up two visual "buffers" that will be used to draw arrows on the chart. It also allows the user to choose whether to display the name of the pattern or not.

  2. Pattern Recognition: The script then goes through each bar of the chart, comparing the opening and closing prices to identify the following candlestick patterns:

    • Bullish Patterns (indicating a potential price increase):
      • Bullish Engulfing: A smaller bearish (downward) candle is followed by a larger bullish (upward) candle that completely "engulfs" the previous one.
      • Bullish Piercing: Similar to Engulfing, but the second bullish candle doesn't completely engulf the first bearish candle.
      • Morning Star: A three-candle pattern indicating a potential reversal from a downtrend.
      • Hammer: A single candle pattern with a small body and a long lower shadow, indicating potential buying pressure.
    • Bearish Patterns (indicating a potential price decrease):
      • Bearish Engulfing: A smaller bullish (upward) candle is followed by a larger bearish (downward) candle that completely "engulfs" the previous one.
      • Dark Cloud Cover: Similar to Engulfing, but the second bearish candle doesn't completely engulf the first bullish candle.
      • Evening Star: A three-candle pattern indicating a potential reversal from an uptrend.
      • Shooting Star: A single candle pattern with a small body and a long upper shadow, indicating potential selling pressure.
  3. Visual Alerts: If a pattern is found, the script can display two optional visual aids on the chart:

    • An arrow pointing up (for bullish patterns) or down (for bearish patterns) near the identified pattern.
    • A text label indicating the name of the identified pattern.
  4. Drawing the output: The script uses graphic objects to draw in the main chart

  5. Data Storage: Finally, the script stores the high or low price, depending on the pattern to be latter printed into the chart.

In essence, this script automates the process of identifying candlestick patterns on a chart, providing traders with visual cues to potential trading opportunities.

Miscellaneous
Implements a curve of type %1
6 Views
0 Downloads
0 Favorites
Bheurekso_pattern
//+------------------------------------------------------------------+
//|                                            Bheurekso_pattern.mq4 |
//|                                                   Êðèâîøåèí Å.Â. |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Êðèâîøåèí Å.Â."
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
//---- input parameters
extern bool       Arrow=true;
extern bool       Name=true;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,108);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,108);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
//----
	ObjectsDeleteAll(0,OBJ_TEXT);
	ObjectsDeleteAll(0,OBJ_ARROW);
	//DelArrow(0,0); 
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }

//+------------------------------------------------------------------+
//SetArrow(t[shift1],l[shift1]-15*Point,241,LIME);
void SetArrow(int sh, datetime tm, double pr, int cod,color clr)
{
	ObjectCreate("Arrow-"+cod+"-"+sh,OBJ_ARROW,0,tm,pr);
	ObjectSet("Arrow-"+cod+"-"+sh,OBJPROP_ARROWCODE,cod);
	ObjectSet("Arrow-"+cod+"-"+sh,OBJPROP_COLOR,clr);
}
//SetText(t[shift1],l[shift1]-28*Point,"Engulfing",LIME);
void SetText(int sh,datetime tm,double pr,string text,color clr)
{
	ObjectCreate(text+"-"+sh,OBJ_TEXT,0,tm,pr);
	ObjectSetText(text+"-"+sh,text);
	ObjectSet(text+"-"+sh,OBJPROP_COLOR,clr);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
	int    counted_bars=IndicatorCounted();
//---- 
	int myBars=0, StartBar=0;//, Kedip(false);
	int shift=0, shift1=0, shift2=0, shift3=0;
	bool BullEngulf=False, MorningStar=False, BullPierce=False, Hammer=False;
	bool BearEngulf=False, EveningStar=False, DarkCloud=False, Shooter=False;
	bool Harami=False;
	int limit;
   
	if(myBars!=Bars) 
	{ 
		myBars=Bars; 
	}
   limit=Bars-counted_bars;
	for(shift=limit;shift>=0;shift--) 
	{
		// Manjakan MT
		shift1=shift+1;
		shift2=shift+2;
		shift3=shift+3;

		//*** periksa pola bullish***
		//***************************
		
		//--- Bullish Engulfing (2 bars)
		if((Close[shift2]<Open[shift2]) && (Open[shift1]<Close[shift2]) && //| l[shift1] < l[shift2]) & 
				(Close[shift1]>Open[shift2])) 
			BullEngulf=True;
		else 
			BullEngulf=False;
		
		//--- Bullish Piercing (2 bars) cuma cari kalo ga ada BullEngulf
		if(!BullEngulf)
		{
			if((Close[shift2]<Open[shift2]) && (Close[shift1]>Open[shift1]) && 
					((Open[shift1]<Close[shift2]) || (Low[shift1]<Low[shift2])) && 
					(Close[shift1]>Close[shift2]+((Open[shift2]-Close[shift2])/2))) 
				BullPierce=True;
			else 
				BullPierce=False;
		}
		else 
		{
			BullPierce=False;
		}
		
		// Morning Star (3 bars)
		if((Close[shift3]<Open[shift3]) && (Open[shift2]<Close[shift3]) && (Close[shift2]<Close[shift3]) &&
				((Open[shift1]>Close[shift2]) || (High[shift1]>High[shift2])) && (Close[shift1]>=Close[shift3]))
			MorningStar=True;
		else
			MorningStar=False;
		
		// Hammer
		if((Close[shift1]>Open[shift1]) && 
				(Open[shift1]-Low[shift1]>MathMax(High[shift1]-Close[shift1],Close[shift1]-Open[shift1])*3))
			Hammer=True;
		else 
			Hammer=False;
		
		//*** periksa pola bearish***
		//***************************
		
		//--- Bearish Engulfing (2 bars)
		if((Close[shift2]>Open[shift2]) && (Close[shift1]<Open[shift1]) && (Open[shift1]>Close[shift2]) &&
				((Close[shift1]<Open[shift2]) || (Low[shift1]<Low[shift2])))
			BearEngulf=True;
		else
			BearEngulf=False;
		
		//--- Bearish Dark Cloud (2 bars) cuma cari kalo ga ada BearEngulf
		if(!BearEngulf)
		{
			if((Close[shift2]>Open[shift2]) && ((Open[shift1]>Close[shift2]) || (High[shift1]>High[shift2])) &&
					(Close[shift1]<Close[shift2]-((Close[shift2]-Open[shift2])/2)))
				DarkCloud=True;
			else 
				DarkCloud=False;
		}
		else 
		{
			DarkCloud=False;
		}
		
		// Evening Star (3 bars)
		if((Close[shift3]>Open[shift3]) && (Open[shift2]>Close[shift3]) && (Close[shift2]>Close[shift3]) && 
				((Open[shift1]<Close[shift2]) || (Low[shift1]<Low[shift2])) && (Close[shift1]<Close[shift3]))
			EveningStar=True;
		else 
			EveningStar=False;
		
		// Shooting Star 
		if((Close[shift1]<Open[shift1]) && (High[shift1]-Open[shift1]>MathMax(Close[shift1]-Low[shift1],Open[shift1]-Close[shift1])*3)) 
			Shooter=True;
		else
			Shooter=False;
		
		// Kasih keterangan dan panah Bullish di chart
		if(BullEngulf)
		{
			if(Name)
				SetText(shift,Time[shift1],Low[shift1]-28*Point,"Engulfing",Lime);
			if(Arrow)
				SetArrow(shift1,Time[shift1],Low[shift1]-20*Point,241,Lime);
		}
		else 
		{
			if(BullPierce)
			{
				if(Name)
					SetText(shift1,Time[shift1],Low[shift1]-23*Point,"Piercing",White);
				if(Arrow)
					SetArrow(shift1,Time[shift1],Low[shift1]-15*Point,241,Lime);
			}
		}
		
		if(MorningStar)
		{
			if(Name)
				SetText(shift2,Time[shift2],Low[shift2]-18*Point,"Morning Star",Magenta);
			if(Arrow)
				SetArrow(shift2,Time[shift2],Low[shift2]-10*Point,241,Lime);
		}
		

		if(Hammer)
		{
			if(Name)
				SetText(shift1,Time[shift1],Low[shift1]-13*Point,"Hammer",Lime);
			if(Arrow)
				SetArrow(shift1,Time[shift1],Low[shift1]-5*Point,241,Lime);
		}
		
		// Kasih keterangan dan panah Bearish di chart
		if(BearEngulf)
		{
			if(Name)
				SetText(shift1,Time[shift1],High[shift1]+28*Point,"Engulfing",OrangeRed);
			if(Arrow)
				SetArrow(shift1,Time[shift1],High[shift1]+20*Point,242,OrangeRed);
		}
		else 
		{
			if(DarkCloud)
			{
				if(Name)
					SetText(shift1,Time[shift1],High[shift1]+23*Point,"Dark Cloud",White);
				if(Arrow)
					SetArrow(shift1,Time[shift1],High[shift1]+15*Point,242,OrangeRed);
			}
		}
		
		if(EveningStar)
		{
			if(Name)
				SetText(shift2,Time[shift2],High[shift2]+18*Point,"Evening Star",Magenta);
			if(Arrow)
				SetArrow(shift2,Time[shift2],High[shift2]+10*Point,242,OrangeRed);
		}
		
		if(Shooter)
		{
			if(Name)
				SetText(shift1,Time[shift1],High[shift1]+13*Point,"Shooting",OrangeRed);
			if(Arrow)
				SetArrow(shift1,Time[shift1],High[shift1]+5*Point,242,OrangeRed);
		}
		

		// Tampilkan disaat ada konfirmasi.


		if( (BullEngulf || BullPierce || MorningStar || Hammer) && 
				(Close[shift]>Open[shift]))
			ExtMapBuffer1[shift] = Low[shift]-7*Point;
		else 
			ExtMapBuffer1[shift] = 0.0;

		if( (BearEngulf || DarkCloud || EveningStar || Shooter) && 
				(Close[shift]<Open[shift]))
			ExtMapBuffer2[shift] = High[shift]+7*Point;
		else 
			ExtMapBuffer2[shift] = 0.0;

		StartBar-=1;
	}
	
	
	
	
//----
   return(0);
}
//+------------------------------------------------------------------+

Comments