Coding help - page 38

 

...

In indicator the only way to do that would be to keep it in endless loop till some event (keyboard, mouse, ...) is detected

But that would also mean that the execution of the rest of the terminal functions is stopped (it is the same as when you have a bad indicator that crashes - blocks your metatrader) So, it is not a good solution. Function that is usually used for that (sleep) which allows other code execution while your code is paused (that would be the time when you allow the rest of the stuff in terminal to do the job) is disabled in indicators so it can not be used for a solution

marley60:
if there is an alarm, it makes a "pling" sound once. is there a possibility to play an alarm sound untill i stop it? (reason: i will not hear a single "pling" when i´m in the toilet or kitchen) i replaced the alarm sound with a song but i would prefer to have a choice between play once/play untill stoped (like it was in tradestation).
 

Question about Index

Hi Mladen;

I saw that somene call indicator such as Ind[3][0][1] like that , what is meaning first and second defined index ?

thanls in advance

kemal

 

ZigZag Problem in EA

Hi,

I use standard Zigzag indy in my EA. I use the following code to determine the zigzag nodes. I noticed that sometimes the MT4 returns the zigzag nodes from the wrong time frame. For example, when I try to get H1 zigzag nodes, MT4returns M15 zigzag node values. Has anyone come across such problem before? If you know more info about zigzag and the possible problem area, please advise.

Many thanks.

FFJason

note: TF is the time frame which I feed different values for getting zigzag nodes from different time frame. Somehow MT4 mixed up the node values when a specific TF is used.

void vGetNode2(int TF,double& lwnd2[2],double& hgnd2[2])

{ int t=0; int p=0; int q=0; double nd2i;

for (i=0; i<=150; i++)

{ nd2i=iCustom(NULL,TF,"ZigZag",13,8,5,0,i);

if (nd2i==iLow(NULL,TF,i)) {if (p<=1) {lwnd2[p]=nd2i; p++;}}

if (nd2i==iHigh(NULL,TF,i)) {if (q<=1) {hgnd2[q]=nd2i; q++;}}

if (p==2 && q==2) break;

}

return;

}

 

How to Open new order after S/L of previous order?

Open new order after S/L of previous order.
Dear sir;

Is any body know the program for EA to after close the order based on the S/L the new order is open?

Regards
 

...

You probably have a case when the ZigZag peak of one time frame is the same as the ZigZag peak of another time frame (which is not an unusual case since they are looking for peaks). As far as time frames are concerned, you are getting correct time frame values with that code. Maybe just one change in the code has to be done in order to ensure that you get 4 last ZigZag values, and then the code would be like this

void vGetNode2(int TF,double& lwnd2[2],double& hgnd2[2])

{

int p=0; int q=0; int max=iBarShift(NULL,TF,0); double nd2i;

for (int i=0; i<max; i++)

{

nd2i=iCustom(NULL,TF,"ZigZag",13,8,5,0,i);

if (nd2i==iLow(NULL,TF,i)) {if (p<=1) {lwnd2[p]=nd2i; p++;}}

if (nd2i==iHigh(NULL,TF,i)) {if (q<=1) {hgnd2[q]=nd2i; q++;}}

if (p==2 && q==2) break;

}

return;

}

[/PHP]

As you can see only the loop end is changed from "150" to "Bars-1"

novalight:
Hi,

I use standard Zigzag indy in my EA. I use the following code to determine the zigzag nodes. I noticed that sometimes the MT4 returns the zigzag nodes from the wrong time frame. For example, when I try to get H1 zigzag nodes, MT4returns M15 zigzag node values. Has anyone come across such problem before? If you know more info about zigzag and the possible problem area, please advise.

Many thanks.

FFJason

note: TF is the time frame which I feed different values for getting zigzag nodes from different time frame. Somehow MT4 mixed up the node values when a specific TF is used.

[PHP]

void vGetNode2(int TF,double& lwnd2[2],double& hgnd2[2])

{ int t=0; int p=0; int q=0; double nd2i;

for (i=0; i<=150; i++)

{ nd2i=iCustom(NULL,TF,"ZigZag",13,8,5,0,i);

if (nd2i==iLow(NULL,TF,i)) {if (p<=1) {lwnd2[p]=nd2i; p++;}}

if (nd2i==iHigh(NULL,TF,i)) {if (q<=1) {hgnd2[q]=nd2i; q++;}}

if (p==2 && q==2) break;

}

return;

}

 

ZigZag problem in EA

Hi Maiden,

Thank you very much for your help.

I did some reading on iBarShift, and your iBarShift(NULL,TF,0) seems to get the total number of bars on the chart. Please correct me if I misunderstand your intention of using iBarShift.

