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

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Gray         //0ts
#property indicator_color2 Gray        //1ks
#property indicator_color3 Silver      //2uk
#property indicator_color4 Gray        //3dk
#property indicator_color5 Green       //4cs
#property indicator_color6 Red      //5sa
#property indicator_color7 Gray  //6sb
//---- input parameters

extern int a_ichi=22;

double ts_c=0.5;
double ks_c=1.5;
double ss_c=3.0;

extern color up_clr = Green;
extern color down_clr = Red;
extern color av_clr = Blue;
extern bool Levels =   true;
extern bool Comments = true;
extern int Dig = 3; 
int Tenkan;
int Kijun;
int Senkou;



//---- 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;


int shift;



double    

mode_ts,
mode_ks,
mode_sb,
mode_sa,
mode_cs;
double
  
   
   
   up_lev_ts,
   up_lev_ks,
   up_lev_sb,
   av_0,
   down_lev_ts,
   down_lev_ks,
   down_lev_sb,
   
   abs_diff_ts_ks,
   abs_diff_ks_sb,
   summ_abs_diff_tsks_ks_sb,
   max_abs_summ_diff_tsks_kssb;
   

string comm="";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
     
      {
      Tenkan   =a_ichi*ts_c;
      Kijun    =a_ichi*ks_c;
      Senkou   =a_ichi*ss_c;
      }
      
      
  
   
   
   
//----
   SetIndexStyle(0,DRAW_LINE,0,1);
   SetIndexBuffer(0,Tenkan_Buffer);
   SetIndexDrawBegin(0,Tenkan-1);
   SetIndexLabel(0,"TS");
//----
   SetIndexStyle(1,DRAW_LINE,0,2);
   SetIndexBuffer(1,Kijun_Buffer);
   SetIndexDrawBegin(1,Kijun-1);
   SetIndexShift(1,Tenkan);
   SetIndexLabel(1,"KS");
//----
   a_begin=Kijun; if(a_begin<Tenkan) a_begin=Tenkan;
   SetIndexStyle(2,DRAW_NONE, STYLE_DOT);
   SetIndexBuffer(2,SpanA_Buffer);
   SetIndexDrawBegin(2,Kijun+a_begin-1);
   SetIndexShift(2,Kijun);
   SetIndexLabel(2,NULL);
   SetIndexStyle(5,DRAW_NONE,0,2);
   SetIndexBuffer(5,SpanA2_Buffer);
   SetIndexDrawBegin(5,Kijun+a_begin-1);
   SetIndexShift(5,Kijun);
   SetIndexLabel(5,"SA");
//----
   SetIndexStyle(3,DRAW_NONE, STYLE_DOT);
   SetIndexBuffer(3,SpanB_Buffer);
   SetIndexDrawBegin(3,Kijun+Senkou-1);
   SetIndexShift(3,Kijun);
   SetIndexLabel(3,NULL);
   SetIndexStyle(6,DRAW_LINE,0,3);
   SetIndexBuffer(6,SpanB2_Buffer);
   SetIndexDrawBegin(6,Kijun+Senkou-1);
   SetIndexShift(6,Kijun);
   SetIndexLabel(6,"SB");
//----
   SetIndexStyle(4,DRAW_NONE,0,2);
   SetIndexBuffer(4,Chinkou_Buffer);
   SetIndexShift(4,-Kijun);
   SetIndexLabel(4,"CS");
   
   
   
   
   //IndicatorDigits (MarketInfo(Symbol(),MODE_DIGITS)-1);

   

//----
   return(0);
}
  
  int deinit() 
{


//ObjectsDeleteAll();

return(0);
}
//+------------------------------------------------------------------+
//| Ichimoku Kinko Hyo                                               |
//+------------------------------------------------------------------+
int start()
  {
      
      
      string buff_str="StartBar";
      if(ObjectFind(buff_str)==-1)
      {
         ObjectCreate(buff_str, OBJ_ARROW,0, Time[0], Low[1]-2*Point );
         ObjectSet(buff_str, OBJPROP_COLOR, Gray);
      }
      else
      {
         shift=iBarShift(NULL,0,ObjectGet(buff_str,OBJPROP_TIME1));
         ObjectsDeleteAll(-1, OBJ_HLINE);
      }   

   
   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++) {  }
      for(i=1;i<=Senkou;i++)  {  }
     }
//---- 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--;
      
      
     }
      
   for(i=Bars-Kijun;i>=0;i--)
   {	
   
	//ma_ks_ks[i] = iMAOnArray(Kijun_Buffer,0,Kijun/2,0,MODE_SMA,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]= (High[i]+Low[i]+Close[i])/3  ; i--; }
   }


//--

{ 
      
     
      
      
      
      
         {
         mode_ts = Tenkan_Buffer[shift];
         mode_ks = Kijun_Buffer[shift];
         mode_sb = SpanB_Buffer[shift];
         
         mode_sa = SpanA_Buffer[shift];
         mode_cs = Chinkou_Buffer[shift];
         }
         
         
         
         
          
            
           {  
            
            up_lev_ts      =   ((((mode_ts+MathAbs(mode_ts-mode_ks)*ts_c)+(mode_ks+MathAbs(mode_ts-mode_ks)*ts_c)+(mode_sb+MathAbs(mode_ts-mode_ks)*ts_c))/3)+(((mode_ts+MathAbs(mode_ks-mode_sb)*ts_c)+(mode_ks+MathAbs(mode_ks-mode_sb)*ts_c)+(mode_sb+MathAbs(mode_ks-mode_sb)*ts_c))/3)+(((mode_ts+MathAbs(mode_ts-mode_sb)*ts_c)+(mode_ks+MathAbs(mode_ts-mode_sb)*ts_c)+(mode_sb+MathAbs(mode_ts-mode_sb)*ts_c))/3))/3;  
            up_lev_ks      =   ((((mode_ts+MathAbs(mode_ts-mode_ks)*ks_c)+(mode_ks+MathAbs(mode_ts-mode_ks)*ks_c)+(mode_sb+MathAbs(mode_ts-mode_ks)*ks_c))/3)+(((mode_ts+MathAbs(mode_ks-mode_sb)*ks_c)+(mode_ks+MathAbs(mode_ks-mode_sb)*ks_c)+(mode_sb+MathAbs(mode_ks-mode_sb)*ks_c))/3)+(((mode_ts+MathAbs(mode_ts-mode_sb)*ks_c)+(mode_ks+MathAbs(mode_ts-mode_sb)*ks_c)+(mode_sb+MathAbs(mode_ts-mode_sb)*ks_c))/3))/3;
            up_lev_sb      =   ((((mode_ts+MathAbs(mode_ts-mode_ks)*ss_c)+(mode_ks+MathAbs(mode_ts-mode_ks)*ss_c)+(mode_sb+MathAbs(mode_ts-mode_ks)*ss_c))/3)+(((mode_ts+MathAbs(mode_ks-mode_sb)*ss_c)+(mode_ks+MathAbs(mode_ks-mode_sb)*ss_c)+(mode_sb+MathAbs(mode_ks-mode_sb)*ss_c))/3)+(((mode_ts+MathAbs(mode_ts-mode_sb)*ss_c)+(mode_ks+MathAbs(mode_ts-mode_sb)*ss_c)+(mode_sb+MathAbs(mode_ts-mode_sb)*ss_c))/3))/3;
            down_lev_ts    =   ((((mode_ts-MathAbs(mode_ts-mode_ks)*ts_c)+(mode_ks-MathAbs(mode_ts-mode_ks)*ts_c)+(mode_sb-MathAbs(mode_ts-mode_ks)*ts_c))/3)+(((mode_ts-MathAbs(mode_ks-mode_sb)*ts_c)+(mode_ks-MathAbs(mode_ks-mode_sb)*ts_c)+(mode_sb-MathAbs(mode_ks-mode_sb)*ts_c))/3)+(((mode_ts-MathAbs(mode_ts-mode_sb)*ts_c)+(mode_ks-MathAbs(mode_ts-mode_sb)*ts_c)+(mode_sb-MathAbs(mode_ts-mode_sb)*ts_c))/3))/3;
            down_lev_ks    =   ((((mode_ts-MathAbs(mode_ts-mode_ks)*ks_c)+(mode_ks-MathAbs(mode_ts-mode_ks)*ks_c)+(mode_sb-MathAbs(mode_ts-mode_ks)*ks_c))/3)+(((mode_ts-MathAbs(mode_ks-mode_sb)*ks_c)+(mode_ks-MathAbs(mode_ks-mode_sb)*ks_c)+(mode_sb-MathAbs(mode_ks-mode_sb)*ks_c))/3)+(((mode_ts-MathAbs(mode_ts-mode_sb)*ks_c)+(mode_ks-MathAbs(mode_ts-mode_sb)*ks_c)+(mode_sb-MathAbs(mode_ts-mode_sb)*ks_c))/3))/3;
            down_lev_sb    =   ((((mode_ts-MathAbs(mode_ts-mode_ks)*ss_c)+(mode_ks-MathAbs(mode_ts-mode_ks)*ss_c)+(mode_sb-MathAbs(mode_ts-mode_ks)*ss_c))/3)+(((mode_ts-MathAbs(mode_ks-mode_sb)*ss_c)+(mode_ks-MathAbs(mode_ks-mode_sb)*ss_c)+(mode_sb-MathAbs(mode_ks-mode_sb)*ss_c))/3)+(((mode_ts-MathAbs(mode_ts-mode_sb)*ss_c)+(mode_ks-MathAbs(mode_ts-mode_sb)*ss_c)+(mode_sb-MathAbs(mode_ts-mode_sb)*ss_c))/3))/3;
            
            av_0           =   (up_lev_ts+down_lev_ts)/2; 
            
            
         
         }
         
           
         
      
      
      
      
      
   
   
   
}

   {
   
   
   
   }  

//----


   {
   
   
   if (Levels == true)
   
   {
   
   
   ObjectCreate("SUP_1", OBJ_HLINE, 0, 0, NormalizeDouble  (up_lev_ts, Dig));
   ObjectSet   ("SUP_1", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet   ("SUP_1", OBJPROP_COLOR, up_clr);
   ObjectSet   ("SUP_1", OBJPROP_WIDTH, 1);
   ObjectMove  ("SUP_1", 0, 0, NormalizeDouble  (up_lev_ts, Dig));
      
   ObjectCreate("SUP_2", OBJ_HLINE, 0, 0, NormalizeDouble  (up_lev_ks, Dig));
   ObjectSet   ("SUP_2", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet   ("SUP_2", OBJPROP_COLOR, up_clr);
   ObjectSet   ("SUP_2", OBJPROP_WIDTH, 2);
   ObjectMove  ("SUP_2", 0, 0, NormalizeDouble  (up_lev_ks, Dig));
   
   ObjectCreate("SUP_3", OBJ_HLINE, 0, 0, NormalizeDouble  (up_lev_sb, Dig));
   ObjectSet   ("SUP_3", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet   ("SUP_3", OBJPROP_COLOR, up_clr);
   ObjectSet   ("SUP_3", OBJPROP_WIDTH, 3);
   ObjectMove  ("SUP_3", 0, 0, NormalizeDouble  (up_lev_sb, Dig));
   
   //
   
   ObjectCreate("RES_1", OBJ_HLINE, 0, 0, NormalizeDouble  (down_lev_ts, Dig));
   ObjectSet   ("RES_1", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet   ("RES_1", OBJPROP_COLOR, down_clr);
   ObjectSet   ("RES_1", OBJPROP_WIDTH, 1);
   ObjectMove  ("RES_1", 0, 0, NormalizeDouble  (down_lev_ts, Dig));
   
   ObjectCreate("RES_2", OBJ_HLINE, 0, 0, NormalizeDouble  (down_lev_ks, Dig));
   ObjectSet   ("RES_2", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet   ("RES_2", OBJPROP_COLOR, down_clr);
   ObjectSet   ("RES_2", OBJPROP_WIDTH, 2);
   ObjectMove  ("RES_2", 0, 0, NormalizeDouble  (down_lev_ks, Dig));
   
   ObjectCreate("RES_3", OBJ_HLINE, 0, 0, NormalizeDouble  (down_lev_sb, Dig));
   ObjectSet   ("RES_3", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet   ("RES_3", OBJPROP_COLOR, down_clr);
   ObjectSet   ("RES_3", OBJPROP_WIDTH, 3);
   ObjectMove  ("RES_3", 0, 0, NormalizeDouble  (down_lev_sb, Dig));
   
      ObjectCreate("AV_0", OBJ_HLINE, 0, 0, NormalizeDouble  (av_0, Dig));
      ObjectSet   ("AV_0", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet   ("AV_0", OBJPROP_COLOR, av_clr);
      ObjectSet   ("AV_0", OBJPROP_WIDTH, 1);
      ObjectMove  ("AV_0", 0, 0, NormalizeDouble  (av_0, Dig));
   
            
   }
   
   
   }
   
      

   
   {
      if (Comments == true)
   
   {
      
      comm=            "=========\n";
      comm=comm+       "" + DoubleToStr(Tenkan, 0) + " " + DoubleToStr(Kijun, 0) + " " + DoubleToStr(Senkou, 0) + "\n";
      comm=comm+       "" + TimeToStr(ObjectGet(buff_str,OBJPROP_TIME1), TIME_DATE|TIME_MINUTES) + "\n";
      comm=comm+       "=========\n";
      /*
      comm=comm+       "TS " + DoubleToStr(mode_ts, (MarketInfo(Symbol(),MODE_DIGITS)-1)) + "\n";
      comm=comm+       "KS " + DoubleToStr(mode_ks, (MarketInfo(Symbol(),MODE_DIGITS)-1)) + "\n";
      comm=comm+       "SA " + DoubleToStr(mode_sa, (MarketInfo(Symbol(),MODE_DIGITS)-1)) + "\n";
      comm=comm+       "SB " + DoubleToStr(mode_sb, (MarketInfo(Symbol(),MODE_DIGITS)-1)) + "\n";
      comm=comm+       "CS " + DoubleToStr(mode_cs, (MarketInfo(Symbol(),MODE_DIGITS)-1)) + "\n";
      comm=comm+       "=========\n";
      */
      
      comm=comm+       "TS-KS = " + DoubleToStr (NormalizeDouble((mode_ts-mode_ks)/Point/1 ,0),0) + "\n";
      comm=comm+       "SA-SB = " + DoubleToStr (NormalizeDouble((mode_sa-mode_sb)/Point/1 ,0),0) + "\n";
      comm=comm+       "CS-SA = " + DoubleToStr (NormalizeDouble((mode_cs-mode_sa)/Point/1 ,0),0) + "\n";
     
      //comm=comm+       "HI-LO = " +   DoubleToStr (NormalizeDouble((High[iHighest(NULL,0,MODE_HIGH,Kijun,shift)]-Low[iLowest(NULL,0,MODE_LOW,Kijun,shift)])/Point/10,0),0) + "\n";
      comm=comm+       "=========\n";
      
      
      /*
      
         Rsmax2 = High[iHighest(NULL, 0, MODE_HIGH, Kijun, shift)];
       
         Rsmin2 = Low[iLowest(NULL, 0, MODE_LOW, Kijun, shift)];
       
         AvgRange2 = (Rsmax2 / Point) - (Rsmin2 / Point);
      
            mode_ts = Tenkan_Buffer[shift];
            mode_ks = Kijun_Buffer[shift];
            mode_sb = SpanB2_Buffer[shift];
            mode_cs = Chinkou_Buffer[shift];
         
               comm=comm+       "" + DoubleToStr((up_lev_ts-av_0)/Point/10 ,0) + "\n";
               comm=comm+       "" + DoubleToStr((up_lev_ks-up_lev_ts)/Point/10 ,0) + "\n";
               comm=comm+       "" + DoubleToStr((up_lev_sb-up_lev_ks)/Point/10 ,0) + "\n";
               comm=comm+       "=========\n";
      
      comm=comm+       "SUP_1=" + DoubleToStr(up_lev_sb,(MarketInfo(Symbol(),MODE_DIGITS)-2)) + "\n";
      comm=comm+       "SUP_2=" + DoubleToStr(up_lev_ks,(MarketInfo(Symbol(),MODE_DIGITS)-2)) + "\n";
      comm=comm+       "SUP_3=" + DoubleToStr(up_lev_ts,(MarketInfo(Symbol(),MODE_DIGITS)-2)) + "\n";
      comm=comm+       "=========\n";
      comm=comm+       "AVR_0=" + DoubleToStr(av_0,(MarketInfo(Symbol(),MODE_DIGITS)-2)) + "\n";
      comm=comm+       "=========\n";
      comm=comm+       "RES_1=" + DoubleToStr(down_lev_ts,(MarketInfo(Symbol(),MODE_DIGITS)-2)) + "\n";
      comm=comm+       "RES_2=" + DoubleToStr(down_lev_ks,(MarketInfo(Symbol(),MODE_DIGITS)-2)) + "\n";
      comm=comm+       "RES_3=" + DoubleToStr(down_lev_sb,(MarketInfo(Symbol(),MODE_DIGITS)-2)) + "\n";
      comm=comm+       "=========\n";
      */     
      
      
   Comment (comm);
}
}


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

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---