olyakish_fractals_06
Download scriptThis script is designed to analyze market price action by identifying specific types of "fractals"—which are essentially peaks and valleys in a chart—and categorizing them based on trading volume and momentum. It then visualizes these points with dynamic lines to help traders identify significant structural levels.
Core Logic and Functionality
Fractal Identification and Classification The script scans historical price data to find high and low points (fractals). Unlike standard fractal indicators that simply mark every peak, this script categorizes them into four distinct types based on a comparison between the current fractal and the previous one:
- Green Fractals: Occur when there is a significant increase in volume and positive momentum.
- Red Fractals: Occur when there is a significant increase in volume but negative momentum.
- Fading (SaddleBrown) Fractals: Occur when volume decreases and momentum is negative.
- Blue Fractals: Occur when volume decreases but momentum remains positive.
Technical Filters To ensure the data is meaningful, the script uses two primary filters:
- Volume Percentage: A user-defined threshold determines how much the trading volume must change to qualify a fractal for a specific category.
- Momentum Analysis (MFI): The script calculates a momentum value by looking at the range of price movement relative to the volume. This allows the tool to distinguish between "strong" and "weak" price moves.
Dynamic Visualizations The script translates these calculations into visual aids on the chart:
- Trend Lines: Based on your selection, it draws trend lines connecting these specific fractal types. You can choose which category (e.g., only Green, or only Red) to visualize at any given time.
- Historical Tracking: There is an option to display "Old Lines." This allows you to see the previous price levels alongside current ones, providing a clearer picture of how support and resistance have shifted over time.
- Auto-Adjustment: The script automatically manages the movement of these lines as new data points appear, keeping the most relevant structural levels at the forefront of the view.
User Customization The logic allows for high flexibility through several adjustable parameters:
- Bars in Fractal: Defines how many bars are looked at to confirm a peak or valley.
- Shift Bars: Limits how far back into history the script calculates data.
- Pips Offset: Controls the distance between the price action and the drawn lines for better visibility.
//+------------------------------------------------------------------+
//| v04 |
//| |
//| v02 |
//| Äîáàâëåí ïðîöåíò äëÿ îòñåèâàíèÿ ôðàêòàëîâ |
//| v03 |
//| Ðèñóåò ëèíèè |
//| v04 |
//| Ôèëüòð äëÿ ëèíèé ïî àëëèãàòîðó |
//| v05 |
//| âûáîð âàðèàíòà ïîñòðîåíèÿ ëèíèé |
//| v06 |
//| âûáîð êîëè÷åñòâà áàðîâ â ôðàêòàëå |
//+------------------------------------------------------------------+
#property copyright "by olyakish"
#property link ""
//----
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Lime //Çåëåíûé ôðàêòàë
#property indicator_color2 Red // Ïðèñåäàþùèé
#property indicator_color3 SaddleBrown //Óâÿäàþùèé
#property indicator_color4 Blue // Ôàëüøèâûé
//----
extern int Pips = 15;
extern int ShiftBars = 1000;
extern string rem0="Êîëè÷åñòâî áàðîâ â ôðàêòàëå";
extern int BarsInFractal = 11;
extern string rem1="Ïðîöåíò äëÿ îòñåèâàíèÿ ïî îáúåìó";
extern int Percent=110;
extern string rem2="Ðèñîâàòü ïðåäûäóùèå ëèíèè?";
extern bool UseOldLine=true;
extern string rem3="Ïî êàêèì ôðàêòàëàì ðèñóåì ëèíèè";
extern string rem4="0-çåëåíûå,1-ïðèñåäàþùèå";
extern string rem5="2-óâÿäàþùèå,3-ôàëüøèâûå";
extern int FractalLines=1;
double ExtLimeBuffer[];
double ExtRedBuffer[];
double ExtSaddleBrownBuffer[];
double ExtBlueBuffer[];
int i,j,z;
double a_Fractal[2]; // 0- ïîñëåäíèé 1-ïðåäûäóùèé
double a_MFI[2]; // 0- ïîñëåäíèé 1-ïðåäûäóùèé
double a_Volume[2]; // 0- ïîñëåäíèé 1-ïðåäûäóùèé
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
int test;
test=BarsInFractal/2;
if (test*2==BarsInFractal){Alert("Çíà÷åíèå BarsInFractal äîëæíî áûòü íå÷åòíûì");deinit();}
if (BarsInFractal<3){Alert("Çíà÷åíèå BarsInFractal äîëæíî áûòü >=3");deinit();}
SetIndexShift(0,0);
SetIndexShift(1,0);
SetIndexShift(2,0);
SetIndexShift(3,0);
//----
SetIndexBuffer(0, ExtLimeBuffer);
SetIndexBuffer(1, ExtRedBuffer);
SetIndexBuffer(2, ExtSaddleBrownBuffer);
SetIndexBuffer(3, ExtBlueBuffer);
//----
SetIndexStyle(0, DRAW_ARROW );
SetIndexStyle(1, DRAW_ARROW);
SetIndexStyle(2, DRAW_ARROW);
SetIndexStyle(3, DRAW_ARROW);
SetIndexArrow(0,177);
SetIndexArrow(1,177);
SetIndexArrow(2,177);
SetIndexArrow(3,177);
///----
SetIndexLabel(0, "Çåëåíûé ôðàêòàë");
SetIndexLabel(1, "Ïðèñåäàþùèé ôðàêòàë");
SetIndexLabel(2, "Óâÿäàþùèé ôðàêòàë");
SetIndexLabel(3, "Ôàëüøèâûé ôðàêòàë");
//----
ObjectCreate("Up",OBJ_TREND,0,iTime(NULL, 0, 2),High[2],iTime(NULL, 0, 1),High[1],0,0);
ObjectSet("Up",OBJPROP_COLOR,Aqua);
ObjectSet("Up",OBJPROP_RAY,true);
ObjectSet("Up",OBJPROP_BACK,1);
ObjectCreate("Down",OBJ_TREND,0,iTime(NULL, 0, 2),Low[2],iTime(NULL, 0, 1),Low[1],0,0);
ObjectSet("Down",OBJPROP_COLOR,Tomato);
ObjectSet("Down",OBJPROP_RAY,true);
ObjectSet("Down",OBJPROP_BACK,1);
if (UseOldLine)
{
ObjectCreate("Up_Prev",OBJ_TREND,0,iTime(NULL, 0, 2),High[2],iTime(NULL, 0, 1),High[1],0,0);
ObjectSet("Up_Prev",OBJPROP_COLOR,Aqua);
ObjectSet("Up_Prev",OBJPROP_RAY,true);
ObjectSet("Up_Prev",OBJPROP_STYLE,STYLE_DASH);
ObjectSet("Up_Prev",OBJPROP_BACK,1);
ObjectCreate("Down_Prev",OBJ_TREND,0,iTime(NULL, 0, 2),Low[2],iTime(NULL, 0, 1),Low[1],0,0);
ObjectSet("Down_Prev",OBJPROP_COLOR,Tomato);
ObjectSet("Down_Prev",OBJPROP_RAY,true);
ObjectSet("Down_Prev",OBJPROP_STYLE,STYLE_DASH);
ObjectSet("Down_Prev",OBJPROP_BACK,1);
}
//----
return(0);
}
int deinit()
{
ObjectDelete("Up");
ObjectDelete("Down");
if (UseOldLine)
{
ObjectDelete("Up_Prev");
ObjectDelete("Down_Prev");
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int n=BarsInFractal;
while (ExtLimeBuffer[n]!=NULL || ExtRedBuffer[n]!=NULL || ExtSaddleBrownBuffer[n]!=NULL || ExtBlueBuffer[n]!=NULL)
{
if (n>ShiftBars) {n=ShiftBars;break;}
n++;
}
for(int i=n+20; i>=(BarsInFractal/2+1); i--)
{
//-- âåðõíèå ôðàêòàëû
ArrayInitialize(a_Fractal,0);
ArrayInitialize(a_MFI,0);
ArrayInitialize(a_Volume,0);
if (High[i]==High[iHighest(Symbol(),0,MODE_HIGH,BarsInFractal,i-BarsInFractal/2)]) // íà i áàðå åñòü ôðàêòàë ââåðõ
{
a_Fractal[0]=High[i]; // öåíà íà ôðàêòàëå
for (z=i-BarsInFractal/2;z<=i-BarsInFractal/2+BarsInFractal;z++){a_Volume[0]+=Volume[z];} // îáúåì
for (z=i-BarsInFractal/2;z<=i-BarsInFractal/2+BarsInFractal;z++){a_MFI[0]+=High[z]-Low[z];}
a_MFI[0]=a_MFI[0]/a_Volume[0];
// ïîøëè èñêàòü ôðàêòàë íà âíèç ïî èñòîðèè
j=i+1;
while (a_Fractal[1]==0 && j<Bars)
{
if (High[j]==High[iHighest(Symbol(),0,MODE_HIGH,BarsInFractal,j-BarsInFractal/2)]) {break;} // íàøëè íî íå òîò (òîæå ââåðõ)
if (Low[j]==Low[iLowest(Symbol(),0,MODE_LOW,BarsInFractal,j-BarsInFractal/2)]) //-- Íàøëè ôðàêòàë âíèç
{
a_Fractal[1]=Low[j];
for (z=j-BarsInFractal/2;z<=j-BarsInFractal/2+BarsInFractal;z++){a_Volume[1]+=Volume[z];} // îáúåì
for (z=j-BarsInFractal/2;z<=j-BarsInFractal/2+BarsInFractal;z++){a_MFI[1]+=High[z]-Low[z];}
a_MFI[1]=a_MFI[1]/a_Volume[1];
if (a_Volume[0]>a_Volume[1]*Percent/100 && a_MFI[0]<a_MFI[1]){ExtRedBuffer[i]=High[i]+Pips*Point;break;} // èìååì ïðèñåäàþùèé ôðàêòàë (MFI - îáúåì +)
if (a_Volume[0]>a_Volume[1]*Percent/100 && a_MFI[0]>a_MFI[1]){ExtLimeBuffer[i]=High[i]+Pips*Point;break;} // èìååì çåëåíûé ôðàêòàë (MFI + îáúåì +)
if (a_Volume[0]*Percent/100<a_Volume[1] && a_MFI[0]>a_MFI[1]){ExtBlueBuffer[i]=High[i]+Pips*Point;break;} // èìååì ôàëüøèâûé ôðàêòàë (MFI + îáúåì -)
if (a_Volume[0]*Percent/100<a_Volume[1] && a_MFI[0]<a_MFI[1]){ExtSaddleBrownBuffer[i]=High[i]+Pips*Point;break;} // èìååì óâÿäàþùèé ôðàêòàë (MFI - îáúåì -)
}
j++;
}
}
//--- íèæíèå ôðàêòàëû
ArrayInitialize(a_Fractal,0);
ArrayInitialize(a_MFI,0);
ArrayInitialize(a_Volume,0);
if (Low[i]==Low[iLowest(Symbol(),0,MODE_LOW,BarsInFractal,i-BarsInFractal/2)]) // íà i áàðå åñòü ôðàêòàë âíèç
{
a_Fractal[0]=Low[i]; // öåíà íà ôðàêòàëå
for (z=i-BarsInFractal/2;z<=i-BarsInFractal/2+BarsInFractal;z++){a_Volume[0]+=Volume[z];} // îáúåì
for (z=i-BarsInFractal/2;z<=i-BarsInFractal/2+BarsInFractal;z++){a_MFI[0]+=High[z]-Low[z];}
a_MFI[0]=a_MFI[0]/a_Volume[0];
// ïîøëè èñêàòü ôðàêòàë íà ââåðõ ïî èñòîðèè
j=i+1;
while (a_Fractal[1]==0 && j<Bars)
{
if (Low[j]==Low[iLowest(Symbol(),0,MODE_LOW,BarsInFractal,j-BarsInFractal/2)]) {break;}
if (High[j]==High[iHighest(Symbol(),0,MODE_HIGH,BarsInFractal,j-BarsInFractal/2)]) //-- Íàøëè ôðàêòàë ââåðõ
{
a_Fractal[1]=High[j];
for (z=j-BarsInFractal/2;z<=j-BarsInFractal/2+BarsInFractal;z++){a_Volume[1]+=Volume[z];} // îáúåì
for (z=j-BarsInFractal/2;z<=j-BarsInFractal/2+BarsInFractal;z++){a_MFI[1]+=High[z]-Low[z];}
a_MFI[1]=a_MFI[1]/a_Volume[1];
if (a_Volume[0]>a_Volume[1]*Percent/100 && a_MFI[0]<a_MFI[1]){ExtRedBuffer[i]=Low[i]-Pips*Point;break;} // èìååì ïðèñåäàþùèé ôðàêòàë (MFI - îáúåì +)
if (a_Volume[0]>a_Volume[1]*Percent/100 && a_MFI[0]>a_MFI[1]){ExtLimeBuffer[i]=Low[i]-Pips*Point;break;} // èìååì çåëåíûé ôðàêòàë (MFI + îáúåì +)
if (a_Volume[0]*Percent/100<a_Volume[1] && a_MFI[0]>a_MFI[1]){ExtBlueBuffer[i]=Low[i]-Pips*Point;break;} // èìååì ôàëüøèâûé ôðàêòàë (MFI + îáúåì -)
if (a_Volume[0]*Percent/100<a_Volume[1] && a_MFI[0]<a_MFI[1]){ExtSaddleBrownBuffer[i]=Low[i]-Pips*Point;break;} // èìååì óâÿäàþùèé ôðàêòàë (MFI - îáúåì -)
}
j++;
}
}
}
/// îòðèñîâêà ëèíèé
double _Price[3,2];
int _Time[3,2];
ArrayInitialize(_Price,-1);
ArrayInitialize(_Time,-1);
int up=0,down=0;
for(i=3; i<=ShiftBars; i++)
{
//up
// double iLips=iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORLIPS, i);
// double iTeeth=iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORTEETH, i);
// double iJaw=iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORJAW, i);
// ïî çåëåíûì
if (FractalLines==0)
{
if (ExtLimeBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_UPPER,i)!=NULL && up<=2 && iFractals(NULL,0,MODE_UPPER,i)<=ExtLimeBuffer[i])
// && iFractals(NULL,0,MODE_UPPER,i)>iLips && iFractals(NULL,0,MODE_UPPER,i)>iTeeth && iFractals(NULL,0,MODE_UPPER,i)>iJaw)
{
_Price[up,0]=ExtLimeBuffer[i];_Time[up,0]=iTime(NULL, 0, i);up++;
}
if (ExtLimeBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_LOWER,i)!=NULL && down<=2 && iFractals(NULL,0,MODE_LOWER,i)>=ExtLimeBuffer[i])
//&& iFractals(NULL,0,MODE_LOWER,i)<iLips && iFractals(NULL,0,MODE_LOWER,i)<iTeeth && iFractals(NULL,0,MODE_LOWER,i)<iJaw)
{
_Price[down,1]=ExtLimeBuffer[i];_Time[down,1]=iTime(NULL, 0, i);down++;
}
}
// ïî ïðèñåäàþùèì
if (FractalLines==1)
{
if (ExtRedBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_UPPER,i)!=NULL && up<=2 && iFractals(NULL,0,MODE_UPPER,i)<=ExtRedBuffer[i])
//&& iFractals(NULL,0,MODE_UPPER,i)>iLips && iFractals(NULL,0,MODE_UPPER,i)>iTeeth && iFractals(NULL,0,MODE_UPPER,i)>iJaw)
{
_Price[up,0]=ExtRedBuffer[i];_Time[up,0]=iTime(NULL, 0, i);up++;
}
if (ExtRedBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_LOWER,i)!=NULL && down<=2 && iFractals(NULL,0,MODE_LOWER,i)>=ExtRedBuffer[i])
//&& iFractals(NULL,0,MODE_LOWER,i)<iLips && iFractals(NULL,0,MODE_LOWER,i)<iTeeth && iFractals(NULL,0,MODE_LOWER,i)<iJaw)
{
_Price[down,1]=ExtRedBuffer[i];_Time[down,1]=iTime(NULL, 0, i);down++;
}
}
// ïî ôàëüøèâûì
if (FractalLines==2)
{
if (ExtSaddleBrownBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_UPPER,i)!=NULL && up<=2 && iFractals(NULL,0,MODE_UPPER,i)<=ExtSaddleBrownBuffer[i])
//&& iFractals(NULL,0,MODE_UPPER,i)>iLips && iFractals(NULL,0,MODE_UPPER,i)>iTeeth && iFractals(NULL,0,MODE_UPPER,i)>iJaw)
{
_Price[up,0]=ExtSaddleBrownBuffer[i];_Time[up,0]=iTime(NULL, 0, i);up++;
}
if (ExtSaddleBrownBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_LOWER,i)!=NULL && down<=2 && iFractals(NULL,0,MODE_LOWER,i)>=ExtSaddleBrownBuffer[i])
//&& iFractals(NULL,0,MODE_LOWER,i)<iLips && iFractals(NULL,0,MODE_LOWER,i)<iTeeth && iFractals(NULL,0,MODE_LOWER,i)<iJaw)
{
_Price[down,1]=ExtSaddleBrownBuffer[i];_Time[down,1]=iTime(NULL, 0, i);down++;
}
}
// ïî óâÿäàþùèì
if (FractalLines==3)
{
if (ExtBlueBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_UPPER,i)!=NULL && up<=2 && iFractals(NULL,0,MODE_UPPER,i)<=ExtBlueBuffer[i])
//&& iFractals(NULL,0,MODE_UPPER,i)>iLips && iFractals(NULL,0,MODE_UPPER,i)>iTeeth && iFractals(NULL,0,MODE_UPPER,i)>iJaw)
{
_Price[up,0]=ExtBlueBuffer[i];_Time[up,0]=iTime(NULL, 0, i);up++;
}
if (ExtBlueBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_LOWER,i)!=NULL && down<=2 && iFractals(NULL,0,MODE_LOWER,i)>=ExtBlueBuffer[i])
//&& iFractals(NULL,0,MODE_LOWER,i)<iLips && iFractals(NULL,0,MODE_LOWER,i)<iTeeth && iFractals(NULL,0,MODE_LOWER,i)<iJaw)
{
_Price[down,1]=ExtBlueBuffer[i];_Time[down,1]=iTime(NULL, 0, i);down++;
}
}
}
ObjectMove("Up",1,_Time[0,0],_Price[0,0]);
ObjectMove("Up",0,_Time[1,0],_Price[1,0]);
ObjectMove("Down",1,_Time[0,1],_Price[0,1]);
ObjectMove("Down",0,_Time[1,1],_Price[1,1]);
if (UseOldLine)
{
ObjectMove("Up_Prev",1,_Time[1,0],_Price[1,0]);
ObjectMove("Up_Prev",0,_Time[2,0],_Price[2,0]);
ObjectMove("Down_Prev",1,_Time[1,1],_Price[1,1]);
ObjectMove("Down_Prev",0,_Time[2,1],_Price[2,1]);
}
return(0);
}
//+------------------------------------------------------------------+
Comments