Help Needed PLZ !!!

 

Hi guys,


I'm quite new to this format of coding, but would obviously like to learn more. I've started with a simple EA, using the ZigZag indicator, but I'm struggling to make sense of the whole thing . . . The only thing that I'm after, is to report back the last 4 turn signals of the ZigZag indicator, but even that seems to be a mission at the moment. If anybody can offer some advice, or code examples, it would be greatly appreciated!!!!


I started with this using the ordinary ZigZag.mp4


//Input Parameters
extern double Lots = 1.0;
extern int ExtDepth = 4;
extern int ExtDeviation = 1;
extern int ExtBackStep = 2;


//Vars

double ZigZagValue[];
string ZigZagDirection[];


...


int start()
{

int i = 0;
int n = 4;

//Set Arrays
ArraySetAsSeries(ZigZagValue, false);
ArraySetAsSeries(ZigZagDirection, false);
ArrayResize(ZigZagValue, 4);
ArrayResize(ZigZagDirection, 3);
ArraySetAsSeries(ZigZagValue, true);
ArraySetAsSeries(ZigZagDirection, true);

//Get Indicator Values
while (n>=0)
{
double zigzag = iCustom(Symbol(), Period(), "ZigZag", ExtDepth, ExtDeviation, ExtBackStep, 0, i);
if (zigzag > 0)
{
ZigZagValue[n] = NormalizeDouble(zigzag,5);
n-=1;
}
i++;
}


//Calculate Directions (UP, DOWN, EVEN)
for (int ct1=1; ct1<=3; ct1++)
{
if (ZigZagValue[ct1 - 1] < ZigZagValue[ct1]) {ZigZagDirection[ct1] = "UP";} else {ZigZagDirection[ct1] = "DOWN";}
}


//Debug
//Print("ZigZag - " + ZigZagValue[0] + "(" + ZigZagDirection[1] + ") - " + ZigZagValue[1] + "(" + ZigZagDirection[2] + ") - " + ZigZagValue[2] + "(" + ZigZagDirection[3] + ") - " + ZigZagValue[3]);

}


Here i just basically used the external indicator with the iCustom function to get the last 4 points. My Problem here was I found that although it returned the points correctly, there were rather large gaps between the times that the data was returned. It almost looks like the start function only "ticks" when the "last" point has been "fixed" if you will? Also, i'm under the impression that the very last point returned is actually not fixed, but dynamic, and is still being moved around as the loop runs. This returns incosistant data, as I cant keep the previous last 4 point saved, but one is actually replaced by the temporary point.


After pulling out all my hair, I tried using the indicator ZigZag_Channels.mq4. I edited that indicator, to instead of drawing channel lines, keep a buffer with the last "know" points, both high, and low like this :


In the EA :


//Vars

double Point1, Point2, Point3, Point4, Point5 = 0;
string Direc1, Direc2, Direc3, Direc4 = "EVEN";


...


int start()
{

//Get Indicator Values
Point1 = NormalizeDouble(iCustom(NULL, 0, "ZigZag_Channels", ExtDepth, ExtDeviation, ExtBackStep, Yellow, Yellow, 0, 6, 0), 5);
Point2 = NormalizeDouble(iCustom(NULL, 0, "ZigZag_Channels", ExtDepth, ExtDeviation, ExtBackStep, Yellow, Yellow, 0, 2, 0), 5);
Point3 = NormalizeDouble(iCustom(NULL, 0, "ZigZag_Channels", ExtDepth, ExtDeviation, ExtBackStep, Yellow, Yellow, 0, 4, 0), 5);
Point4 = NormalizeDouble(iCustom(NULL, 0, "ZigZag_Channels", ExtDepth, ExtDeviation, ExtBackStep, Yellow, Yellow, 0, 3, 0), 5);
Point5 = NormalizeDouble(iCustom(NULL, 0, "ZigZag_Channels", ExtDepth, ExtDeviation, ExtBackStep, Yellow, Yellow, 0, 5, 0), 5);

//Calculate Directions (UP, DOWN, EVEN)
if (Point1 < Point2) {Direc1 = "UP";} else if (Point1 > Point2) {Direc1 = "DOWN";} else if (Point1 == Point2) {Direc1 = "EVEN";}
if (Point2 < Point3) {Direc2 = "UP";} else if (Point2 > Point3) {Direc2 = "DOWN";} else if (Point2 == Point3) {Direc2 = "EVEN";}
if (Point3 < Point4) {Direc3 = "UP";} else if (Point3 > Point4) {Direc3 = "DOWN";} else if (Point3 == Point4) {Direc3 = "EVEN";}
if (Point4 < Point5) {Direc4 = "UP";} else if (Point4 > Point5) {Direc4 = "DOWN";} else if (Point4 == Point5) {Direc4 = "EVEN";}

//Debug
Print("MultiZ - " + Point1 + "(" + Direc1 + ") - " + Point2 + "(" + Direc2 + ") - " + Point3 + "(" + Direc3 + ") - " + Point4 + "(" + Direc4 + ") - " + Point5);

}


In the Indicator, added new buffers, and replaced the DrawTrends() function with this :


void DrawTrends()
{
double temp = 0;
static int count = 0;
double save_0, save_1, save_2, save_3, save_4;
int t_0, t_1, t_2, t_3, t_4;

//get last up
for(int i = 0 ; i < Bars ; i++)
{
temp = ExtMapBuffer[i];
if (temp != 0) count++;
if(count == back + 1 && temp != 0) {save_0 = temp; t_0 = i;}
if(count == back + 2 && temp != 0) {save_1 = temp; t_1 = i;}
if(count == back + 3 && temp != 0) {save_2 = temp; t_2 = i;}
if(count == back + 4 && temp != 0) {save_3 = temp; t_3 = i;}
if(count == back + 5 && temp != 0) {save_4 = temp; t_4 = i;}
if(count == back + 6) break;
}


for(count=Bars-1; count>=0; count--)
{
upperband1[count]= save_3;
upperband2[count]= save_1;
lowerband1[count]= save_2;
lowerband2[count]= save_0;
extraband1[count]= save_4;
}

}


I know the indexing of the lines in the EA is a bit strange, but I was still testing . . . The problem here was the same as before. The "tick" didn't seem like it actually occured on every market tick, but rather every time the indicator had new values. . . . .


I dont know, think I'm a bit lost honestly!!!!!!! My question again : Can anybody show me, like when an EA runs, how you can get the last 4 points of a ZigZag, at any given moment? Any help would be greatly appreciated !!!!!


Arrie.

 
Look at ZZ[1 to 4] instead of ZZ[0 to 3] because as you say the last point is not fixed until the candle closes. Also you need to remember with the this indicator the last point may still change on the new candle until the latest candle is either the lowest or highest of the series. I don't see how you can know that the last point of the zigzag is the last one until the trend has ended and you only know that many candles after the point is fixed.
 

Thanks for the reply Ruptor!!


Agreed, the last point might change yes, but with the way the code is now, somehow I'm still not getting the previous 4 points. What happens is, that ZigZag indicator actually reports back the dynamic point, which pushes out my last lets say low point value, then the indicator decides that was not the actual point, and removes it again, shifting my array of values back again . . .


So tracing lets say the trend between the points in the same minute . . . would give me something like (just test data) :

UP - DOWN - UP

UP - DOWN - UP

DOWN - UP DOWN (here the dynamic point came into play)

UP - DOWN - UP

UP - DOWN - UP

DOWN - UP - DOWN (here the dynamic point came into play)


Thats the one problem yes, can you shed any light on my question of the actual "ticks" of the expert advisor as per my post above?

Reason: