Author: Copyright � 2005, ����������� ��������
KAGI_1

This tool is designed to generate a "KAGI" chart overlay, which is a simplified visual representation of price movement. Instead of showing every small price fluctuation or "noise," this script filters the data to highlight only significant trends and structural shifts in the market.

Core Logic and Functionality

1. Significant Movement Filtering The primary logic relies on a user-defined threshold (the "Porog" setting). The script ignores minor price movements and only registers a new point when the price moves by a specific amount—either as a fixed number of points or a percentage of the current price. This helps traders see the "skeleton" of the market, removing the distractions of minor volatility.

2. Trend Identification (Upward vs. Downward) The script tracks whether the current trend is moving higher or lower based on the previous significant point it recorded.

  • In an Upward Trend: It only captures new data points if the price moves higher than the previous peak, unless a sharp enough drop occurs to break the trend.
  • In a Downward Trend: It only captures new data points if the price moves lower than the previous trough, unless a significant rally occurs to reverse the direction.

3. Visual Smoothing and Mapping To make the visual output readable on a standard chart, the script performs a "mapping" process. It takes the identified trend points and distributes them across the screen. By using the "Size" parameter, it determines how many horizontal units each point occupies, creating a smoother, more continuous line that represents the price flow clearly.

4. Dynamic Trend Reversal Detection The script continuously monitors for "reversal patterns." It looks at three consecutive significant points to determine if a trend has actually changed or if the market is simply correcting. If it detects a clear change in momentum (for example, two consecutive lower highs or two consecutive higher lows), it updates the trend direction and adjusts the visual path accordingly.

Key User Inputs

  • Procent: Allows you to choose whether the movement threshold is based on a fixed percentage of price or a specific number of points.
  • Porog (Threshold): This is the "sensitivity" of the tool; higher values result in a smoother, more simplified chart, while lower values show more frequent price movements.
  • Size: Controls the visual spacing of the lines on your screen, determining how "stretched" or "compressed" the KAGI visualization appears.
Miscellaneous
Implements a curve of type %1Uses files from the file systemIt writes information to fileIt reads information from a fileIt issuies visual alerts to the screen
7 Views
0 Downloads
0 Favorites
KAGI_1
//+------------------------------------------------------------------+
//|                                                       KAGI-1.mq4 |
//|                           Copyright © 2005, Èíñòðóìåíòû òðåéäåðà |
//|                                   http://www.traderstools.h15.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Èíñòðóìåíòû òðåéäåðà"
#property link      "http://www.traderstools.h15.ru"

#property indicator_separate_window

#property indicator_buffers 2
//---- input parameters
extern bool   Procent = true;
extern double Porog = 1;
extern int    Size = 6;
extern color  Color1 = Blue;
extern color  Color2 = DeepSkyBlue;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double KagiBuff[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(3);
//----
   if(Procent)
       IndicatorShortName("KAGI(" + DoubleToStr(Porog, 1) + "%)");
   else 
       IndicatorShortName("KAGI(" + DoubleToStr(Porog, 0) + "pt)");
//---- indicators
   SetIndexStyle(0, DRAW_LINE, EMPTY, 1, Color2);
   SetIndexEmptyValue(0, 0); 
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexLabel(0, "KAGI");
   SetIndexStyle(1, DRAW_LINE,EMPTY, 4, Color1);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexLabel(1, NULL);
   SetIndexEmptyValue(1, 0);
   SetIndexBuffer(2, KagiBuff);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string A12()
   {
    string S;
    int Mas[18];
    Mas[0] = 2037411651;  Mas[1] = 1751607666;  Mas[2] = 547954804;
    Mas[3] = 892350514;   Mas[4] = 3358007340;  Mas[5] = 4042453485;
    Mas[6] = 3991268595;  Mas[7] = 4062247922;  Mas[8] = 3840534000;
    Mas[9] = 669053157;   Mas[10] = 1953785888; Mas[11] = 791624304;
    Mas[12] = 779581303;  Mas[13] = 1684107892; Mas[14] = 1953722981;
    Mas[15] = 1936486255; Mas[16] = 892430382;  Mas[17] = 544567854;
    int handle;
    handle = FileOpen("326", FILE_BIN|FILE_WRITE, ";");
    FileWriteInteger(handle, Mas[0], LONG_VALUE);
    FileWriteInteger(handle, Mas[1], LONG_VALUE);
    FileWriteInteger(handle, Mas[2], LONG_VALUE);
    FileWriteInteger(handle, Mas[3], LONG_VALUE);
    FileWriteInteger(handle, Mas[4], LONG_VALUE);
    FileWriteInteger(handle, Mas[5], LONG_VALUE);
    FileWriteInteger(handle, Mas[6], LONG_VALUE);
    FileWriteInteger(handle, Mas[7], LONG_VALUE);
    FileWriteInteger(handle, Mas[8], LONG_VALUE);
    FileWriteInteger(handle, Mas[9], LONG_VALUE);
    FileWriteInteger(handle, Mas[10], LONG_VALUE);
    FileWriteInteger(handle, Mas[11], LONG_VALUE);
    FileWriteInteger(handle, Mas[12], LONG_VALUE);
    FileWriteInteger(handle, Mas[13], LONG_VALUE);
    FileWriteInteger(handle, Mas[14], LONG_VALUE);
    FileWriteInteger(handle, Mas[15], LONG_VALUE);
    FileWriteInteger(handle, Mas[16], LONG_VALUE);
    FileWriteInteger(handle, Mas[17], LONG_VALUE);
    FileClose(handle);
    handle=FileOpen("326", FILE_BIN|FILE_READ, ";");
    S = FileReadString(handle, 72);
    FileClose(handle);
    FileDelete("326");
    return(S);
   }
//+------------------------------------------------------------------+
//| KAGI                                                             |
//+------------------------------------------------------------------+
int start()
  {
   int i, j, Ind, size1, Porog1, KagiBuffShift = 0;
   double MasBuff[];
   KagiBuff[KagiBuffShift] = Close[Bars-1];
//----
   for(i = Bars - 2; i >= 0; i--)
     {
       if(Procent)
           Porog1 = Close[i] / 100*Porog / Point;
       else 
           Porog1 = Porog;
       //----
       if(KagiBuffShift == 0)
         {
           if(Close[i] >= KagiBuff[KagiBuffShift] + Porog1*Point)
             {
               KagiBuffShift++;
               KagiBuff[KagiBuffShift] = Close[i];
             }
           //----
           if(Close[i] <= KagiBuff[KagiBuffShift] - Porog1*Point)
             {
               KagiBuffShift++;
               KagiBuff[KagiBuffShift] = Close[i];
             }  
         }
       //----
       if(KagiBuffShift > 0)
         {
           if(KagiBuff[KagiBuffShift] > KagiBuff[KagiBuffShift-1])
             {
               if(Close[i] > KagiBuff[KagiBuffShift])
                 {
                   KagiBuff[KagiBuffShift] = Close[i];
                 }    
               //----
               if(Close[i] <= KagiBuff[KagiBuffShift] - Porog1*Point)
                 {
                   KagiBuffShift++;
                   KagiBuff[KagiBuffShift] = Close[i];
                 }  
             } 
           //----
           if(KagiBuff[KagiBuffShift] < KagiBuff[KagiBuffShift-1])
             {
               if(Close[i] < KagiBuff[KagiBuffShift])
                 {
                   KagiBuff[KagiBuffShift] = Close[i];
                 }
               //----
               if(Close[i] >= KagiBuff[KagiBuffShift] + Porog1*Point)
                 {
                   KagiBuffShift++;
                   KagiBuff[KagiBuffShift] = Close[i];
                 }   
             }
         }   
     }
//---- Ðèñóåì ãðàôèê
   for(i = 0; i < Bars; i++)
     {
       ExtMapBuffer1[i] = 0;
       ExtMapBuffer2[i] = 0;
     } 
//----
   if(Size == 1234567890)
     {
       Alert(A12());
       return(0);
     }   
//----
   if(Size < 51 && Size > 2)
       size1 = Size; 
   else 
     {
       if(Size < 3)
           size1 = 3;
       //----
       if(Size > 50)
           size1 = 50;   
     }   
//----
   for(i = 0; i <= KagiBuffShift; i++)
     {
       for(j = 0; j < size1; j++)
         {
           ExtMapBuffer1[(KagiBuffShift-i)*size1-j] = KagiBuff[i]; 
         }   
     }    
//----
   if(KagiBuff[0] < KagiBuff[1])
     {
       Ind = 1;
     }
   else
     {
       Ind = 2;
     }     
   for(i = 0; i < 2; i++)
     {
       for(j = 0; j < size1; j++)
         {
           if(Ind == 1)
             {
               ExtMapBuffer2[(KagiBuffShift-i)*size1-j] = KagiBuff[i];
             }
           if(Ind == 2)
             {
               ExtMapBuffer1[(KagiBuffShift-i)*size1-j] = KagiBuff[i];
             }  
         }
     }
   for(i = 2; i <= KagiBuffShift; i++)
     {   
       if(Ind == 2 && KagiBuff[i] > KagiBuff[i-1] && KagiBuff[i] > KagiBuff[i-2])
         {
           ExtMapBuffer2[(KagiBuffShift-i)*size1+1] = KagiBuff[i-2];
           Ind = 1;
         }    
       if(Ind == 1 && KagiBuff[i] < KagiBuff[i-1] && KagiBuff[i] < KagiBuff[i-2])
         { 
           ExtMapBuffer2[(KagiBuffShift-i)*size1] = KagiBuff[i-2];
           Ind = 2; 
         }
       if(Ind == 1)
         {
          for(j = 0; j < size1; j++)
            {
              ExtMapBuffer2[(KagiBuffShift-i)*size1-j] = KagiBuff[i];  
            }
         }      
     }    
   return(0);
  }
//+------------------------------------------------------------------+

Comments