This script is a specialized trading tool designed for the MetaTrader 4 platform. It automates the calculation of the Ichimoku Kinko Hyo (also known as the Ichimoku Cloud) indicator, which is a comprehensive technique used to analyze trend direction, momentum, and support/resistance levels simultaneously.
Beyond just drawing these technical lines on your chart, this script includes an automated notification system that alerts you in real-time when specific price actions occur.
Core Visual Components
The script calculates and displays five primary components of the Ichimoku system:
- Tenkan Sen (Conversion Line): A fast-moving average that tracks short-term momentum by identifying the midpoint between the highest highs and lowest lows over a set period.
- Kijun Sen (Base Line): A slower-moving average that identifies medium-term trends, acting as a primary stabilizer for price movement.
- Senkou Span A & B: These two components work together to create the "Kumo" or "Cloud." They represent projected support and resistance zones based on previous price action and current averages.
- Chinkou Span (Lagging Span): This shifts past closing prices onto the current chart to help identify historical momentum relative to current price levels.
Automated Alert Logic
The primary functionality of this script is its ability to monitor the relationship between these components and provide "Buy" or "Sell" signals through pop-up alerts. You can customize these notifications using three different modes:
1. Tenkan/Kijun Crosses (Mode 1) This tracks the "Golden Cross" and "Dead Cross" logic. The script monitors the intersection of the fast-moving Tenkan line and the slower Kijun line:
- Buy Signal: Triggered when the Tenkan line crosses above the Kijun line, suggesting an increase in upward momentum.
- Sell Signal: Triggered when the Tenkan line crosses below the Kijun line, suggesting a shift toward downward momentum.
2. Kijun/Price Crosses (Mode 2) This tracks the relationship between the price and the "Base Line" (Kijun Sen):
- Buy Signal: Triggered when the current market price moves above the Kijun line.
- Sell Signal: Triggered when the current market price moves below the Kijun line.
3. Combined Alerts (Mode 3) This mode activates both of the notification systems described above simultaneously, providing a comprehensive alert system for multiple types of trend shifts.
Key Features for the User
- Customizable Visibility: You can choose to toggle each component (lines and clouds) on or off depending on your personal trading style.
- Smart Filtering: The script includes internal logic to ensure alerts are not repetitive. It "remembers" if a trend has already been signaled, preventing the system from spamming multiple notifications for the same price movement.
- Multi-Asset Awareness: Every alert message automatically includes the name of the currency pair or asset being traded and the current timeframe, allowing you to quickly identify which trade is signaling a move.
//+------------------------------------------------------------------+
//| IchimokuAlert_v2.mq4 |
//| Copyright © 2006, Forex-TSD.com |
//| Written by IgorAD,igorad2003@yahoo.co.uk |
//| Adapted and improved by Snowski © 2009 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link "http://www.forex-tsd.com/"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 Thistle
#property indicator_color4 Indigo
#property indicator_color5 Yellow
#property indicator_color6 Indigo
#property indicator_color7 Thistle
//---- input parameters
extern int Tenkan =9;
extern int Kijun =26;
extern int Senkou =52;
extern int AlertMode =3;
extern string Alert_Setting = "--- Alert Setting:---";
extern string A_S0 = "0 = no alert";
extern string A_S1 = "1 = Tenkan crosses Kjiun";
extern string A_S2 = "2 = Kijun crosses Price";
extern string A_S3 = "3 = both";
extern bool Show_Tenkan = true;
extern bool Show_Kijun = true;
extern bool Show_Senkou = true;
extern bool Show_Kumo = true;
//---- buffers
double Tenkan_Buffer[];
double Kijun_Buffer[];
double SpanA_Buffer[];
double SpanB_Buffer[];
double Chinkou_Buffer[];
double SpanA2_Buffer[];
double SpanB2_Buffer[];
//----
int a_begin;
bool UptrendAlert1,DntrendAlert1,UptrendAlert2,DntrendAlert2;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(Show_Tenkan==true){
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(0,Tenkan_Buffer);
SetIndexDrawBegin(0,Tenkan-1);
SetIndexLabel(0,"Tenkan Sen");
}
//----
if(Show_Kijun==true){
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(1,Kijun_Buffer);
SetIndexDrawBegin(1,Kijun-1);
SetIndexLabel(1,"Kijun Sen");
}
//----
if(Show_Kumo==true){
a_begin=Kijun; if(a_begin<Tenkan) a_begin=Tenkan;
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_DOT);
SetIndexBuffer(2,SpanA_Buffer);
SetIndexDrawBegin(2,Kijun+a_begin-1);
SetIndexShift(2,Kijun);
SetIndexLabel(2,NULL);
SetIndexStyle(5,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(5,SpanA2_Buffer);
SetIndexDrawBegin(5,Kijun+a_begin-1);
SetIndexShift(5,Kijun);
SetIndexLabel(5,"Senkou Span A");
}
//----
if(Show_Kumo==true){
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_DOT);
SetIndexBuffer(3,SpanB_Buffer);
SetIndexDrawBegin(3,Kijun+Senkou-1);
SetIndexShift(3,Kijun);
SetIndexLabel(3,NULL);
SetIndexStyle(6,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(6,SpanB2_Buffer);
SetIndexDrawBegin(6,Kijun+Senkou-1);
SetIndexShift(6,Kijun);
SetIndexLabel(6,"Senkou Span B");
}
//----
if(Show_Senkou==true){
SetIndexStyle(4,DRAW_LINE);
SetIndexBuffer(4,Chinkou_Buffer);
SetIndexShift(4,-Kijun);
SetIndexLabel(4,"Chinkou Span");
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Ichimoku Kinko Hyo |
//+------------------------------------------------------------------+
int start()
{
int i,k;
int counted_bars=IndicatorCounted();
double high,low,price;
//----
if(Bars<=Tenkan || Bars<=Kijun || Bars<=Senkou) return(0);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=Tenkan;i++) Tenkan_Buffer[Bars-i]=0;
for(i=1;i<=Kijun;i++) Kijun_Buffer[Bars-i]=0;
for(i=1;i<=a_begin;i++) { SpanA_Buffer[Bars-i]=0; SpanA2_Buffer[Bars-i]=0; }
for(i=1;i<=Senkou;i++) { SpanB_Buffer[Bars-i]=0; SpanB2_Buffer[Bars-i]=0; }
}
//---- Tenkan Sen
i=Bars-Tenkan;
if(counted_bars>Tenkan) i=Bars-counted_bars-1;
while(i>=0)
{
high=High[i]; low=Low[i]; k=i-1+Tenkan;
while(k>=i)
{
price=High[k];
if(high<price) high=price;
price=Low[k];
if(low>price) low=price;
k--;
}
Tenkan_Buffer[i]=(high+low)/2;
i--;
}
//---- Kijun Sen
i=Bars-Kijun;
if(counted_bars>Kijun) i=Bars-counted_bars-1;
while(i>=0)
{
high=High[i]; low=Low[i]; k=i-1+Kijun;
while(k>=i)
{
price=High[k];
if(high<price) high=price;
price=Low[k];
if(low>price) low=price;
k--;
}
Kijun_Buffer[i]=(high+low)/2;
i--;
}
//---- Senkou Span A
i=Bars-a_begin+1;
if(counted_bars>a_begin-1) i=Bars-counted_bars-1;
while(i>=0)
{
price=(Kijun_Buffer[i]+Tenkan_Buffer[i])/2;
SpanA_Buffer[i]=price;
SpanA2_Buffer[i]=price;
i--;
}
//---- Senkou Span B
i=Bars-Senkou;
if(counted_bars>Senkou) i=Bars-counted_bars-1;
while(i>=0)
{
high=High[i]; low=Low[i]; k=i-1+Senkou;
while(k>=i)
{
price=High[k];
if(high<price) high=price;
price=Low[k];
if(low>price) low=price;
k--;
}
price=(high+low)/2;
SpanB_Buffer[i]=price;
SpanB2_Buffer[i]=price;
i--;
}
//---- Chinkou Span
i=Bars-1;
if(counted_bars>1) i=Bars-counted_bars-1;
while(i>=0) { Chinkou_Buffer[i]=Close[i]; i--; }
//----
if (AlertMode == 1 || AlertMode == 3)
{
string Message1 = "Tenkan crosses Kijun: "+Symbol()+" on M"+Period();
/*
if ( Tenkan_Buffer[0]>Kijun_Buffer[0] && Tenkan_Buffer[1]<Kijun_Buffer[1])
PlaySound("alert.wav");
if ( Tenkan_Buffer[0]<Kijun_Buffer[0] && Tenkan_Buffer[1]>Kijun_Buffer[1])
PlaySound("alert.wav");
*/
if ( Tenkan_Buffer[1]>Kijun_Buffer[1] && Tenkan_Buffer[2]<Kijun_Buffer[2] && !UptrendAlert1)
{Alert("BUY Signal --- : "+Message1); UptrendAlert1 = true; DntrendAlert1 = false;}
if ( Tenkan_Buffer[1]<Kijun_Buffer[1] && Tenkan_Buffer[2]>Kijun_Buffer[2] && !DntrendAlert1)
{Alert("SELL Signal --- : "+Message1); UptrendAlert1 = false; DntrendAlert1 = true;}
}
if (AlertMode == 2 || AlertMode == 3)
{
string Message2 = "Kijun crossed Price: "+Symbol()+" on M"+Period();
/*
if ( Close[0]>Close[0+Kijun] && Close[1]<Close[1+Kijun])
PlaySound("alert2.wav");
if ( Close[0]<Close[0+Kijun] && Close[1]>Close[1+Kijun])
PlaySound("alert2.wav");
*/
if ( Close[1]>Close[1+Kijun] && Close[2]<Close[2+Kijun] && !UptrendAlert2)
{Alert("BUY Signal --- : "+Message2); DntrendAlert2 = false; UptrendAlert2 = true;}
if ( Close[1]<Close[1+Kijun] && Close[2]>Close[2+Kijun] && !DntrendAlert2)
{Alert("SELL Signal --- : "+Message2); DntrendAlert2 = true; UptrendAlert2 = false;}
}
return(0);
}
//+------------------------------------------------------------------+
Comments