Kijun-SenSoundAlert
Download scriptThis script is designed as a custom technical analysis tool for the MetaTrader platform. Its primary purpose is to identify and highlight specific price movements based on a component of the Ichimoku Cloudkōhyo indicator, specifically focusing on the Kijun-sen (the "Baseline").
Core Functionality
The script monitors the relationship between the current market price and the Kijun-sen line. It acts as an automated lookout that alerts the user when the price crosses this specific baseline, which many traders use to determine the medium-term trend of a financial instrument.
How it Works
The logic follows a structured three-step process:
1. Data Calculation The tool automatically scans historical price data to calculate the Kijun-sen value. It looks back at a specific timeframe (defined by the "Kijun" setting) and identifies the highest peak and the lowest valley within that period. It then calculates the midpoint of these two extremes to plot the baseline on your chart.
2. Dynamic Visual Representation The script draws this baseline on the chart, applying a visual offset (the "Shift"). This ensures that the line is positioned correctly relative to current price action, making it easier for users to see where the equilibrium point lies at any given moment.
3. Automated Alert System This is the active "intelligence" of the script. It constantly monitors two conditions:
- Upside Breakout: If the market price closes above the Kijun-sen line, the script triggers an audible alert and a visual notification on your screen.
- Downside Breakout: If the market price closes below the Kijun-sen line, it similarly triggers an alert.
To prevent the system from sending repetitive notifications for the same movement, it includes a "toggle" logic. Once it announces a cross in one direction, it waits for a new confirmation before alerting you again, ensuring that your workspace remains clear of unnecessary noise while still capturing the critical moments where the trend shifts.
//+------------------------------------------------------------------+
//| Ichimoku.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| Copyright © 2004, AlexSilver â ïëàíå + |
//| http://www.metaquotes.net/ |
//| http://www.viac.ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, AlexSilver â ïëàíå +"
#property link "http://www.viac.ru/"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- input parameters
extern int Kijun=26;
extern int KijunShift=9;
//---- buffers
double Kijun_Buffer[];
bool Above=true, Below=true;
//----
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- Âûâîä Kijun-sen
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Kijun_Buffer);
SetIndexDrawBegin(1,Kijun+KijunShift-1);
SetIndexShift(1,KijunShift);
SetIndexLabel(1,"Kijun Sen");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Ichimoku Kinko Hyo |
//+------------------------------------------------------------------+
int start()
{
int i,k;
double u=0;
int counted_bars=IndicatorCounted();
double high,low,price;
//----
if(Bars<=Kijun) return(0);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=Kijun;i++) Kijun_Buffer[Bars-i]=0;
}
//---- 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+KijunShift]=(high+low)/2;
i--;
} i=KijunShift-1;
while(i>=0)
{
high=High[0]; low=Low[0]; k=Kijun-KijunShift+i;
while(k>=0)
{
price=High[k];
if(high<price) high=price;
price=Low[k];
if(low>price) low=price;
k--;
}
Kijun_Buffer[i]=(high+low)/2;
i--;
}
if(Above){
if(Close[0]>Kijun_Buffer[9])
{
Alert("Bar Close >",Kijun_Buffer[9]," ",Symbol());
PlaySound("alert.wav");
Above=false;
}
}
if(Below) {
if(Close[0]<Kijun_Buffer[9])
{
Alert("Bar Close <",Kijun_Buffer[9]," ",Symbol());
PlaySound("alert.wav");
Below=false;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments