Hello Everyone,
I just finished make an indicator to draw a fibonacci retracement for the last wave depend on the zigzag indicator, but I still have a problem and tired to find the solve of drawing the fibo expansion by using Obj_expansion code. I want it to draw a fibo expansion depend on the last 3 zigzag coordinates and I couldn't code it. It's need the 1st coordinate and I don't know how to get it. Does anyone know how to resolve this problem? or anyone know how fibo expansion is manually calculated if I have the 3 coordinates?
I wait the resolve before the market open
.
ooh, I forget something
, this is the 1st problem I have. The 2nd & 3rd comes later after resloving 1st
another thing, when I try testing indicator by strategy tester using visual mode I found that fibo expansion does't move to the new value..... I think the problem is in this code (Colored by red)
olso the 100.0% line moving to a new positions and last zigzag value is still as it, I don't know why, despite 0.00% line is still as it.... so, WHERE IS THE ERROR?
You can see it when you testing on small timeframes.
So is there anyone can helping me please?
Have a good day.
I just finished make an indicator to draw a fibonacci retracement for the last wave depend on the zigzag indicator, but I still have a problem and tired to find the solve of drawing the fibo expansion by using Obj_expansion code. I want it to draw a fibo expansion depend on the last 3 zigzag coordinates and I couldn't code it. It's need the 1st coordinate and I don't know how to get it. Does anyone know how to resolve this problem? or anyone know how fibo expansion is manually calculated if I have the 3 coordinates?
I wait the resolve before the market open
ooh, I forget something
another thing, when I try testing indicator by strategy tester using visual mode I found that fibo expansion does't move to the new value..... I think the problem is in this code (Colored by red)
QuoteDislikedif(ObjectFind("FIBOexpansion") != 0)
{
ObjectCreate("FIBOexpansion", OBJ_EXPANSION,0,Time[lasthighpos],S1,Time[lastlowpos],R1,Time[lasthighpos],S1);
ObjectSet("FIBOexpansion", OBJPROP_STYLE, STYLE_DOT);
ObjectSet("FIBOexpansion", OBJPROP_COLOR, Fibo_Expansion_Color);
}
else
{
ObjectMove("FIBOexpansion", 0, Time[lasthighpos]+Time[lastlowpos]+Time[lasthighpos],S1);
}
olso the 100.0% line moving to a new positions and last zigzag value is still as it, I don't know why, despite 0.00% line is still as it.... so, WHERE IS THE ERROR?
You can see it when you testing on small timeframes.
So is there anyone can helping me please?
Have a good day.
Inserted Code
//+------------------------------------------------------------------+
//| Zigzagy Auto Fibo.mq4 |
//| Copyright © 2005-2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- indicator parameters
extern int ExtDepth=90;
extern int ExtDeviation=5;
extern int ExtBackstep=3;
extern color ZigZag_Color= Red;
extern int ZigZag_Width=4;
extern color Fibo_Expansion_Color= Blue;
extern color Fibo_0.00_Color= Yellow;
extern color Fibo_23.6_Color= Red;
extern color Fibo_38.2_Color= White;
extern color Fibo_50.0_Color= White;
extern color Fibo_61.8_Color= Red;
extern color Fibo_76.4_Color= White;
extern color Fibo_100.0_Color= Aqua;
//---- indicator buffers
double ZigzagBuffer[];
double HighMapBuffer[];
double LowMapBuffer[];
int level=3; // recounting's depth
bool downloadhistory=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
//---- drawing settings
SetIndexStyle(0,DRAW_SECTION,0,ZigZag_Width,ZigZag_Color);
//---- indicator buffers mapping
SetIndexBuffer(0,ZigzagBuffer);
SetIndexBuffer(1,HighMapBuffer);
SetIndexBuffer(2,LowMapBuffer);
SetIndexEmptyValue(0,0.0);
//---- indicator short name
IndicatorShortName("ZigZag("+ExtDepth+","+ExtDeviation+","+ExtBackstep+")");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
ObjectDelete("R1 Label");
ObjectDelete("R1 Line");
ObjectDelete("S1 Label");
ObjectDelete("S1 Line");
ObjectDelete("FIBO236 Label");
ObjectDelete("FIBO236 Line");
ObjectDelete("FIBO382 Label");
ObjectDelete("FIBO382 Line");
ObjectDelete("FIBO50 Label");
ObjectDelete("FIBO50 Line");
ObjectDelete("FIBO618 Label");
ObjectDelete("FIBO618 Line");
ObjectDelete("FIBO764 Label");
ObjectDelete("FIBO764 Line");
ObjectDelete("FIBOexpansion");
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int i, counted_bars = IndicatorCounted();
int limit,counterZ,whatlookfor;
int shift,back,lasthighpos,lastlowpos;
double val,res;
double curlow,curhigh,lasthigh,lastlow;
if (counted_bars==0 && downloadhistory) // history was downloaded
{
ArrayInitialize(ZigzagBuffer,0.0);
ArrayInitialize(HighMapBuffer,0.0);
ArrayInitialize(LowMapBuffer,0.0);
}
if (counted_bars==0)
{
limit=Bars-ExtDepth;
downloadhistory=true;
}
if (counted_bars>0)
{
while (counterZ<level && i<100)
{
res=ZigzagBuffer[i];
if (res!=0) counterZ++;
i++;
}
i--;
limit=i;
if (LowMapBuffer[i]!=0)
{
curlow=LowMapBuffer[i];
whatlookfor=1;
}
else
{
curhigh=HighMapBuffer[i];
whatlookfor=-1;
}
for (i=limit-1;i>=0;i--)
{
ZigzagBuffer[i]=0.0;
LowMapBuffer[i]=0.0;
HighMapBuffer[i]=0.0;
}
}
for(shift=limit; shift>=0; shift--)
{
val=Low[iLowest(NULL,0,MODE_LOW,ExtDepth,shift)];
if(val==lastlow) val=0.0;
else
{
lastlow=val;
if((Low[shift]-val)>(ExtDeviation*Point)) val=0.0;
else
{
for(back=1; back<=ExtBackstep; back++)
{
res=LowMapBuffer[shift+back];
if((res!=0)&&(res>val)) LowMapBuffer[shift+back]=0.0;
}
}
}
if (Low[shift]==val) LowMapBuffer[shift]=val; else LowMapBuffer[shift]=0.0;
//--- high
val=High[iHighest(NULL,0,MODE_HIGH,ExtDepth,shift)];
if(val==lasthigh) val=0.0;
else
{
lasthigh=val;
if((val-High[shift])>(ExtDeviation*Point)) val=0.0;
else
{
for(back=1; back<=ExtBackstep; back++)
{
res=HighMapBuffer[shift+back];
if((res!=0)&&(res<val)) HighMapBuffer[shift+back]=0.0;
}
}
}
if (High[shift]==val) HighMapBuffer[shift]=val; else HighMapBuffer[shift]=0.0;
}
// final cutting
if (whatlookfor==0)
{
lastlow=0;
lasthigh=0;
}
else
{
lastlow=curlow;
lasthigh=curhigh;
}
for (shift=limit;shift>=0;shift--)
{
res=0.0;
switch(whatlookfor)
{
case 0: // look for peak or lawn
if (lastlow==0 && lasthigh==0)
{
if (HighMapBuffer[shift]!=0)
{
lasthigh=High[shift];
lasthighpos=shift;
whatlookfor=-1;
ZigzagBuffer[shift]=lasthigh;
res=1;
}
if (LowMapBuffer[shift]!=0)
{
lastlow=Low[shift];
lastlowpos=shift;
whatlookfor=1;
ZigzagBuffer[shift]=lastlow;
res=1;
}
}
break;
case 1: // look for peak
if (LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift]<lastlow && HighMapBuffer[shift]==0.0)
{
ZigzagBuffer[lastlowpos]=0.0;
lastlowpos=shift;
lastlow=LowMapBuffer[shift];
ZigzagBuffer[shift]=lastlow;
res=1;
}
if (HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0)
{
lasthigh=HighMapBuffer[shift];
lasthighpos=shift;
ZigzagBuffer[shift]=lasthigh;
whatlookfor=-1;
res=1;
}
break;
case -1: // look for lawn
if (HighMapBuffer[shift]!=0.0 && HighMapBuffer[shift]>lasthigh && LowMapBuffer[shift]==0.0)
{
ZigzagBuffer[lasthighpos]=0.0;
lasthighpos=shift;
lasthigh=HighMapBuffer[shift];
ZigzagBuffer[shift]=lasthigh;
}
if (LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0)
{
lastlow=LowMapBuffer[shift];
lastlowpos=shift;
ZigzagBuffer[shift]=lastlow;
whatlookfor=1;
}
break;
default: return;
}
}
double R1,S1,Q,FIBO236,FIBO382,FIBO50,FIBO618,FIBO764;
if(whatlookfor==1)
{
R1=High[iHighest(NULL,0,MODE_HIGH,1,lasthighpos)];
S1=Low[iLowest(NULL,0,MODE_LOW,1,lastlowpos)];
Q=R1-S1;
FIBO236=S1+(Q*0.236);
FIBO382=S1+(Q*0.382);
FIBO50=S1+(Q*0.5);
FIBO618=S1+(Q*0.618);
FIBO764=S1+(Q*0.764);
}
else
{
S1=High[iHighest(NULL,0,MODE_HIGH,1,lasthighpos)];
R1=Low[iLowest(NULL,0,MODE_LOW,1,lastlowpos)];
Q=MathAbs(R1-S1);
FIBO236=S1-(Q*0.236);
FIBO382=S1-(Q*0.382);
FIBO50=S1-(Q*0.5);
FIBO618=S1-(Q*0.618);
FIBO764=S1-(Q*0.764);
}
if(ObjectFind("R1 label") != 0)
{
ObjectCreate("R1 label", OBJ_TEXT, 0, Time[3], R1);
ObjectSetText("R1 label", "100.0%", 8, "Arial", Fibo_100.0_Color);
}
else
{
ObjectMove("R1 label", 0, Time[3], R1);
}
//----
if(ObjectFind("S1 label") != 0)
{
ObjectCreate("S1 label", OBJ_TEXT, 0, Time[3], S1);
ObjectSetText("S1 label", "0.0%", 8, "Arial", Fibo_0.00_Color);
}
else
{
ObjectMove("S1 label", 0, Time[3], S1);
}
//----
if(ObjectFind("FIBO236 label") != 0)
{
ObjectCreate("FIBO236 label", OBJ_TEXT, 0, Time[3], FIBO236);
ObjectSetText("FIBO236 label", "23.6%", 12, "High Tower Text", Fibo_23.6_Color);
}
else
{
ObjectMove("FIBO236 label", 0, Time[3], FIBO236);
}
//----
if(ObjectFind("FIBO382 label") != 0)
{
ObjectCreate("FIBO382 label", OBJ_TEXT, 0, Time[3], FIBO382);
ObjectSetText("FIBO382 label", "38.2%", 8, "Arial", Fibo_38.2_Color);
}
else
{
ObjectMove("FIBO382 label", 0, Time[3], FIBO382);
}
//----
if(ObjectFind("FIBO50 label") != 0)
{
ObjectCreate("FIBO50 label", OBJ_TEXT, 0, Time[3], FIBO50);
ObjectSetText("FIBO50 label", "50.0%", 8, "Arial", Fibo_50.0_Color);
}
else
{
ObjectMove("FIBO50 label", 0, Time[3], FIBO50);
}
//----
if(ObjectFind("FIBO618 label") != 0)
{
ObjectCreate("FIBO618 label", OBJ_TEXT, 0, Time[3], FIBO618);
ObjectSetText("FIBO618 label", "61.8%", 12, "High Tower Text", Fibo_61.8_Color);
}
else
{
ObjectMove("FIBO618 label", 0, Time[3], FIBO618);
}
//----
if(ObjectFind("FIBO764 label") != 0)
{
ObjectCreate("FIBO764 label", OBJ_TEXT, 0, Time[3], FIBO764);
ObjectSetText("FIBO764 label", "76.4%", 8, "Arial", Fibo_76.4_Color);
}
else
{
ObjectMove("FIBO764 label", 0, Time[3], FIBO764);
}
//------------------------------------------------------------
if(ObjectFind("R1 line") != 0)
{
ObjectCreate("R1 line", OBJ_HLINE, 0, Time[3], R1);
ObjectSet("R1 line", OBJPROP_STYLE, STYLE_DASH);
ObjectSet("R1 line", OBJPROP_COLOR, Fibo_100.0_Color);
}
else
{
ObjectMove("R1 line", 0, Time[3], R1);
}
//----
if(ObjectFind("S1 line") != 0)
{
ObjectCreate("S1 line", OBJ_HLINE, 0, Time[3], S1);
ObjectSet("S1 line", OBJPROP_STYLE, STYLE_DASH);
ObjectSet("S1 line", OBJPROP_COLOR, Fibo_0.00_Color);
}
else
{
ObjectMove("S1 line", 0, Time[3], S1);
}
//----
if(ObjectFind("FIBO236 line") != 0)
{
ObjectCreate("FIBO236 line", OBJ_HLINE, 0, Time[3], FIBO236);
ObjectSet("FIBO236 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
ObjectSet("FIBO236 line", OBJPROP_COLOR, Fibo_23.6_Color);
}
else
{
ObjectMove("FIBO236 line", 0, Time[3], FIBO236);
}
//----
if(ObjectFind("FIBO382 line") != 0)
{
ObjectCreate("FIBO382 line", OBJ_HLINE, 0, Time[3], FIBO382);
ObjectSet("FIBO382 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
ObjectSet("FIBO382 line", OBJPROP_COLOR, Fibo_38.2_Color);
}
else
{
ObjectMove("FIBO382 line", 0, Time[3], FIBO382);
}
//----
if(ObjectFind("FIBO50 line") != 0)
{
ObjectCreate("FIBO50 line", OBJ_HLINE, 0, Time[3], FIBO50);
ObjectSet("FIBO50 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
ObjectSet("FIBO50 line", OBJPROP_COLOR, Fibo_50.0_Color);
}
else
{
ObjectMove("FIBO50 line", 0, Time[3], FIBO50);
}
//----
if(ObjectFind("FIBO618 line") != 0)
{
ObjectCreate("FIBO618 line", OBJ_HLINE, 0, Time[3], FIBO618);
ObjectSet("FIBO618 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
ObjectSet("FIBO618 line", OBJPROP_COLOR, Fibo_61.8_Color);
}
else
{
ObjectMove("FIBO618 line", 0, Time[3], FIBO618);
}
//----
if(ObjectFind("FIBO764 line") != 0)
{
ObjectCreate("FIBO764 line", OBJ_HLINE, 0, Time[3], FIBO764);
ObjectSet("FIBO764 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
ObjectSet("FIBO764 line", OBJPROP_COLOR, Fibo_76.4_Color);
}
else
{
ObjectMove("FIBO764 line", 0, Time[3], FIBO764);
}
//----
if(whatlookfor==1){
if(ObjectFind("FIBOexpansion") != 0)
{
ObjectCreate("FIBOexpansion", OBJ_EXPANSION,0,Time[lasthighpos],S1,Time[lastlowpos],R1,Time[lasthighpos],S1);
ObjectSet("FIBOexpansion", OBJPROP_STYLE, STYLE_DOT);
ObjectSet("FIBOexpansion", OBJPROP_COLOR, Fibo_Expansion_Color);
}
else
{
ObjectMove("FIBOexpansion", 0, Time[lasthighpos]+Time[lastlowpos]+Time[lasthighpos],S1);
}
}
else
{
if(ObjectFind("FIBOexpansion") != 0)
{
ObjectCreate("FIBOexpansion", OBJ_EXPANSION,0,[color="Red"]Time[lasthighpos],S1[/color],Time[lastlowpos],R1,Time[lasthighpos],S1);
ObjectSet("FIBOexpansion", OBJPROP_STYLE, STYLE_DOT);
ObjectSet("FIBOexpansion", OBJPROP_COLOR, Fibo_Expansion_Color);
}
else
{
ObjectMove("FIBOexpansion", 0, Time[lasthighpos]+Time[lastlowpos]+Time[lasthighpos],S1);
}
}
}
return(0);
//+------------------------------------------------------------------+ Attached File(s)