I look at those instances where ZigZag returned wrong node values, and the search number (I use 150) was not the issue. Also, I do understand that some nodes are the same for different time frame, but the errors I found were two or more nodes and the corresponding bar numbers were all pointing to a different time frame. That was the problem that puzzling me.

Today I found more puzzling problem with Zigzag. I use Alert to display the nodes returned by the routine and I found that sometimes the routine returns one correct pair of node and its bar number, but the other node and bar number were both 0. That is really strange. I further enhance the routine by ensuring that no node is 0 value with the following codes. I just hope that it is not MT4 skipping a heart beat or stall, and throw out garbage to my EA. The reason I say this is that my other EA which shows alert messages when my program trying to insert SL and TP, or gather OP values, and it happened quite often that MT4 just skipped these steps, and returned 0 values. I have to enhance my program to look out for these instances and make sure that these tasks are performed properly.

Please advise. I am at the end of my wit. Your help is greatly appreciated. Cheers,

Novalight

int iGetNode4(int TF, double& lwnd4, double& hgnd4, int& lwnd4bar, int& hgnd4bar)

{ lwnd4=0; hgnd4=0; lwnd4bar=0; hgnd4bar=0; int t=0,p=0; //node 4 = arrow

for (i=0; i<=120; i++)

{ double lowi=iLow(NULL,TF,i); double highi=iHigh(NULL,TF,i);

if (iCustom(NULL,TF,"ZigZag",80,35,12,0,i)==lowi && lowi!=0) {if (t==0) {lwnd4=iLow(NULL,TF,i); lwnd4bar=i; t++; if(lwnd4==0) Alert(lwnd4);}}

if (iCustom(NULL,TF,"ZigZag",80,35,12,0,i)==highi && highi!=0) {if (p==0) {hgnd4=iHigh(NULL,TF,i); hgnd4bar=i; p++;if (hgnd4==0) Alert(hgnd4);}}

if (t==1 && p==1) break;

}

if (lwnd4bar<hgnd4bar) return(1); //current node 4 is a low node for Long

if (lwnd4bar>hgnd4bar) return(-1); //current node 4 is a high node for Short

return;

}

[/PHP]

mladen:
You probably have a case when the ZigZag peak of one time frame is the same as the ZigZag peak of another time frame (which is not an unusual case since they are looking for peaks). As far as time frames are concerned, you are getting correct time frame values with that code. Maybe just one change in the code has to be done in order to ensure that you get 4 last ZigZag values, and then the code would be like this

[PHP]void vGetNode2(int TF,double& lwnd2[2],double& hgnd2[2])

{

int p=0; int q=0; int max=iBarShift(NULL,TF,0); double nd2i;

for (int i=0; i<max; i++)

{

nd2i=iCustom(NULL,TF,"ZigZag",13,8,5,0,i);

if (nd2i==iLow(NULL,TF,i)) {if (p<=1) {lwnd2[p]=nd2i; p++;}}

if (nd2i==iHigh(NULL,TF,i)) {if (q<=1) {hgnd2[q]=nd2i; q++;}}

if (p==2 && q==2) break;

}

return;

}

As you can see only the loop end is changed from "150" to "Bars-1"
 

...

As of iBarShift(NULL,TF,0) : yes, it returns the total bars of a target time frame. But the loop will not be executed that much times, It will exist as soon as the last 4 ZigZag peaks are found.

Now for the sake of argument imagine this : you call the function for one time frame and you have the limit of 150 bars to look for the last 4 peaks. It does the job and then you look into another time frame. And, just for the sake of argument, imagine that the 4th peak is outside the first 150 bars. What will happen. Since your arrays were not cleaned some results for previously looked for time frame are still there since at the 150th bar not all 4 peaks were found and some previously found peaks are left there as they were found in the currently seeked time frame

That was the purpose for adding that code : to make sure it actually finds the last 4 peaks. Sometimes it will take 10 bars sometimes 1000 (it entirely depends on ZigZag and is not a fixed number of bars) but it will not loop "bars" times. It will loop only necessary times and it will make sure that all the 4 peaks are from the target time frame

As far as time frame mixup is concerned I do not think that it is happening. The way how history file for target time frames are opened (by simply adding minutes of the target time frame to symbol name) makes it impossible to read data from 2 time frames in a single loop if the time frame parameter is not altered (only 1 history file is opened in that case and it can not access data from different time frame).

novalight:
Hi Maiden,

Thank you very much for your help.

I did some reading on iBarShift, and your iBarShift(NULL,TF,0)seems to get the total number of bars on the chart. Please correct me if I misunderstand your intention of using iBarShift.

I look at those instances where ZigZag returned wrong node values, and the search number (I use 150) was not the issue. Also, I do understand that some nodes are the same for different time frame, but the errors I found were two or more nodes and the corresponding bar numbers were all pointing to a different time frame. That was the problem that puzzling me.

Today I found more puzzling problem with Zigzag. I use Alert to display the nodes returned by the routine and I found that sometimes the routine returns one correct pair of node and its bar number, but the other node and bar number were both 0. That is really strange. I further enhance the routine by ensuring that no node is 0 value with the following codes. I just hope that it is not MT4 skipping a heart beat or stall, and throw out garbage to my EA. The reason I say this is that my other EA which shows alert messages when my program trying to insert SL and TP, or gather OP values, and it happened quite often that MT4 just skipped these steps, and returned 0 values. I have to enhance my program to look out for these instances and make sure that these tasks are performed properly.

Please advise. I am at the end of my wit. Your help is greatly appreciated. Cheers,

Novalight

int iGetNode4(int TF, double& lwnd4, double& hgnd4, int& lwnd4bar, int& hgnd4bar)

{ lwnd4=0; hgnd4=0; lwnd4bar=0; hgnd4bar=0; int t=0,p=0; //node 4 = arrow

for (i=0; i<=120; i++)

{ double lowi=iLow(NULL,TF,i); double highi=iHigh(NULL,TF,i);

if (iCustom(NULL,TF,"ZigZag",80,35,12,0,i)==lowi && lowi!=0) {if (t==0) {lwnd4=iLow(NULL,TF,i); lwnd4bar=i; t++; if(lwnd4==0) Alert(lwnd4);}}

if (iCustom(NULL,TF,"ZigZag",80,35,12,0,i)==highi && highi!=0) {if (p==0) {hgnd4=iHigh(NULL,TF,i); hgnd4bar=i; p++;if (hgnd4==0) Alert(hgnd4);}}

if (t==1 && p==1) break;

}

if (lwnd4bar<hgnd4bar) return(1); //current node 4 is a low node for Long

if (lwnd4bar>hgnd4bar) return(-1); //current node 4 is a high node for Short

return;

}

 

ZigZag problem in EA

Hi Maiden,

You are absolutely right! I review my code and found that 150 is insufficient for big zigzag, and if not all 4 nodes are found, the entire logic of identifying which node comes fist or last will be haywire.

In conclusion, there is nothing wrong with Zigzag nor MT4, it is purely my own mistake in setting too small a search number. I thank you for your time, patient, and more importantly your willingness to help ......

Take care .....

Novalight

mladen:
As of iBarShift(NULL,TF,0) : yes, it returns the total bars of a target time frame. But the loop will not be executed that much times, It will exist as soon as the last 4 ZigZag peaks are found.

Now for the sake of argument imagine this : you call the function for one time frame and you have the limit of 150 bars to look for the last 4 peaks. It does the job and then you look into another time frame. And, just for the sake of argument, imagine that the 4th peak is outside the first 150 bars. What will happen. Since your arrays were not cleaned some results for previously looked for time frame are still there since at the 150th bar not all 4 peaks were found and some previously found peaks are left there as they were found in the currently seeked time frame

That was the purpose for adding that code : to make sure it actually finds the last 4 peaks. Sometimes it will take 10 bars sometimes 1000 (it entirely depends on ZigZag and is not a fixed number of bars) but it will not loop "bars" times. It will loop only necessary times and it will make sure that all the 4 peaks are from the target time frame

As far as time frame mixup is concerned I do not think that it is happening. The way how history file for target time frames are opened (by simply adding minutes of the target time frame to symbol name) makes it impossible to read data from 2 time frames in a single loop if the time frame parameter is not altered (only 1 history file is opened in that case and it can not access data from different time frame).
 

Help with code

Would someone be kind enough to add code to the SnakeBorders indicator to add the two following plots:

1. A line plot that plots the middle of the white range(as depicted by red line on pic).

2. A line plot that plots the opposite extreme of the yellow line plot(as depicted by the cyan line on pic).snakeborders.mq4

Files:
sb.gif  39 kb
 

please someone help to create this indicator for me

Indicator I want

Condition

Buy when Body candle price cross above ma indicator and rsi > rsi 50 after candle close open new candle begin one Blue arrow and Blue Line until Sell

Sell when Body candle price cross bottom ma indicator and rsi < rsi 50 after candle close open new candle begin one Red arrow and Red Line Until Buy

please add input for changing value too

Sorry in my bad english

Thank you so much

Reason: