_iGDR_FL
Download scriptThis script is designed to identify and visualize significant price levels on a trading chart by analyzing historical price patterns. It specifically focuses on identifying "Fractals"—which are structural peaks and valleys in price action—and then determines which of these points represent the most influential support and resistance zones.
How the Logic Works
1. Pattern Identification (Fractal Detection) The script scans the recent price history to find specific geometric patterns. It looks for "peaks" (highs) and "valleys" (lows). You can choose between two types of detection:
- Strict: A peak is only counted if it is strictly higher than all neighboring bars within a user-defined range.
- Non-Strict: A peak is counted if it is simply higher than the center bar in that range, allowing for more frequent signals.
2. Data Filtering and Storage Once the script identifies these peaks and valleys, it compiles them into a list. To ensure the analysis remains relevant to current market conditions, it focuses on a specific number of recent bars (defaulting to 480) and limits the total number of unique points it tracks.
3. Dynamic Error Margin Calculation Instead of using a fixed distance to determine what counts as a "level," the script automatically calculates the average height of the candles in the current market. It uses this average to set a dynamic "error margin." This ensures that if the market volatility increases or decreases, the logic adjusts accordingly to group nearby prices together correctly.
4. Density Rating (Significance Scoring) This is the core intelligence of the script. It compares every identified fractal point against every other point in the list.
- If two points are very close to each other (within the calculated error margin), they are considered part of the same "zone."
- The script assigns a score based on how many other points cluster around a specific price. A high score indicates a "heavy" zone where the price has interacted frequently in the past.
5. Ranking and Visualization Finally, the script extracts the top three most significant levels from its data:
- It selects the three highest-scoring clusters regardless of whether they are peaks or valleys.
- It draws these levels on your chart as visual channels and trend lines.
- Each level is assigned a unique color for easy identification.
- It provides an on-screen text summary detailing how many fractals were found, the coordinates of the strongest three levels, and the specific point margin used for the calculation.
// Indicators Pack - Green Digger Reseach
//+------------------------------------------------------------------+
//| [IP-GDR] Fractal Levels |
//| Copyright © 2008-2009, GreenDog, Russia |
//| krot@inbox.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008-2009, GreenDog"
#property link "krot@inbox.ru"
#property indicator_chart_window
extern int frNum = 2; // êîëè÷åñòâî áàðîâ ôðàêòàëà, 2=5-áàðíûé ôðàêòàë, 3=7-áàðíûé è òä
extern int frType = 1; // òèï îïðåäåëåíèÿ ôðàêòàëà 0=ñòðîãèé, 1=íåñòðîãèé
extern int frMode = 0; // ðåæèìû - MODE_LOW(1)=Sup, MODE_HIGH(2)=Res, 0=S&R
extern double dlt = 0.24; // ïîãðåøíîñòü îò ñðåäåé âûñîòû áàðîâ
extern int sBars = 480; // êîëè÷åñòâî áàðîâ, îäíàêî îáðàáàòûâàåòñÿ íå áîëåå 200
bool Go = true;
int lastBars=0,lastTime=0;
double aData[240][2],aRes[3][2];
int aCol[6]={MistyRose, OldLace, Honeydew, Red, Gold, Green};
int init(){
if (frNum!=0 && frNum<2) { Go=false; return(-1); }
if (sBars!=0 && sBars<frNum*10) { Go=false; return(-1); }
if (sBars==0) sBars=Bars;
return(0);
}
int deinit(){
Comment("");
for(int i=0;i<3;i++){
string name="IPGDR_Lv"+i; ObjectDelete(name);
name=name+"Up"; ObjectDelete(name);
name=name+"Dw"; ObjectDelete(name);
name=name+"Tx"; ObjectDelete(name);
}
}
int start(){
if (!Go) { Comment("Íåêîððåêòíûå ïàðàìåòðû èíäèêàòîðà!"); return(-1); }
if (Bars<sBars) { Comment("Íåäîñòàòî÷íî áàðîâ íà ãðàôèêå!"); return(0); }
if (Bars==lastBars) return(0); // ñ÷èòàåì òîêà â íà÷àëå áàðà
lastBars=Bars;
// èùåì ôðàêòàëû, çàíîñèì èõ â ìàññèâ, íî íå áîëåå äîïóñòèìîãî êîëè÷åñòâà
int sh=0; ArrayInitialize(aData,0);
double lastExt=0;
for(int i=frNum+1;i<sBars-2*frNum;i++){
if (frMode!=MODE_LOW && upFrac(i)) { // äîáàâëÿåì âåðøèíû [êðîìå ðåæèìà âïàäèí]
// ïðè íåñòðîãîì óñëîâèè ïðîïóñêàåì äóáëèðóþùèå ñîñåäíèå âåðøèíû
if (!(frType!=0 && lastExt>0 && lastExt==High[i])){
aData[sh][0]=High[i]; lastExt=High[i]; sh++;
}
}
if (sh>=240) break;
if (frMode!=MODE_HIGH && dwFrac(i)) { // äîáàâëÿåì âïàäèíû [êðîìå ðåæèìà âåðøèí]
// ïðè íåñòðîãîì óñëîâèè ïðîïóñêàåì äóáëèðóþùèå ñîñåäíèå âïàäèíû
if (!(frType!=0 && lastExt>0 && lastExt==Low[i])){
aData[sh][0]=Low[i]; lastExt=Low[i]; sh++;
}
}
if (sh>=240) break;
}
// îïðåäåëÿåì ñðåäíèé ðàçìàõ ñâå÷ è ñîîòâ äîïóñê
double sHL=0; for(i=1;i<=sBars;i++) sHL=sHL+(High[i]-Low[i]); sHL=sHL/sBars; dlt=sHL*dlt;
// îïðåäåëÿåì ðåéòèíãè äëÿ êàæäîãî óðîâíÿ
for(i=0;i<sh;i++){
for(int j=i+1;j<sh;j++){
if (aData[j][0]>aData[i][0]-dlt && aData[j][0]<aData[i][0]+dlt) {
aData[i][1]=aData[i][1]+1; aData[j][1]=aData[j][1]+1;
}
}
}
// îïðåäåëÿåì òðè ñèëüíåéøèõ óðîâíÿ
double cur[2],tmp[2]; aRes[0][0]=aData[0][0]; aRes[0][1]=aData[0][1];
for(i=1;i<sh;i++){
cur[0]=aData[i][0]; cur[1]=aData[i][1];
if (cur[1]>aRes[0][1]) { // åñëè ðåéòèíã áîëüøå 1ãî ìåñòà, òî 1å ñòàíîâèöî òåêóùèì
tmp[0]=aRes[0][0]; tmp[1]=aRes[0][1]; aRes[0][0]=cur[0]; aRes[0][1]=cur[1]; cur[0]=tmp[0]; cur[1]=tmp[1];
}
// åñëè ðåéòèíã âûøå 2ãî ìåñòà è ïðè ýòîì íå ïðèíàäëåæèò 1ìó - çàìåùàåì 2å ìåñòî
if (cur[1]>aRes[1][1] && (cur[0]<aRes[0][0]-dlt || cur[0]>aRes[0][0]+dlt)) {
tmp[0]=aRes[1][0]; tmp[1]=aRes[1][1]; aRes[1][0]=cur[0]; aRes[1][1]=cur[1]; cur[0]=tmp[0]; cur[1]=tmp[1];
}
// åñëè ðåéòèíã âûøå 3ãî ìåñòà è ïðè ýòîì íå ïðèíàäëåæèò 1ìó è 2ìó - çàìåùàåì 3å ìåñòî
if (cur[1]>aRes[2][1] && (cur[0]<aRes[0][0]-dlt || cur[0]>aRes[0][0]+dlt) && (cur[0]<aRes[1][0]-dlt || cur[0]>aRes[1][0]+dlt)) {
aRes[2][0]=cur[0]; aRes[2][1]=cur[1];
}
}
// îòðèñîâûâàåì ñèëüíûå óðîâíè
for(i=0;i<3;i++){
double dwL=aRes[i][0]-dlt, upL=aRes[i][0]+dlt;
string name="IPGDR_Lv"+i;
ObjectCreate(name,OBJ_CHANNEL,0,Time[24],upL,Time[1],upL,Time[24],dwL);
ObjectSet(name,OBJPROP_COLOR,aCol[i]); ObjectSet(name,OBJPROP_BACK,true); ObjectSet(name,OBJPROP_RAY,true);
name=name+"Up";
ObjectCreate(name,OBJ_TREND,0,Time[24],upL,Time[1],upL);
ObjectSet(name,OBJPROP_COLOR,aCol[i+3]); ObjectSet(name,OBJPROP_RAY,true);
name=name+"Dw";
ObjectCreate(name,OBJ_TREND,0,Time[24],dwL,Time[1],dwL);
ObjectSet(name,OBJPROP_COLOR,aCol[i+3]); ObjectSet(name,OBJPROP_RAY,true);
name=name+"Tx";
ObjectCreate(name,OBJ_TEXT,0,Time[32],upL+2*Point);
ObjectSetText(name,DoubleToStr(aRes[i][0],Digits),14,"tahoma",aCol[i+3]);
}
// âûâîäèì êîììåíòàðèè
string rem="";
if (frType==1) rem=rem+"Êëàññè÷åñêèå "; else rem=rem+"Ñòðîãèå ";
rem=rem+(frNum*2+1)+"-áàðíûå ôðàêòàëû";
if (frMode==MODE_LOW) rem=rem+", âïàäèíû"; else if (frMode==MODE_LOW) rem=rem+", âåðøèíû";
rem=rem+"\nÍàéäåíî "+(sh)+" ôðàêòàëà(îâ) \nÍàèáîëåå ñèëüíûå óðîâíè ";
rem=StringConcatenate(rem,aRes[0][0],"[",aRes[0][1],"], ",aRes[1][0],"[",aRes[1][1],"], ",aRes[2][0],"[",aRes[2][1],
"], ïîãðåøíîñòü ±",NormalizeDouble(dlt/Point,1)," ïóíêòà(îâ)");
Comment(rem);
return(0);
}
bool upFrac(int cnt){
for(int i=1;i<=frNum;i++){
if (frType==0) { // åñëè ñòðîãîå óñëîâèå è ïîñò èëè ïðåä áàðû âûøå-ðàâíû ñîñåäà - íåò ôðàêòàëà
if (High[cnt+i]>=High[cnt+i-1] || High[cnt-i]>=High[cnt-i+1]) return(false);
}
else { // åñëè íåñòðîãîå óñëîâèå è ïîñò èëè ïðåä áàðû âûøå öåíòðà - íåò ôðàêòàëà
if (High[cnt+i]>High[cnt] || High[cnt-i]>High[cnt]) return(false);
}
}
return(true);
}
bool dwFrac(int cnt){
for(int i=1;i<=frNum;i++){
if (frType==0) { // åñëè ñòðîãîå óñëîâèå è ïîñò èëè ïðåä áàðû íèæå-ðàâíû ñîñåäà - íåò ôðàêòàëà
if (Low[cnt+i]<=Low[cnt+i-1] || Low[cnt-i]<=Low[cnt-i+1]) return(false);
}
else { // åñëè íåñòðîãîå óñëîâèå è ïîñò èëè ïðåä áàðû íèæå öåíòðà - íåò ôðàêòàëà
if (Low[cnt+i]<Low[cnt] || Low[cnt-i]<Low[cnt]) return(false);
}
}
return(true);
}
Comments