KAGI_1[1]
Download scriptThis script is designed for the MetaTrader platform to generate a specialized visual indicator known as "KAGI." Its primary purpose is to filter out market noise and provide a clearer view of price trends by focusing on significant movements rather than minor fluctuations.
Core Logic and Functionality
1. Trend Filtering and Thresholds The script operates based on user-defined sensitivity levels. You can choose to set these thresholds as either a fixed number of points (the smallest price movement) or as a percentage of the current price. This allows the indicator to remain consistent across different assets, whether you are trading high-value currencies or low-value stocks.
2. Price Movement Detection Instead of plotting every single price change, the logic monitors the closing prices of bars. It only "records" a new price point when the market moves by a distance that exceeds your specified threshold (the "Porog"). If the price fluctuates within that small range, the script ignores it, effectively smoothing out the visual representation of the market.
3. Directional Logic The indicator distinguishes between upward and downward trends based on these significant moves:
- Upward Trend: If the price moves up significantly beyond the previous recorded point, the indicator tracks the new high.
- Downward Trend: If the price drops significantly below the previous recorded point, it tracks the new low.
- Trend Persistence: While in a trend, the script will continue to update the current price point as long as it continues to move in that same direction (higher for up, lower for down). It only "locks" a new structural point when a significant reversal occurs.
4. Visual Smoothing and Representation The script includes a unique mechanism to handle how these points are displayed on your chart:
- Data Mapping: It takes the recorded "Kagi" points and expands them into a visual buffer. This creates a more substantial visual line rather than just a series of dots.
- Dynamic Rendering: It uses a "Size" parameter to determine how many horizontal units are used to represent each structural change. This helps in creating a distinct visual "staircase" effect, making it easier for the trader to identify support and resistance levels at a glance.
Summary for the User
Essentially, this script acts as a "noise filter." It cleans up the jagged movements of a standard price chart and replaces them with a simplified series of steps. When you see a step move up or down, it signifies that the market has moved enough to be considered a meaningful trend change, helping you identify the underlying direction of the market more effectively.
//+------------------------------------------------------------------+
//| 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 = 12;
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