Reads correctly but doesn't work often

 
 

  This piece of code is from starting with mql5. it works fine when displaying comments and also opens an order correctly at odd times, the conditions 

 pick up the correct value for the current candle wanted and displays it , buffer is set for 0 because it gets the current candle, as before it had many candle values displaying

and opened positions where ever, if it ever did. I modified the original because the function it had wasn't working at the start of my ea because it was at the start of ontick..

I've tried my own, I've searched through examples through the forum and articles, but this seems to sort of sort of not work and so I'm running with this for now until I learn how to properly

do it on an ea, as most were indicator examples.. so my problem is, I cant get it to open a buy and sell even though it will correct display a comment every time of the current high or low.

 
mmee55:

  This piece of code is from starting with mql5. it works fine when displaying comments and also opens an order correctly at odd times, the conditions 

 pick up the correct value for the current candle wanted and displays it , buffer is set for 0 because it gets the current candle, as before it had many candle values displaying

and opened positions where ever, if it ever did. I modified the original because the function it had wasn't working at the start of my ea because it was at the start of ontick..

I've tried my own, I've searched through examples through the forum and articles, but this seems to sort of sort of not work and so I'm running with this for now until I learn how to properly

do it on an ea, as most were indicator examples.. so my problem is, I cant get it to open a buy and sell even though it will correct display a comment every time of the current high or low.

PLOT_EMPTY_VALUE 

is an enumeration where as

EMPTY_VALUE 

is a constant that should be used here

and copy required data

if(CopyBuffer(ZZH,1,0,count,HBuffer)!=count)return; 
Reason: