Ind_VilkaFractals_v1.2
Download scriptThis script is a specialized technical analysis tool designed for the MetaTrader 4 platform. It automates the detection and visual mapping of specific price action patterns based on the "Vilka Khvashova" trading strategy.
Core Functionality
The primary purpose of this script is to identify "Fractals"—specific peaks and valleys in price movement—and use them to detect potential trend reversals or significant market shifts. Instead of just marking these points, the script performs an active analysis of how these fractals relate to one another chronologically.
How the Logic Works
The script operates through several distinct layers of logic:
1. Fractal Detection The tool constantly scans the price history to find "Upper" and "Lower" Fractals. These represent local highs and lows where the price has moved significantly in one direction before pivoting.
2. Pattern Recognition (The "Vilka" Logic) Rather than alerting on every single fractal, the script looks for a specific geometric relationship between three consecutive points:
- For Upward Patterns: It tracks a sequence of high points. If it identifies a specific downward slope across these points, it interprets this as a potential signal.
- For Downward Patterns: It tracks a sequence of low points. If it identifies a specific upward slope across these points, it interprets this as a potential signal.
3. Visual Mapping and Dynamics When the script identifies a qualifying pattern, it dynamically draws trend lines on your chart:
- Dynamic Drawing: It creates horizontal/trend segments to connect the relevant fractal points, helping you see the "structure" of the move visually.
- Real-time Validation: The script monitors these lines as they form. If the price action subsequently invalidates the pattern (moves against the expected direction), the script automatically removes the drawn lines to keep your chart clean and accurate.
- Memory Management: To ensure the platform remains fast, the script limits the number of visible lines on the screen, removing the oldest ones as new ones are created.
4. User Notifications For active traders, the script includes an alert system. When a valid "Vilka" pattern is confirmed by the logic, it triggers a real-time notification on your screen, providing the specific symbol and time of the occurrence.
Summary of Features
- Visual Clarity: Uses different colors (typically Blue for upward structures and Red for downward) to distinguish between market movements.
- Automatic Cleanup: Automatically deletes old objects and removes "broken" patterns that no longer meet the strategy's criteria.
- Customizable Visibility: Allows users to toggle fractal symbols on/off and set the specific number of lines they wish to see on their workspace.
//+------------------------------------------------------------------+
//| Ind_VilkaFractals_v1.2.mq4 |
//| Copyright © 2009, Alexey Sleptsov (lekhach) |
//| lekhach18@rambler.ru |
//+------------------------------------------------------------------+
// Èíäèêàòîð ðàáîòàåò ïî ñòðàòåãèè "Âèëêà ×óâàøîâà".
// Âåðñèÿ 1.2:
// 1. Äîáàâëåíà ôóíêöèÿ óäàëåíèÿ îáúåêòîâ ïðè âûãðóçêå èíäèêàòîðà.
// 2. Óäàëåíû ëèøíèå ñòðîêè èç êîäà.
// 3. Ïåðåäåëàí Alert.
// 4. Äîáàâëåí FractalsTrue.
//--------------------------------------------------------------------
#property copyright "lekhach © 2009"
#property link "lekhach18@rambler.ru"
//--------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1
//---- input parameters
extern int Lines=20; // Êîëè÷åñòâî âèäèìûõ/íåâèäèìûõ ôðàêòàëüíûõ ëèíèé
extern bool FractalsTrue=true; // Âêë/âûêë çíà÷êîâ ôðàêòàëîâ
extern bool AlertTrue=true; // Âêë/âûêë ñèãíàëà
extern color LinesColorUp=Blue; // Öâåò âåðõíèõ ôðàêòàëüíûõ ëèíèé
extern color LinesColorDown=Red; // Öâåò íèæíèõ ôðàêòàëüíûõ ëèíèé
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//--- my variables
int Up=0;
int BufUp=0;
int Down=0;
int BufDown=0;
double BufPriceUp[100000];
double BufDateUp[100000];
double BufPriceDown[100000];
double BufDateDown[100000];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,217);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,218);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(1,0.0);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("Fractals");
SetIndexLabel(0,"FractalsUp");
SetIndexLabel(1,"FractalsDown");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
for (int j=0; j<100000; j++)
{
ObjectDelete("LineUp"+j);
ObjectDelete("LineDown"+j);
}
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit;
//---- Ïîñëåäíèé ïîñ÷èòàííûé áàð áóäåò ïåðåñ÷èòàí
if (counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- Îñíîâíîé öèêë
for (int i=limit; i>2; i--)
{
if (FractalsTrue==true)
{
ExtMapBuffer1[i]=iFractals(NULL,0,MODE_UPPER,i);
ExtMapBuffer2[i]=iFractals(NULL,0,MODE_LOWER,i);
}
//---- Áëîê Up-ôðàêòàëîâ
if (iFractals(NULL,0,MODE_UPPER,i)!=0)
{
Up++;
BufPriceUp[Up]=iFractals(NULL,0,MODE_UPPER,i);
BufDateUp[Up]=Time[i];
if (Up>2 && Up-BufUp>1 && BufPriceUp[Up]<BufPriceUp[Up-1] && BufPriceUp[Up-1]<BufPriceUp[Up-2])
{
BufUp=Up;
ObjectCreate("LineUp"+(Up-1),OBJ_TREND,0,BufDateUp[Up-1],BufPriceUp[Up-1],BufDateUp[Up],BufPriceUp[Up]);
ObjectCreate("LineUp"+Up,OBJ_TREND,0,BufDateUp[Up-2],BufPriceUp[Up-2],BufDateUp[Up-1],BufPriceUp[Up-1]);
if (ObjectGetValueByShift("LineUp"+Up,i-1)>ObjectGetValueByShift("LineUp"+(Up-1),i-1))
{
ObjectDelete("LineUp"+Up);
ObjectDelete("LineUp"+(Up-1));
}
else if (AlertTrue==true) Alert(Symbol(),Period()," Íèçõîäÿùàÿ âèëêà! ",TimeToStr(Time[i],TIME_DATE|TIME_SECONDS));
}
ObjectSet("LineUp"+(Up-1),OBJPROP_COLOR,LinesColorUp);
ObjectSet("LineUp"+(Up-1),OBJPROP_WIDTH,2);
ObjectSet("LineUp"+(Up-1),OBJPROP_RAY,True);
ObjectSet("LineUp"+Up,OBJPROP_COLOR,LinesColorUp);
ObjectSet("LineUp"+Up,OBJPROP_WIDTH,2);
ObjectSet("LineUp"+Up,OBJPROP_RAY,True);
if (Up>Lines+1) ObjectDelete("LineUp"+(Up-Lines-1));
}
//---- Áëîê Down-ôðàêòàëîâ
if (iFractals(NULL,0,MODE_LOWER,i)!=0)
{
Down++;
BufPriceDown[Down]=iFractals(NULL,0,MODE_LOWER,i);
BufDateDown[Down]=Time[i];
if (Down>2 && Down-BufDown>1 && BufPriceDown[Down]>BufPriceDown[Down-1] && BufPriceDown[Down-1]>BufPriceDown[Down-2])
{
BufDown=Down;
ObjectCreate("LineDown"+(Down-1),OBJ_TREND,0,BufDateDown[Down-1],BufPriceDown[Down-1],BufDateDown[Down],BufPriceDown[Down]);
ObjectCreate("LineDown"+Down,OBJ_TREND,0,BufDateDown[Down-2],BufPriceDown[Down-2],BufDateDown[Down-1],BufPriceDown[Down-1]);
if (ObjectGetValueByShift("LineDown"+Down,i-1)<ObjectGetValueByShift("LineDown"+(Down-1),i-1))
{
ObjectDelete("LineDown"+Down);
ObjectDelete("LineDown"+(Down-1));
}
else if (AlertTrue==true) Alert(Symbol(),Period()," Âîñõîäÿùàÿ âèëêà! ",TimeToStr(Time[i],TIME_DATE|TIME_SECONDS));
}
ObjectSet("LineDown"+(Down-1),OBJPROP_COLOR,LinesColorDown);
ObjectSet("LineDown"+(Down-1),OBJPROP_WIDTH,2);
ObjectSet("LineDown"+(Down-1),OBJPROP_RAY,True);
ObjectSet("LineDown"+Down,OBJPROP_COLOR,LinesColorDown);
ObjectSet("LineDown"+Down,OBJPROP_WIDTH,2);
ObjectSet("LineDown"+Down,OBJPROP_RAY,True);
if (Down>Lines+1) ObjectDelete("LineDown"+(Down-Lines-1));
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments