Ichimoku+GuppyAlligator2
Download scriptThis script is a specialized technical analysis tool designed for the MetaTrader trading platform. It functions by generating multiple visual data lines on a price chart to help traders identify market trends and potential equilibrium points.
Core Functionality
The logic of this script is based on the "Ichimoku Kinko Hyo" philosophy, which focuses on calculating the midpoint between high and low prices over specific timeframes. Instead of using a single standard line, this tool expands that concept by creating eight distinct data streams, categorized into two main groups: Tenkan lines and Kijun lines.
How the Logic Works
The script processes market data by looking backward through historical price history to perform the following actions:
- Dynamic Range Calculation: For each of the eight lines, the script identifies a specific "look-back" period (defined by the user's settings). It scans the highest price reached and the lowest price dropped within that specific window of time.
- Midpoint Averaging: Once the high and low points for that window are found, the script calculates the exact mathematical middle point. This result is then plotted as a line on your chart.
- Multi-Layered Analysis: By providing four different versions of both Tenkan and Kijun lines, the script allows you to see several layers of market "balance" simultaneously. Because each line uses a slightly different look-back window (for example, Tenkan 1 might look at very recent price action while Kijun 4 looks at a much broader timeframe), it allows traders to visualize:
- Short-term momentum: Fast-moving lines that react quickly to recent price changes.
- Long-term stability: Slower, smoother lines that represent the broader trend and historical support/resistance levels.
Visual Representation
When applied to a chart, the script generates eight separate lines. These are designed to interact with one another; by observing where these lines cluster, cross each other, or flatten out, a trader can interpret the market's current strength, volatility, and overall direction across multiple time horizons at once.
//+------------------------------------------------------------------+
//| Ichimoku+GuppyAlligator2.mq4 |
//| Copyright © 2009, úXgFX!. |
//|@gp´zÈÇAÇ¢«¢Ç¿çÅà ÁÄà´z¸¯êÎðµ¢Å·ô|
//| http://fx-insanity-trade.seesaa.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, úXgFX!."
#property link "http://fx-insanity-trade.seesaa.net/"
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Yellow
#property indicator_color2 Pink
#property indicator_color3 Pink
#property indicator_color4 Pink
#property indicator_color5 Aqua
#property indicator_color6 Aqua
#property indicator_color7 Aqua
#property indicator_color8 Aqua
//---- input parameters
extern int Tenkan1=1;
extern int Tenkan2=2;
extern int Tenkan3=3;
extern int Tenkan4=4;
extern int Kijun1=18;
extern int Kijun2=19;
extern int Kijun3=20;
extern int Kijun4=21;
//---- buffers
double Tenkan1_Buffer[];
double Tenkan2_Buffer[];
double Tenkan3_Buffer[];
double Tenkan4_Buffer[];
double Kijun1_Buffer[];
double Kijun2_Buffer[];
double Kijun3_Buffer[];
double Kijun4_Buffer[];
//----
int a_begin;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Tenkan1_Buffer);
SetIndexDrawBegin(0,Tenkan1-1);
SetIndexLabel(0,"Tenkan1");
SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(1,Tenkan2_Buffer);
SetIndexDrawBegin(1,Tenkan2-1);
SetIndexLabel(1,"Tenkan2");
SetIndexStyle(2,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(2,Tenkan3_Buffer);
SetIndexDrawBegin(2,Tenkan3-1);
SetIndexLabel(2,"Tenkan3");
SetIndexStyle(3,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(3,Tenkan4_Buffer);
SetIndexDrawBegin(3,Tenkan4-1);
SetIndexLabel(3,"Tenkan4");
//----
SetIndexStyle(4,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(4,Kijun1_Buffer);
SetIndexDrawBegin(4,Kijun1-1);
SetIndexLabel(4,"Kijun1");
SetIndexStyle(5,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(5,Kijun2_Buffer);
SetIndexDrawBegin(5,Kijun2-1);
SetIndexLabel(5,"Kijun2");
SetIndexStyle(6,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(6,Kijun3_Buffer);
SetIndexDrawBegin(6,Kijun3-1);
SetIndexLabel(6,"Kijun3");
SetIndexStyle(7,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(7,Kijun4_Buffer);
SetIndexDrawBegin(7,Kijun4-1);
SetIndexLabel(7,"Kijun4");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Ichimoku Kinko Hyo |
//+------------------------------------------------------------------+
int start()
{
int i,k;
int counted_bars=IndicatorCounted();
double high,low,price;
//----
if(Bars<=Tenkan1 || Bars<=Tenkan2 || Bars<=Tenkan3 || Bars<=Tenkan4 || Bars<=Kijun1 || Bars<=Kijun2 || Bars<=Kijun3 || Bars<=Kijun4) return(0);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=Tenkan1;i++) Tenkan1_Buffer[Bars-i]=0;
for(i=1;i<=Tenkan2;i++) Tenkan2_Buffer[Bars-i]=0;
for(i=1;i<=Tenkan3;i++) Tenkan3_Buffer[Bars-i]=0;
for(i=1;i<=Tenkan4;i++) Tenkan4_Buffer[Bars-i]=0;
for(i=1;i<=Kijun1;i++) Kijun1_Buffer[Bars-i]=0;
for(i=1;i<=Kijun2;i++) Kijun2_Buffer[Bars-i]=0;
for(i=1;i<=Kijun3;i++) Kijun3_Buffer[Bars-i]=0;
for(i=1;i<=Kijun4;i++) Kijun4_Buffer[Bars-i]=0;
}
//---- Tenkan1
i=Bars-Tenkan1;
if(counted_bars>Tenkan1) i=Bars-counted_bars-1;
while(i>=0)
{
high=High[i]; low=Low[i]; k=i-1+Tenkan1;
while(k>=i)
{
price=High[k];
if(high<price) high=price;
price=Low[k];
if(low>price) low=price;
k--;
}
Tenkan1_Buffer[i]=(high+low)/2;
i--;
}
//---- Tenkan2
i=Bars-Tenkan2;
if(counted_bars>Tenkan2) i=Bars-counted_bars-1;
while(i>=0)
{
high=High[i]; low=Low[i]; k=i-1+Tenkan2;
while(k>=i)
{
price=High[k];
if(high<price) high=price;
price=Low[k];
if(low>price) low=price;
k--;
}
Tenkan2_Buffer[i]=(high+low)/2;
i--;
}
//---- Tenkan3
i=Bars-Tenkan3;
if(counted_bars>Tenkan3) i=Bars-counted_bars-1;
while(i>=0)
{
high=High[i]; low=Low[i]; k=i-1+Tenkan3;
while(k>=i)
{
price=High[k];
if(high<price) high=price;
price=Low[k];
if(low>price) low=price;
k--;
}
Tenkan3_Buffer[i]=(high+low)/2;
i--;
}
//---- Tenkan4
i=Bars-Tenkan4;
if(counted_bars>Tenkan4) i=Bars-counted_bars-1;
while(i>=0)
{
high=High[i]; low=Low[i]; k=i-1+Tenkan4;
while(k>=i)
{
price=High[k];
if(high<price) high=price;
price=Low[k];
if(low>price) low=price;
k--;
}
Tenkan4_Buffer[i]=(high+low)/2;
i--;
}
//---- Kijun1
i=Bars-Kijun1;
if(counted_bars>Kijun1) i=Bars-counted_bars-1;
while(i>=0)
{
high=High[i]; low=Low[i]; k=i-1+Kijun1;
while(k>=i)
{
price=High[k];
if(high<price) high=price;
price=Low[k];
if(low>price) low=price;
k--;
}
Kijun1_Buffer[i]=(high+low)/2;
i--;
}
//---- Kijun2
i=Bars-Kijun2;
if(counted_bars>Kijun2) i=Bars-counted_bars-1;
while(i>=0)
{
high=High[i]; low=Low[i]; k=i-1+Kijun2;
while(k>=i)
{
price=High[k];
if(high<price) high=price;
price=Low[k];
if(low>price) low=price;
k--;
}
Kijun2_Buffer[i]=(high+low)/2;
i--;
}
//---- Kijun3
i=Bars-Kijun3;
if(counted_bars>Kijun3) i=Bars-counted_bars-1;
while(i>=0)
{
high=High[i]; low=Low[i]; k=i-1+Kijun3;
while(k>=i)
{
price=High[k];
if(high<price) high=price;
price=Low[k];
if(low>price) low=price;
k--;
}
Kijun3_Buffer[i]=(high+low)/2;
i--;
}
//---- Kijun4
i=Bars-Kijun4;
if(counted_bars>Kijun4) i=Bars-counted_bars-1;
while(i>=0)
{
high=High[i]; low=Low[i]; k=i-1+Kijun4;
while(k>=i)
{
price=High[k];
if(high<price) high=price;
price=Low[k];
if(low>price) low=price;
k--;
}
Kijun4_Buffer[i]=(high+low)/2;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments