yourspace_ElliottWaveModel
Download scriptThis script is designed for the MetaTrader platform to visually map out Elliott Wave Theory structures on a price chart. Elliott Wave Theory is a complex method used by traders to analyze market trends by identifying recurring patterns of "waves" that represent the psychology of crowd movement.
Instead of trying to guess where these waves are automatically, this tool allows you to manually input specific dates and prices to build a structural model. Here is a breakdown of how the logic functions:
1. Input and Initialization
The script begins by establishing a set of "coordinates." You can provide specific dates and times for different points of the Elliott Wave cycle (e.g., Wave 1 through Wave 5, plus corrective phases like A-B-C or X-A-B-C). It also allows you to define mathematical ratios—standard Fibonacci levels such as 0.618, 1.618, and 0.382—which are the foundation of Elliott Wave geometry.
2. Trend Detection
The script automatically determines if the current market movement is an Uptrend or a Downtrend by comparing two specific price points provided in the settings. This determination tells the script whether to look for "Highs" or "Lows" when calculating the distance and size of each wave.
3. The Calculation Logic
The core logic follows a sequential process. Once you provide the initial "Wave 1," the script uses that as a benchmark to calculate all subsequent waves:
- Primary Waves (1-5): The script calculates the height (vertical distance) and the shift (horizontal time distance) of each wave. If you haven't manually entered a specific date for a later wave, the script will use your pre-defined Fibonacci ratios to "project" where that wave should end based on the previous waves.
- Sub-Waves (Small Waves): The script has an optional feature to show "small waves." This breaks down larger movements into smaller components (e.g., Wave 3 being composed of 3-1, 3-2, 3-3, and 3-4). It applies specific mathematical scaling to ensure these sub-movements remain proportional to the main wave.
- Corrective Patterns: The logic includes specialized modules for complex corrections like "A-B-C," "Diagonal" patterns, and "Triangles." It can calculate these based on either your manual inputs or by applying the Fibonacci proportions to the preceding primary waves.
4. Visual Mapping (Drawing)
Once the math is complete, the script handles the visual heavy lifting:
- Trend Lines: It draws solid lines connecting the start and end points of every wave, color-coded for easy distinction between primary and corrective movements.
- Dynamic Labeling: The script automatically places text labels on the chart. Depending on your preferences, these labels can show the Wave name (e.g., "Wave 3"), the specific date/time, the price levels, or the actual numerical difference in points between the start and end of a wave.
Summary for the User
In short, this is a geometric drafting tool. You provide the starting points of a market move, and the script uses Elliott Wave mathematics to draw the rest of the structure accurately on your chart, ensuring that every "small wave" and "correction" maintains the correct proportional relationship to the main trend.
//+------------------------------------------------------------------+
//| yourspace_ElliottWaveModel |
//+------------------------------------------------------------------+
#property copyright "*"
#property link "*"
#property indicator_chart_window
extern string EX_obj_id="ys";
extern string d00="2010.06.07 04:45";
extern string d1z="2010.06.18 10:30";
extern double EX_2W=0.618;
extern double EX_3W=1.618;
extern double EX_4W=0.382;
extern double EX_5W=1.000;
extern double EX_AW=0.382;
extern double EX_BW=0.500;
extern double EX_CW=1.000;
extern double EX_DW=0.382;
extern double EX_EW=0.236;
extern double EX_shift=1.618;
extern bool EX_show_smallwave=true;
extern double EX_31ex=1.000;
extern double EX_33ex=1.000;
extern double EX_35ex=1.000;
extern double EX_2sW=0.618;
extern double EX_3sW=1.618;
extern double EX_4sW=0.382;
extern double EX_5sW=1.000;
extern double EX_bsW=0.500;
extern double EX_csW=1.000;
extern bool EX_op_5_diagonal=true;
extern bool EX_op_C_diagonal=false;
extern bool EX_op_Triangle=false;
extern string d2a="0000.00.00 00:00";
extern string d2b="0000.00.00 00:00";
extern string d2z="0000.00.00 00:00";
extern string d31="0000.00.00 00:00";
extern string d32="0000.00.00 00:00";
extern string d33="0000.00.00 00:00";
extern string d34="0000.00.00 00:00";
extern string d3z="0000.00.00 00:00";
extern string d4a="0000.00.00 00:00";
extern string d4b="0000.00.00 00:00";
extern string d4z="0000.00.00 00:00";
extern string d51="0000.00.00 00:00";
extern string d52="0000.00.00 00:00";
extern string d53="0000.00.00 00:00";
extern string d54="0000.00.00 00:00";
extern string d5z="0000.00.00 00:00";
extern string da1="0000.00.00 00:00";
extern string da2="0000.00.00 00:00";
extern string da3="0000.00.00 00:00";
extern string da4="0000.00.00 00:00";
extern string daa="0000.00.00 00:00";
extern string dab="0000.00.00 00:00";
extern string daz="0000.00.00 00:00";
extern string dba="0000.00.00 00:00";
extern string dbb="0000.00.00 00:00";
extern string dbz="0000.00.00 00:00";
extern string dc1="0000.00.00 00:00";
extern string dc2="0000.00.00 00:00";
extern string dc3="0000.00.00 00:00";
extern string dc4="0000.00.00 00:00";
extern string dcz="0000.00.00 00:00";
extern string dda="0000.00.00 00:00";
extern string ddb="0000.00.00 00:00";
extern string ddz="0000.00.00 00:00";
extern string dea="0000.00.00 00:00";
extern string deb="0000.00.00 00:00";
extern string dez="0000.00.00 00:00";
extern bool EX_show_name=false;
extern bool EX_show_date=false;
extern bool EX_show_price1=false;
extern bool EX_show_price2=false;
extern color EX_cl1=Blue;
extern color EX_cl2=Maroon;
extern color EX_cl3=Aqua;
string NA="0000.00.00 00:00";
string ND="2050.01.01 00:00";
datetime t00,t1z,t2a,t2b,t2z,t31,t32,t33,t34,t3z,t4a,t4b,t4z,t51,t52,t53,t54,t5z,
ta1,ta2,ta3,ta4,taa,tab,taz,tba,tbb,tbz,tc1,tc2,tc3,tc4,tcz,tda,tdb,tdz,tea,teb,tez;
int b00,b1z,b2a,b2b,b2z,b31,b32,b33,b34,b3z,b4a,b4b,b4z,b51,b52,b53,b54,b5z,
ba1,ba2,ba3,ba4,baa,bab,baz,bba,bbb,bbz,bc1,bc2,bc3,bc4,bcz,bda,bdb,bdz,bea,beb,bez;
double p00,p1z,p2a,p2b,p2z,p31,p32,p33,p34,p3z,p4a,p4b,p4z,p51,p52,p53,p54,p5z,
pa1,pa2,pa3,pa4,paa,pab,paz,pba,pbb,pbz,pc1,pc2,pc3,pc4,pcz,pda,pdb,pdz,pea,peb,pez;
int X1,X2,X3,X4,X5,Xa,Xb,Xc,Xd,Xe,e;
double H1,H2,H3,H4,H5,Ha,Hb,Hc,Hd,He;
double f1=1.000,f2=0.500,f3=0.618,f4=0.236,f5=0.382;
bool uptrend;
string cid;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{IndicatorShortName("yourspace_EWM");
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{DelObject();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{ DelObject();
cid=EX_obj_id+"-"; e=0;
SetTime();
if(Close[b00]<Close[b1z]) uptrend=true; else uptrend=false;
Wave1();
Wave2();
Wave3();
Wave4();
Wave5();
WaveA();
WaveB();
WaveC();
if(EX_op_Triangle)
{WaveD();
WaveE();
}
return(0);
}
//+------------------------------------------------------------------+
//| Wave1 |
//+------------------------------------------------------------------+
void Wave1()
{
H1=mHigh(b1z)-mLow(b00); X1=(b00-b1z)*EX_shift;
p00=mLow (b00);
p1z=mHigh(b1z);
DrawWave("1 wave",t00,p00,t1z,p1z,EX_cl1);
}
//+------------------------------------------------------------------+
//| Wave2 |
//+------------------------------------------------------------------+
void Wave2()
{
if(d2z==NA)
{H2=H1*EX_2W; X2=X1*EX_2W;
p2z=p1z-H2; t2z=Shift(t1z,X2);}
else
{H2=mHigh(b1z)-mLow(b2z); X2=b1z-b2z;
p2z=mLow(b2z); t2z=Time[b2z];}
DrawWave("2 wave",t1z,p1z,t2z,p2z,EX_cl1);
if(EX_show_smallwave) {} else return;
if(d2z==NA) {}
else if(d2a!=NA && d2b!=NA) {} else return;
double fp=1.0-1.0*EX_bsW+1.0*EX_csW;
double fx=1.0+1.0*EX_bsW+1.0*EX_csW;
if(d2a==NA) {p2a=p1z-H2*1.0/fp; t2a=Shift(t1z,X2*1.0/fx);}
else {p2a=mLow (b2a);}
if(d2b==NA) {p2b=p2a+H2*1.0*EX_bsW/fp; t2b=Shift(t2a,X2*1.0*EX_bsW/fx);}
else {p2b=mHigh(b2b);}
DrawWave("2-a wave",t1z,p1z,t2a,p2a,EX_cl2);
DrawWave("2-b wave",t2a,p2a,t2b,p2b,EX_cl2);
DrawWave(" " ,t2b,p2b,t2z,p2z,EX_cl2);
}
//+------------------------------------------------------------------+
//| Wave3 |
//+------------------------------------------------------------------+
void Wave3()
{
if(d3z==NA)
{double fp=1.0-1.0*EX_2sW+1.0*EX_3sW-(1.0*EX_3sW)*EX_4sW+1.0*EX_5sW;
double fx=1.0+1.0*EX_2sW+1.0*EX_3sW+(1.0*EX_3sW)*EX_4sW+1.0*EX_5sW;
double H=H1*EX_3W;
double X=X1*EX_3W;
double h1=(H*1.0/fp)*(EX_31ex-1.0);
double h2=(H*1.0*EX_2sW/fp)*(EX_31ex-1.0);
double h3=(H*1.0*EX_3sW/fp)*(EX_33ex-1.0);
double h4=(H*1.0*EX_3sW/fp)*(EX_33ex-1.0)*EX_4sW;
double h5=(H*1.0*EX_5sW/fp)*(EX_35ex-1.0);
H3=H+h1-h2+h3-h4+h5;
double x1=(X*1.0/fx)*(EX_31ex-1.0);
double x2=(X*1.0*EX_2sW/fx)*(EX_31ex-1.0);
double x3=(X*1.0*EX_3sW/fx)*(EX_33ex-1.0);
double x4=(X*1.0*EX_3sW/fx)*(EX_33ex-1.0)*EX_4sW;
double x5=(X*1.0*EX_5sW/fx)*(EX_35ex-1.0);
X3=X+x1+x2+x3+x4+x5;
p3z=p2z+H3; t3z=Shift(t2z,X3);
}
else
{H3=mHigh(b3z)-mLow(b2z); X3=b2z-b3z;
p3z=mHigh(b3z); t3z=Time[b3z];}
DrawWave("3 wave",t2z,p2z,t3z,p3z,EX_cl1);
if(EX_show_smallwave) {} else return;
if(d3z==NA) {}
else if(d31!=NA && d32!=NA && d33!=NA && d34!=NA) {} else return;
if(d31==NA) {p31=p2z+H*1.0/fp +h1; t31=Shift(t2z,X*1.0/fx +x1);}
else {p31=mHigh(b31);}
if(d32==NA) {p32=p31-H*1.0*EX_2sW/fp-h2; t32=Shift(t31,X*1.0*EX_2sW/fx+x2);}
else {p32=mLow (b32);}
if(d33==NA) {p33=p32+H*1.0*EX_3sW/fp+h3; t33=Shift(t32,X*1.0*EX_3sW/fx+x3);}
else {p33=mHigh(b33);}
if(d34==NA) {p34=p33-H*(1.0*EX_3sW)*EX_4sW/fp-h4; t34=Shift(t33,X*(1.0*EX_3sW)*EX_4sW/fx+x4);}
else {p34=mLow (b34);}
DrawWave("3-1 wave",t2z,p2z,t31,p31,EX_cl2);
DrawWave("3-2 wave",t31,p31,t32,p32,EX_cl2);
DrawWave("3-3 wave",t32,p32,t33,p33,EX_cl2);
DrawWave("3-4 wave",t33,p33,t34,p34,EX_cl2);
DrawWave(" " ,t34,p34,t3z,p3z,EX_cl2);
}
//+------------------------------------------------------------------+
//| Wave4 |
//+------------------------------------------------------------------+
void Wave4()
{
if(d4z==NA)
{H4=H3*EX_4W; X4=X3*EX_4W;
p4z=p3z-H4; t4z=Shift(t3z,X4);}
else
{H4=mHigh(b3z)-mLow(b4z); X4=b3z-b4z;
p4z=mLow(b4z); t4z=Time[b4z];}
DrawWave("4 wave",t3z,p3z,t4z,p4z,EX_cl1);
if(EX_show_smallwave) {} else return;
if(d4z==NA) {}
else if(d4a!=NA && d4b!=NA) {} else return;
double fp=1.0-1.0*EX_bsW+1.0*EX_csW;
double fx=1.0+1.0*EX_bsW+1.0*EX_csW;
if(d4a==NA) {p4a=p3z-H4*1.0/fp; t4a=Shift(t3z,X4*1.0/fx);}
else {p4a=mLow (b4a);}
if(d4b==NA) {p4b=p4a+H4*1.0*EX_bsW/fp; t4b=Shift(t4a,X4*1.0*EX_bsW/fx);}
else {p4b=mHigh(b4b);}
DrawWave("4-a wave",t3z,p3z,t4a,p4a,EX_cl2);
DrawWave("4-b wave",t4a,p4a,t4b,p4b,EX_cl2);
DrawWave(" " ,t4b,p4b,t4z,p4z,EX_cl2);
}
//+------------------------------------------------------------------+
//| Wave5 |
//+------------------------------------------------------------------+
void Wave5()
{
if(d5z==NA)
{H5=H1*EX_5W; X5=X1*EX_5W;
p5z=p4z+H5; t5z=Shift(t4z,X5);}
else
{H5=mHigh(b5z)-mLow(b4z); X5=b4z-b5z;
p5z=mHigh(b5z); t5z=Time[b5z];}
DrawWave("5 wave",t4z,p4z,t5z,p5z,EX_cl1);
if(EX_show_smallwave) {} else return;
if(d5z==NA) {}
else if(d51!=NA && d52!=NA && d53!=NA && d54!=NA) {} else return;
double fp,fx;
if(EX_op_5_diagonal)
{fp=f1-f2+f3-f4+f5;
fx=f1+f2+f3+f4+f5;
if(d51==NA) {p51=p4z+H5*f1/fp; t51=Shift(t4z,X5*f1/fx);}
else {p51=mHigh(b51);}
if(d52==NA) {p52=p51-H5*f2/fp; t52=Shift(t51,X5*f2/fx);}
else {p52=mLow (b52);}
if(d53==NA) {p53=p52+H5*f3/fp; t53=Shift(t52,X5*f3/fx);}
else {p53=mHigh(b53);}
if(d54==NA) {p54=p53-H5*f4/fp; t54=Shift(t53,X5*f4/fx);}
else {p54=mLow (b54);}
}
else
{fp=1.0-1.0*EX_2sW+1.0*EX_3sW-(1.0*EX_3sW)*EX_4sW+1.0*EX_5sW;
fx=1.0+1.0*EX_2sW+1.0*EX_3sW+(1.0*EX_3sW)*EX_4sW+1.0*EX_5sW;
if(d51==NA) {p51=p4z+H5*1.0/fp; t51=Shift(t4z,X5*1.0/fx);}
else {p51=mHigh(b51);}
if(d52==NA) {p52=p51-H5*1.0*EX_2sW/fp; t52=Shift(t51,X5*1.0*EX_2sW/fx);}
else {p52=mLow (b52);}
if(d53==NA) {p53=p52+H5*1.0*EX_3sW/fp; t53=Shift(t52,X5*1.0*EX_3sW/fx);}
else {p53=mHigh(b53);}
if(d54==NA) {p54=p53-H5*(1.0*EX_3sW)*EX_4sW/fp; t54=Shift(t53,X5*(1.0*EX_3sW)*EX_4sW/fx);}
else {p54=mLow (b54);}
}
DrawWave("5-1 wave",t4z,p4z,t51,p51,EX_cl2);
DrawWave("5-2 wave",t51,p51,t52,p52,EX_cl2);
DrawWave("5-3 wave",t52,p52,t53,p53,EX_cl2);
DrawWave("5-4 wave",t53,p53,t54,p54,EX_cl2);
DrawWave(" " ,t54,p54,t5z,p5z,EX_cl2);
}
//+------------------------------------------------------------------+
//| WaveA |
//+------------------------------------------------------------------+
void WaveA()
{
if(daz==NA)
{Ha=(H1-H2+H3-H4+H5)*EX_AW; Xa=(X1-X2+X3-X4+X5)*EX_AW;
paz=p5z-Ha; taz=Shift(t5z,Xa);}
else
{Ha=mHigh(b5z)-mLow(baz); Xa=b5z-baz;
paz=mLow(baz); taz=Time[baz];}
DrawWave("A wave",t5z,p5z,taz,paz,EX_cl1);
if(EX_show_smallwave) {} else return;
if(daz==NA) {}
else if(da1!=NA && da2!=NA && da3!=NA && da4!=NA) {}
else if(daa!=NA && dab!=NA) {} else return;
double fp,fx;
if(daa!=NA || dab!=NA)
{fp=1.0-1.0*EX_bsW+1.0*EX_csW;
fx=1.0+1.0*EX_bsW+1.0*EX_csW;
if(daa==NA) {paa=p5z-Ha*1.0/fp; taa=Shift(t5z,Xa*1.0/fx);}
else {paa=mLow (baa);}
if(dab==NA) {pab=paa+Ha*1.0*EX_bsW/fp; tab=Shift(taa,Xa*1.0*EX_bsW/fx);}
else {pab=mHigh(bab);}
DrawWave("A-a wave",t5z,p5z,taa,paa,EX_cl2);
DrawWave("A-b wave",taa,paa,tab,pab,EX_cl2);
DrawWave(" " ,tab,pab,taz,paz,EX_cl2);
return;
}
fp=1.0-1.0*EX_2sW+1.0*EX_3sW-(1.0*EX_3sW)*EX_4sW+1.0*EX_5sW;
fx=1.0+1.0*EX_2sW+1.0*EX_3sW+(1.0*EX_3sW)*EX_4sW+1.0*EX_5sW;
if(da1==NA) {pa1=p5z-Ha*1.0/fp; ta1=Shift(t5z,Xa*1.0/fx);}
else {pa1=mLow (ba1);}
if(da2==NA) {pa2=pa1+Ha*1.0*EX_2sW/fp; ta2=Shift(ta1,Xa*1.0*EX_2sW/fx);}
else {pa2=mHigh(ba2);}
if(da3==NA) {pa3=pa2-Ha*1.0*EX_3sW/fp; ta3=Shift(ta2,Xa*1.0*EX_3sW/fx);}
else {pa3=mLow (ba3);}
if(da4==NA) {pa4=pa3+Ha*(1.0*EX_3sW)*EX_4sW/fp; ta4=Shift(ta3,Xa*(1.0*EX_3sW)*EX_4sW/fx);}
else {pa4=mHigh(ba4);}
DrawWave("A-1 wave",t5z,p5z,ta1,pa1,EX_cl2);
DrawWave("A-2 wave",ta1,pa1,ta2,pa2,EX_cl2);
DrawWave("A-3 wave",ta2,pa2,ta3,pa3,EX_cl2);
DrawWave("A-4 wave",ta3,pa3,ta4,pa4,EX_cl2);
DrawWave(" " ,ta4,pa4,taz,paz,EX_cl2);
}
//+------------------------------------------------------------------+
//| WaveB |
//+------------------------------------------------------------------+
void WaveB()
{
if(dbz==NA)
{Hb=Ha*EX_BW; Xb=Xa*EX_BW;
pbz=paz+Hb; tbz=Shift(taz,Xb);}
else
{Hb=mHigh(bbz)-mLow(baz); Xb=baz-bbz;
pbz=mHigh(bbz); tbz=Time[bbz];}
DrawWave("B wave",taz,paz,tbz,pbz,EX_cl1);
if(EX_show_smallwave) {} else return;
if(dbz==NA) {}
else if(dba!=NA && dbb!=NA) {} else return;
double fp=1.0-1.0*EX_bsW+1.0*EX_csW;
double fx=1.0+1.0*EX_bsW+1.0*EX_csW;
if(dba==NA) {pba=paz+Hb*1.0/fp; tba=Shift(taz,Xb*1.0/fx);}
else {pba=mHigh(bba);}
if(dbb==NA) {pbb=pba-Hb*1.0*EX_bsW/fp; tbb=Shift(tba,Xb*1.0*EX_bsW/fx);}
else {pbb=mLow (bbb);}
DrawWave("B-a wave",taz,paz,tba,pba,EX_cl2);
DrawWave("B-b wave",tba,pba,tbb,pbb,EX_cl2);
DrawWave(" " ,tbb,pbb,tbz,pbz,EX_cl2);
}
//+------------------------------------------------------------------+
//| WaveC |
//+------------------------------------------------------------------+
void WaveC()
{
if(dcz==NA)
{Hc=Ha*EX_CW; Xc=Xa*EX_CW;
pcz=pbz-Hc; tcz=Shift(tbz,Xc);}
else
{Hc=mHigh(bbz)-mLow(bcz); Xc=bbz-bcz;
pcz=mLow(bcz); tcz=Time[bcz];}
DrawWave("C wave",tbz,pbz,tcz,pcz,EX_cl1);
if(EX_show_smallwave) {} else return;
if(dcz==NA) {}
else if(dc1!=NA && dc2!=NA && dc3!=NA && dc4!=NA) {} else return;
double fp,fx;
if(EX_op_C_diagonal)
{fp=f1-f2+f3-f4+f5;
fx=f1+f2+f3+f4+f5;
if(dc1==NA) {pc1=pbz-Hc*f1/fp; tc1=Shift(tbz,Xc*f1/fx);}
else {pc1=mLow (bc1);}
if(dc2==NA) {pc2=pc1+Hc*f2/fp; tc2=Shift(tc1,Xc*f2/fx);}
else {pc2=mHigh(bc2);}
if(dc3==NA) {pc3=pc2-Hc*f3/fp; tc3=Shift(tc2,Xc*f3/fx);}
else {pc3=mLow (bc3);}
if(dc4==NA) {pc4=pc3+Hc*f4/fp; tc4=Shift(tc3,Xc*f4/fx);}
else {pc4=mHigh(bc4);}
}
else
{fp=1.0-1.0*EX_2sW+1.0*EX_3sW-(1.0*EX_3sW)*EX_4sW+1.0*EX_5sW;
fx=1.0+1.0*EX_2sW+1.0*EX_3sW+(1.0*EX_3sW)*EX_4sW+1.0*EX_5sW;
if(dc1==NA) {pc1=pbz-Hc*1.0/fp; tc1=Shift(tbz,Xc*1.0/fx);}
else {pc1=mLow (bc1);}
if(dc2==NA) {pc2=pc1+Hc*1.0*EX_2sW/fp; tc2=Shift(tc1,Xc*1.0*EX_2sW/fx);}
else {pc2=mHigh(bc2);}
if(dc3==NA) {pc3=pc2-Hc*1.0*EX_3sW/fp; tc3=Shift(tc2,Xc*1.0*EX_3sW/fx);}
else {pc3=mLow (bc3);}
if(dc4==NA) {pc4=pc3+Hc*(1.0*EX_3sW)*EX_4sW/fp; tc4=Shift(tc3,Xc*(1.0*EX_3sW)*EX_4sW/fx);}
else {pc4=mHigh(bc4);}
}
DrawWave("C-1 wave",tbz,pbz,tc1,pc1,EX_cl2);
DrawWave("C-2 wave",tc1,pc1,tc2,pc2,EX_cl2);
DrawWave("C-3 wave",tc2,pc2,tc3,pc3,EX_cl2);
DrawWave("C-4 wave",tc3,pc3,tc4,pc4,EX_cl2);
DrawWave(" " ,tc4,pc4,tcz,pcz,EX_cl2);
}
//+------------------------------------------------------------------+
//| WaveD |
//+------------------------------------------------------------------+
void WaveD()
{
if(ddz==NA)
{Hd=Ha*EX_DW; Xd=Xa*EX_DW;
pdz=pcz+Hd; tdz=Shift(tcz,Xd);}
else
{Hd=mHigh(bdz)-mLow(bcz); Xd=bcz-bdz;
pdz=mHigh(bdz); tdz=Time[bdz];}
DrawWave("B wave",tcz,pcz,tdz,pdz,EX_cl1);
if(EX_show_smallwave) {} else return;
if(ddz==NA) {}
else if(dda!=NA && ddb!=NA) {} else return;
double fp=1.0-1.0*EX_bsW+1.0*EX_csW;
double fx=1.0+1.0*EX_bsW+1.0*EX_csW;
if(dda==NA) {pda=pcz+Hd*1.0/fp; tda=Shift(tcz,Xd*1.0/fx);}
else {pda=mHigh(bda);}
if(ddb==NA) {pdb=pda-Hd*1.0*EX_bsW/fp; tdb=Shift(tda,Xd*1.0*EX_bsW/fx);}
else {pdb=mLow (bdb);}
DrawWave("B-a wave",tcz,pcz,tda,pda,EX_cl2);
DrawWave("B-b wave",tda,pda,tdb,pdb,EX_cl2);
DrawWave(" " ,tdb,pdb,tdz,pdz,EX_cl2);
}
//+------------------------------------------------------------------+
//| WaveE |
//+------------------------------------------------------------------+
void WaveE()
{
if(dez==NA)
{He=Ha*EX_EW; Xe=Xa*EX_EW;
pez=pdz-He; tez=Shift(tdz,Xe);}
else
{He=mHigh(bdz)-mLow(bez); Xe=bdz-bez;
pez=mLow(bez); tez=Time[bez];}
DrawWave("C wave",tdz,pdz,tez,pez,EX_cl1);
if(EX_show_smallwave) {} else return;
if(dez==NA) {}
else if(dea!=NA && deb!=NA) {} else return;
double fp=1.0-1.0*EX_bsW+1.0*EX_csW;
double fx=1.0+1.0*EX_bsW+1.0*EX_csW;
if(dea==NA) {pea=pdz-He*1.0/fp; tea=Shift(tdz,Xe*1.0/fx);}
else {pea=mHigh(bea);}
if(deb==NA) {peb=pea+He*1.0*EX_bsW/fp; teb=Shift(tea,Xe*1.0*EX_bsW/fx);}
else {peb=mLow (beb);}
DrawWave("B-a wave",tdz,pdz,tea,pea,EX_cl2);
DrawWave("B-b wave",tea,pea,teb,peb,EX_cl2);
DrawWave(" " ,teb,peb,tez,pez,EX_cl2);
}
//+------------------------------------------------------------------+
//| DrawWave |
//+------------------------------------------------------------------+
void DrawWave(string n,datetime t1,double p1,datetime t2,double p2,color cl)
{
DrawLine(cid+e,t1,p1,t2,p2,cl); e++;
if(n!=" ")
{string tx=" ";
if(EX_show_name) tx=tx+n+" ";
if(EX_show_date)
if(Period()>=PERIOD_D1) tx=tx+TimeToStr(t2,TIME_DATE)+" ";
else tx=tx+TimeMonth(t2)+"/"+TimeDay(t2)+" "+TimeHour(t2)+":"+TimeMinute(t2)+" ";
if(EX_show_price1) tx=tx+DoubleToStr(p2,Digits)+" ";
if(EX_show_price2) tx=tx+"("+DoubleToStr(p2-p1,Digits)+")";
DrawText(cid+e,t2,tx,p2,EX_cl3);
e++;
}
}
//+------------------------------------------------------------------+
//| DrawLine |
//+------------------------------------------------------------------+
void DrawLine(string no,datetime t1,double p1,datetime t2,double p2,color cl)
{
ObjectCreate(no,OBJ_TREND,0,0,0,0,0);
ObjectSet(no,OBJPROP_STYLE ,STYLE_SOLID);
ObjectSet(no,OBJPROP_COLOR ,cl);
ObjectSet(no,OBJPROP_WIDTH ,1);
ObjectSet(no,OBJPROP_TIME1 ,t1);
ObjectSet(no,OBJPROP_PRICE1,p1);
ObjectSet(no,OBJPROP_TIME2 ,t2);
ObjectSet(no,OBJPROP_PRICE2,p2);
ObjectSet(no,OBJPROP_RAY,false);
ObjectSet(no,OBJPROP_BACK,false);
}
//+------------------------------------------------------------------+
//| DrawText |
//+------------------------------------------------------------------+
void DrawText(string no,datetime tb,string tx,double p,color cl)
{ ObjectCreate(no,OBJ_TEXT,0,0,0);
ObjectSet(no,OBJPROP_TIME1 ,tb);
ObjectSet(no,OBJPROP_PRICE1 ,p);
ObjectSet(no,OBJPROP_COLOR ,cl);
ObjectSet(no,OBJPROP_FONTSIZE,9);
ObjectSetText(no,tx);
}
//+------------------------------------------------------------------+
//| mHigh |
//+------------------------------------------------------------------+
double mHigh(int b)
{ double p;
if(uptrend) p=High[b]; else p=Low[b];
return(p);
}
//+------------------------------------------------------------------+
//| mLow |
//+------------------------------------------------------------------+
double mLow(int b)
{ double p;
if(uptrend) p=Low[b]; else p=High[b];
return(p);
}
//+------------------------------------------------------------------+
//| SetTime |
//+------------------------------------------------------------------+
void SetTime()
{
t00=StrToTime(d00); b00=iBarShift(NULL,0,t00);
t1z=StrToTime(d1z); b1z=iBarShift(NULL,0,t1z);
t2a=StrToTime(d2a); b2a=iBarShift(NULL,0,t2a);
t2b=StrToTime(d2b); b2b=iBarShift(NULL,0,t2b);
t2z=StrToTime(d2z); b2z=iBarShift(NULL,0,t2z);
t31=StrToTime(d31); b31=iBarShift(NULL,0,t31);
t32=StrToTime(d32); b32=iBarShift(NULL,0,t32);
t33=StrToTime(d33); b33=iBarShift(NULL,0,t33);
t34=StrToTime(d34); b34=iBarShift(NULL,0,t34);
t3z=StrToTime(d3z); b3z=iBarShift(NULL,0,t3z);
t4a=StrToTime(d4a); b4a=iBarShift(NULL,0,t4a);
t4b=StrToTime(d4b); b4b=iBarShift(NULL,0,t4b);
t4z=StrToTime(d4z); b4z=iBarShift(NULL,0,t4z);
t51=StrToTime(d51); b51=iBarShift(NULL,0,t51);
t52=StrToTime(d52); b52=iBarShift(NULL,0,t52);
t53=StrToTime(d53); b53=iBarShift(NULL,0,t53);
t54=StrToTime(d54); b54=iBarShift(NULL,0,t54);
t5z=StrToTime(d5z); b5z=iBarShift(NULL,0,t5z);
ta1=StrToTime(da1); ba1=iBarShift(NULL,0,ta1);
ta2=StrToTime(da2); ba2=iBarShift(NULL,0,ta2);
ta3=StrToTime(da3); ba3=iBarShift(NULL,0,ta3);
ta4=StrToTime(da4); ba4=iBarShift(NULL,0,ta4);
taa=StrToTime(daa); baa=iBarShift(NULL,0,taa);
tab=StrToTime(dab); bab=iBarShift(NULL,0,tab);
taz=StrToTime(daz); baz=iBarShift(NULL,0,taz);
tba=StrToTime(dba); bba=iBarShift(NULL,0,tba);
tbb=StrToTime(dbb); bbb=iBarShift(NULL,0,tbb);
tbz=StrToTime(dbz); bbz=iBarShift(NULL,0,tbz);
tc1=StrToTime(dc1); bc1=iBarShift(NULL,0,tc1);
tc2=StrToTime(dc2); bc2=iBarShift(NULL,0,tc2);
tc3=StrToTime(dc3); bc3=iBarShift(NULL,0,tc3);
tc4=StrToTime(dc4); bc4=iBarShift(NULL,0,tc4);
tcz=StrToTime(dcz); bcz=iBarShift(NULL,0,tcz);
tda=StrToTime(dda); bda=iBarShift(NULL,0,tda);
tdb=StrToTime(ddb); bdb=iBarShift(NULL,0,tdb);
tdz=StrToTime(ddz); bdz=iBarShift(NULL,0,tdz);
tea=StrToTime(dea); bea=iBarShift(NULL,0,tea);
teb=StrToTime(deb); beb=iBarShift(NULL,0,teb);
tez=StrToTime(dez); bez=iBarShift(NULL,0,tez);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int DelObject()
{ int i;
for(i=0; i<=200; i++) ObjectDelete(cid+i);
}
//+------------------------------------------------------------------+
// Shift |
//+------------------------------------------------------------------+
datetime Shift(datetime dt,int sf) {
int ty=TimeYear(dt);
int tm=TimeMonth(dt);
int td=TimeDay(dt);
int th=TimeHour(dt);
int ti=TimeMinute(dt);
int i;
for(i=1; i<=sf; i++)
{if (Period()==PERIOD_M1 ) ti=ti+1;
else if(Period()==PERIOD_M5 ) ti=ti+5;
else if(Period()==PERIOD_M15) ti=ti+15;
else if(Period()==PERIOD_M30) ti=ti+30;
else if(Period()==PERIOD_H1 ) th=th+1;
else if(Period()==PERIOD_H4 ) th=th+4;
else if(Period()==PERIOD_D1 ) td=td+1;
else if(Period()==PERIOD_W1 ) td=td+7;
else if(Period()==PERIOD_MN1) tm=tm+1;
if(ti>=60) {ti=ti-60; th++;}
if(th>=24) {th=th-24; td++;}
if(tm==1 || tm==3 || tm==5 || tm==7 || tm==8 || tm==10 || tm==12) {if(td>31) {tm++; td=td-31;}}
else if(tm==2) {
if(MathMod(ty,4)==0)
{if(td>29) {tm++; td=td-29;}}
else
{if(td>28) {tm++; td=td-28;}}
}
else if(tm==4 || tm==6 || tm==9 || tm==11) if(td>30) {tm++; td=td-30;}
if(tm>12) {tm=1; ty++;}
}
return(StrToTime(ty+"."+tm+"."+td+" "+th+":"+ti));
}
Comments