1-3-6_v1
Download scriptThis script is designed to automatically identify and project specific price levels on a trading chart based on a sequence of user-defined price points. It uses a mathematical progression logic to determine where the market might move next, making it a tool for visual trend and level analysis.
Core Functionality
The script works by analyzing three primary price levels (Level 1, Level 2, and Level 3) that you provide as input. Based on these three points, the logic performs the following actions:
1. Trend Direction Detection
The tool first determines the "direction" of the market structure by comparing your three input levels. It identifies whether the price movement is behaving in an ascending or descending manner. This allows the script to automatically decide whether to look for new "Highs" or "Lows" as it calculates subsequent points.
2. Historical Point Identification
The script scans back through the historical price data to find the exact moments (time and price) where your three input levels were first touched. It then labels these on the chart as Points 1, 2, and 3.
3. Automated Level Projection (The "Chain" Logic)
This is the primary engine of the script. Once it understands the relationship between your first three points, it calculates a series of subsequent levels (Points 4, 5, and 6) using a specific mathematical ratio:
- Level 4: Calculated using a constant multiplier (1.62) applied to the distance between your initial points.
- Level 5 & 6: These are calculated dynamically based on the "True" price reached at Point 4. The script doesn't just draw these as static lines; it actively searches the chart to see where the price actually reacted relative to the projected targets.
4. Visual Feedback and Real-Time Tracking
- Dynamic Labeling: As the script finds these points, it places text labels on the chart (e.g., "1", "2", "3", etc.) so you can see exactly where each milestone occurred.
- Visual Guides: It draws horizontal lines representing both the "Ideal" targets (the mathematical prediction) and the "True" levels (the actual price where the market interacted).
- Information Dashboard: The script provides a text summary in the corner of the chart, listing the exact prices and dates for all six points, allowing you to track the progression of the price sequence at a glance.
Summary for the User
Essentially, you provide the "foundation" (the first three points), and the script uses a consistent mathematical formula to project the "extension" (points 4, 5, and 6). It handles the heavy lifting of calculating distances and searching through history to show you where the next logical price targets are located based on the established trend.
//+------------------------------------------------------------------+
//| maloma 4 vicont 1-2-3.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, maloma."
#property indicator_chart_window
//----
extern double level_1=1.2971;//1.2937;//1.2937;
extern double level_2=1.2694;//1.2725;//1.2630;
extern double level_3=1.2978;//1.2874;//1.2829;
/*
extern double level_1=1.2764;//1.2483;//1.2937;
extern double level_2=1.2668;//1.2641;//1.2630;
extern double level_3=1.2714;//1.2524;//1.2829;
*/
extern bool Show_etalon=true;
extern bool Show_target=true;
extern bool Show_true=true;
//----
double level_4=0; double level_5=0; double level_6=0; double level_t=0;
double etalon_4=0; double etalon_5=0; double etalon_6=0;
double true_4=0; double true_5=0; double true_6=0;
int index_1=0; int index_2=0; int index_3=0; int index_4=0; int index_5=0; int index_6=0;
int p2d=0; int p3d=0;
bool get_4=false; bool get_5=false; bool get_6=false;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
int i=0;
if (level_3>level_2 && level_1>level_2) {p3d=1; p2d=-1;}
if (level_3<level_2 && level_1<level_2) {p3d=-1; p2d=1;}
if (p3d==1)
{
while(index_3==0 && i<Bars)
{
if (High[i]==level_3) index_3=Time[i];
i++;}
while(index_2==0 && i<Bars)
{
if (Low[i]==level_2) index_2=Time[i];
i++;}
while(index_1==0 && i<Bars){
if (High[i]==level_1) index_1=Time[i];
i++;}
} else
if (p3d==-1)
{
while(index_3==0 && i<Bars){
if (Low[i]==level_3) index_3=Time[i];
i++;}
while(index_2==0 && i<Bars)
{
if (High[i]==level_2) index_2=Time[i];
i++;}
while(index_1==0 && i<Bars)
{
if (Low[i]==level_1) index_1=Time[i];
i++;}
}
CreateText("Point_3","3",index_3,level_3+50*Point*p3d,FireBrick);
CreateText("Point_2","2",index_2,level_2+50*Point*p2d,FireBrick);
CreateText("Point_1","1",index_1,level_1+50*Point*p3d,FireBrick);
//----
etalon_4=(level_3-(level_3-level_2)*1.62);
etalon_5=((level_3-(level_3-(level_3-(level_3-level_2)*1.62))/2)-(level_2-(level_3-(level_3-(level_3-(level_3-level_2)*1.62))/2)));
etalon_6=(((level_3-(level_3-level_2)*1.62)-((level_3-(level_3-level_2)*1.62)-((level_3-(level_3-(level_3-(level_3-level_2)*1.62))/2)-(level_2-(level_3-(level_3-(level_3-(level_3-level_2)*1.62))/2))))/2)-(level_1-((level_3-(level_3-level_2)*1.62)-((level_3-(level_3-level_2)*1.62)-((level_3-(level_3-(level_3-(level_3-level_2)*1.62))/2)-(level_2-(level_3-(level_3-(level_3-(level_3-level_2)*1.62))/2))))/2)));
//----
if (Show_etalon) CreateObj("Etalon_4",OBJ_HLINE,Time[0],etalon_4,SaddleBrown,STYLE_DASHDOT);
if (Show_etalon) CreateObj("Etalon_5",OBJ_HLINE,Time[0],etalon_5,Teal,STYLE_DASHDOT);
if (Show_etalon) CreateObj("Etalon_6",OBJ_HLINE,Time[0],etalon_6,Purple,STYLE_DASHDOT);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
if (ObjectFind("Point_1")==0) ObjectDelete("Point_1");
if (ObjectFind("Point_2")==0) ObjectDelete("Point_2");
if (ObjectFind("Point_3")==0) ObjectDelete("Point_3");
if (ObjectFind("Point_4")==0) ObjectDelete("Point_4");
if (ObjectFind("Point_5")==0) ObjectDelete("Point_5");
if (ObjectFind("Point_6")==0) ObjectDelete("Point_6");
if (ObjectFind("Etalon_4")==0) ObjectDelete("Etalon_4");
if (ObjectFind("Etalon_5")==0) ObjectDelete("Etalon_5");
if (ObjectFind("Etalon_6")==0) ObjectDelete("Etalon_6");
if (ObjectFind("Level_4")==0) ObjectDelete("Level_4");
if (ObjectFind("Level_5")==0) ObjectDelete("Level_5");
if (ObjectFind("Level_6")==0) ObjectDelete("Level_6");
if (ObjectFind("True_4")==0) ObjectDelete("True_4");
if (ObjectFind("True_5")==0) ObjectDelete("True_5");
if (ObjectFind("True_6")==0) ObjectDelete("True_6");
Comment ("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void find_4(int index, int dir)
{
int tBar=iBarShift(Symbol(),0,index,false)-1;
if (tBar<0) return(0);
level_4=(level_3-(level_3-level_2)*1.62);
if (Show_target) CreateObj("Level_4",OBJ_HLINE,Time[0],level_4,Gold,STYLE_DOT);
for(int cb=tBar;cb>=0;cb--)
{
if (dir==-1)
{
if (true_4==0) double level=level_4; else level=true_4;
if (Low[cb]<=level && get_4==false)
{
true_4=Low[cb];
index_4=Time[cb];
if (Show_true) CreateObj("True_4",OBJ_HLINE,Time[0],true_4,Gold,STYLE_DASH);
CreateText("Point_4","4",index_4,true_4+50*Point*p2d,Gold);
level_5=(level_3-(level_3-true_4)/2)-(level_2-(level_3-(level_3-true_4)/2));
if (Show_target) CreateObj("Level_5",OBJ_HLINE,Time[0],level_5,Aqua,STYLE_DOT);
}
if (true_4!=0 && cb>0)
if (level_5<=High[cb-1])
{
get_4=true;
find_5(index_4,p3d);
}
}
if (dir==1)
{
if (true_4==0) level=level_4; else level=true_4;
if (High[cb]>=level && get_4==false)
{
true_4=High[cb];
index_4=Time[cb];
if (Show_true) CreateObj("True_4",OBJ_HLINE,Time[0],true_4,Gold,STYLE_DASH);
CreateText("Point_4","4",index_4,true_4+50*Point*p2d,Gold);
level_5=(level_3-(level_3-true_4)/2)-(level_2-(level_3-(level_3-true_4)/2));
if (Show_target) CreateObj("Level_5",OBJ_HLINE,Time[0],level_5,Aqua,STYLE_DOT);
}
if (true_4!=0 && cb>0)
if (level_5>=Low[cb-1])
{
get_4=true;
find_5(index_4,p3d);
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void find_5(int index, int dir)
{
int tBar=iBarShift(Symbol(),0,index,false)-1;
if (tBar<0) return(0);
for(int cb=tBar;cb>=0;cb--)
{
if (dir==-1) {
if (true_5==0) double level=level_5; else level=true_5;
if (Low[cb]<=level && get_5==false)
{
true_5=Low[cb];
index_5=Time[cb];
if (Show_true) CreateObj("True_5",OBJ_HLINE,Time[0],true_5,Aqua,STYLE_DASH);
CreateText("Point_5","5",index_5,true_5+50*Point*p3d,Aqua);
level_6=(true_4-(true_4-true_5)/2)-(level_1-(true_4-(true_4-true_5)/2));
if (Show_target) CreateObj("Level_6",OBJ_HLINE,Time[0],level_6,Magenta,STYLE_DOT);
}
if (true_5!=0 && cb>0)
if (level_6<=High[cb-1])
{
get_5=true;
find_6(index_5,p2d);
}
}
if (dir==1)
{
if (true_5==0) level=level_5; else level=true_5;
if (High[cb]>=level && get_5==false)
{
true_5=High[cb];
index_5=Time[cb];
if (Show_true) CreateObj("True_5",OBJ_HLINE,Time[0],true_5,Aqua,STYLE_DASH);
CreateText("Point_5","5",index_5,true_5+50*Point*p3d,Aqua);
level_6=(true_4-(true_4-true_5)/2)-(level_1-(true_4-(true_4-true_5)/2));
if (Show_target) CreateObj("Level_6",OBJ_HLINE,Time[0],level_6,Magenta,STYLE_DOT);
}
if (true_5!=0 && cb>0)
if (level_6>=Low[cb-1])
{
get_5=true;
find_6(index_5,p2d);
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void find_6(int index, int dir)
{
int tBar=iBarShift(Symbol(),0,index,false)-1;
if (tBar<0) return(0);
for(int cb=tBar;cb>=0;cb--)
{
if (dir==-1)
{
if (true_6==0) double level=level_6; else level=true_6;
if (Low[cb]<=level && get_6==false)
{
true_6=Low[cb];
index_6=Time[cb];
if (Show_true) CreateObj("True_6",OBJ_HLINE,Time[0],true_6,Magenta,STYLE_DASH);
CreateText("Point_6","6",index_6,true_6+50*Point*p2d,Magenta);
}
}
if (dir==1)
{
if (true_6==0) level=level_6; else level=true_6;
if (High[cb]>=level && get_6==false)
{
true_6=High[cb];
index_6=Time[cb];
if (Show_true) CreateObj("True_6",OBJ_HLINE,Time[0],true_6,Magenta,STYLE_DASH);
CreateText("Point_6","6",index_6,true_6+50*Point*p2d,Magenta);
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CreateText(string name, string text, int index, double level, color col)
{
if (ObjectFind(name)==-1)
{
ObjectCreate (name,OBJ_TEXT,0,index,level,0,0,0,0);
ObjectSetText(name, text, 14, "Times New Roman", col);
}
else
{
ObjectMove(name, 0, index,level);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CreateObj(string name, int type, int index, double level, color col, int style)
{
if (ObjectFind(name)==-1)
{
ObjectCreate (name,type,0,index,level,0,0,0,0);
ObjectSet (name, OBJPROP_COLOR, col);
ObjectSet (name, OBJPROP_STYLE, style);
}
else
{
ObjectMove(name, 0, index,level);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int i=0; int j=0; int k=0;
find_4(index_3,p2d);
Comment("1: óðîâåíü=",level_1,"; äàòà=",TimeToStr(index_1,TIME_DATE),"\n",
"2: óðîâåíü=",level_2,"; äàòà=",TimeToStr(index_2,TIME_DATE),"\n",
"3: óðîâåíü=",level_3,"; äàòà=",TimeToStr(index_3,TIME_DATE),"\n",
"4: ýòàëîí=",etalon_4,"; öåëåâîé=",level_4,"; äîñòèãëè=",true_4,"; äàòà=",TimeToStr(index_4,TIME_DATE),"\n",
"5: ýòàëîí=",etalon_5,"; öåëåâîé=",level_5,"; äîñòèãëè=",true_5,"; äàòà=",TimeToStr(index_5,TIME_DATE),"\n",
"6: ýòàëîí=",etalon_6,"; öåëåâîé=",level_6,"; äîñòèãëè=",true_6,"; äàòà=",TimeToStr(index_6,TIME_DATE));
return(0);
}
//+------------------------------------------------------------------+
Comments