Ichimoku_sigTKSCcrossChiko

Download script
Author: Copyright � 2004, MetaQuotes Software Corp.
Ichimoku_sigTKSCcrossChiko

This script is designed for the MetaTrader 4 platform to visualize a complex technical analysis tool known as the Ichimoku Kinko Hyo. This indicator is widely used by traders to identify trends, support and resistance levels, and potential turning points in financial markets by looking at historical price data.

Rather than just showing where the price is currently, this logic creates several moving components that help "map out" the market environment. Here is a breakdown of how the logic functions:

Core Trend Components

The script calculates two primary lines that track the relationship between recent highs and lows:

  • Tenkan Sen (Conversion Line): This tracks short-term momentum. It calculates the midpoint of the highest highs and lowest lows over a set period of time.
  • Kijun Sen (Base Line): This tracks medium-term momentum by looking at a longer timeframe of price action.

The "Cloud" (Senkou Span)

One of the most unique features of this logic is the creation of the "Cloud." The script generates two different spans:

  • Senkou Span A: This is derived from the average of the two lines mentioned above (Tenkan and Kijun).
  • Senkou Span B: This is calculated based on a much longer historical timeframe.

When these two spans are plotted together, they form a visual "cloud." Traders typically look at this cloud to identify the market's bias; for example, if the price is above the cloud, the trend may be considered bullish, and if below, it may be bearish.

Signals and Crossings

Beyond just drawing lines, the script contains logic to identify specific "trigger" events where these components interact:

  • Tenkan/Kijun Crosses: The logic monitors when the short-term line crosses over the medium-term line. These are often interpreted as signals for a potential change in momentum.
  • Cloud Crosses: The script identifies moments when the Senkou Span A and B cross each other, which can indicate a shift in the broader market structure.
  • Price/Chinkou Interactions: The script tracks the relationship between current price action (or specific trend lines) and the "Cloud" from previous periods to help determine if the current move has enough strength to sustain itself.

Visual Representation

To make this data digestible for a user, the script uses different visual styles:

  • Lines: Used for the primary trend components (Tenkan, Kijun, and the Spans).
  • Arrows/Markers: The logic specifically identifies "crosses" (where lines meet or pass through one another) and places visual markers on the chart. This allows a trader to see at a glance exactly where a historical shift in momentum occurred without having to manually watch every candle.

Summary of Movement

The script essentially "pre-processes" the raw market data by calculating several different averages and high/low points simultaneously. It then overlays these as a visual map, providing a multi-layered view of short-term speed, medium-term stability, and long-term market boundaries.

Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
Ichimoku_sigTKSCcrossChiko
//+------------------------------------------------------------------+
//|                                                     Ichimoku.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
//mod2008fxtsd
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Tomato
#property indicator_color4 Gold
#property indicator_color5 Teal
#property indicator_color6 SandyBrown
#property indicator_color7 Thistle
#property indicator_color8 MediumTurquoise

#property  indicator_width3  3
#property  indicator_width4  4
#property  indicator_width5  1
#property  indicator_width8  2


//---- input parameters
extern int Tenkan=9;
extern int Kijun=26;
extern int Senkou=52;
extern int KumoShift= 26;
//extern bool Chinkou_line= false;
extern bool ChinkouTencan= false;
extern bool ChinkouKijun = false;

//---- buffers
double Tenkan_Buffer[];
double Kijun_Buffer[];
double SpanA_Buffer[];
double SpanB_Buffer[];
double Chinkou_Buffer[];
double SpanA2_Buffer[];
double SpanB2_Buffer[];
double TKcross_Buffer[];

double Chinkou_Cross_Buffer[];

//----
int a_begin;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//----
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Tenkan_Buffer);
   SetIndexDrawBegin(0,Tenkan-1);
   SetIndexLabel(0,"Tenkan Sen");
//----
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Kijun_Buffer);
   SetIndexDrawBegin(1,Kijun-1);
   SetIndexLabel(1,"Kijun Sen");
//----
   a_begin=Kijun; if(a_begin<Tenkan) a_begin=Tenkan;
//   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_DOT);
   SetIndexBuffer(2,SpanA_Buffer);
   SetIndexStyle (2, DRAW_ARROW);
   SetIndexArrow(2, 115);  //romb
   SetIndexEmptyValue(2, EMPTY_VALUE);   
   SetIndexLabel(2, "KumCross");   //SenkouABCross;KumoCroos
   SetIndexDrawBegin(2,Kijun+a_begin-1);

//   SetIndexShift(2,Kijun);
//   SetIndexLabel(2,NULL);


   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,SpanA2_Buffer);
   SetIndexDrawBegin(5,Kijun+a_begin-1);
   SetIndexShift(5,KumoShift);
   SetIndexLabel(5,"Senkou Span A");
//----
//   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_DOT);
   SetIndexBuffer(7,SpanB_Buffer);
   SetIndexDrawBegin(7,Kijun+Senkou-1);
//  SetIndexShift(3,Kijun);
//  SetIndexLabel(3,NULL);
   SetIndexStyle (7, DRAW_ARROW);
   SetIndexArrow(7, 158);
   SetIndexEmptyValue(3, EMPTY_VALUE);   
   SetIndexLabel(7, "ChikoCross");   //ChinkouPriceCross


   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6,SpanB2_Buffer);
   SetIndexDrawBegin(6,Kijun+Senkou-1);
   SetIndexShift(6,KumoShift);
   SetIndexLabel(6,"Senkou Span B");
//----

   SetIndexBuffer(4,Chinkou_Buffer);   
   SetIndexDrawBegin(4,Kijun-1);
//   SetIndexStyle (4, DRAW_ARROW);
//   SetIndexArrow (4, 158);
//   SetIndexShift(4,NULL);
//   SetIndexEmptyValue(4, EMPTY_VALUE);   
//   SetIndexLabel(4, "ChinkouPriceCross");   

//if(Chinkou_line){   }
   SetIndexStyle(4,DRAW_LINE);
   SetIndexShift(4,-KumoShift);
   SetIndexLabel(4,"Chiko Span");//Chinkou Span"


//----

   SetIndexBuffer(3,TKcross_Buffer);
   SetIndexDrawBegin(3,Kijun-1);
   SetIndexStyle (3, DRAW_ARROW);
   SetIndexArrow (3, 158);
   SetIndexEmptyValue(3, EMPTY_VALUE);   
   SetIndexLabel(3, "TenkanKijunCross");   




   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;
      SpanA2_Buffer[i]=price;
//    SpanA_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;
      SpanB2_Buffer[i]=price;
      
    
      i--;
     }
//---- Chinkou Span

   i=Bars-Senkou;
   if(counted_bars>Senkou) i=Bars-counted_bars-1;

//   i=Bars-1;
//   if(counted_bars>1) i=Bars-counted_bars-1;

   while(i>=0) { 
      
      double Range = 0.0;
      for (int counter=i ;counter<=i+9;counter++) 
      Range += MathAbs(High[counter]-Low[counter]);
      Range /= 10;

   if (Tenkan_Buffer[i+1]<=Kijun_Buffer[i+1] && Tenkan_Buffer[i]>Kijun_Buffer[i])
       TKcross_Buffer[i] =Low[i]-0.75*Range;
   if (Tenkan_Buffer[i+1]>=Kijun_Buffer[i+1] && Tenkan_Buffer[i]<Kijun_Buffer[i])
       TKcross_Buffer[i] =High[i]+0.75*Range;

   if (SpanA2_Buffer[i+1]<=SpanB2_Buffer[i+1] && SpanA2_Buffer[i]>SpanB2_Buffer[i])
       SpanA_Buffer[i] =Low[i]-Range;
   if (SpanA2_Buffer[i+1]>=SpanB2_Buffer[i+1] && SpanA2_Buffer[i]<SpanB2_Buffer[i])
       SpanA_Buffer[i] =High[i]+Range;



  if (ChinkouTencan)Chinkou_Buffer[i]=Tenkan_Buffer[i];
  else 
  if (ChinkouKijun) Chinkou_Buffer[i]=Kijun_Buffer[i];
  else   Chinkou_Buffer[i]=Close[i];


  if (Chinkou_Buffer[KumoShift+i+1]<=Chinkou_Buffer[i+1]&&Chinkou_Buffer[KumoShift+i]>Chinkou_Buffer[i])
         SpanB_Buffer[i] =High[i]+0.5*Range;

  if (Chinkou_Buffer[KumoShift+i+1]>=Chinkou_Buffer[i+1]&&Chinkou_Buffer[KumoShift+i]<Chinkou_Buffer[i])
         SpanB_Buffer[i] =Low[i]-0.5*Range;

   i--; }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments