Please help with this small problem.

 

Hi

I have this code as part of a function in my EA, basically it looks for breakouts of the upper and lower bands from the start time (bar) thats is specified earlier in the in the EA, up to the current bar plus 3.

By defualt the fucntion returns an empty_value unless I break out the bands is detected, I have managed to get this to work.

What I am trying to do is if there is a breakout found, another part of the function looks to see if, after the breakout time to the current bar plus 3 the price has once again gone back between to bands, this is the part that doesnt seem to work well.

What I find is the last part of code that uses (nlbar) just seems to always return an empty value giving false alarms, can anyone help?

int bar = iBarShift(Symbol(),Period(),t,false);// timestart -> timebar
   if(prewBar==0){prewBar = bar;}
   
   for(i=3;i<bar;i++){
      double bbhi = NormalizeDouble(iCustom(NULL, 0, IndicatorName,1,i),Digits);
      if(Open[i]>Close[i]){
         if(Open[i]>=bbhi){nbar=i;out=-1;break;}
      } 
   }
   for(i=3;i<bar;i++){
      double bblo = NormalizeDouble(iCustom(NULL, 0, IndicatorName,2,i),Digits);
      if(Open[i]<Close[i]){
         if(Open[i]<=bblo){nbar=i;if(out!=EMPTY_VALUE){out+=1;break;}else{out=1;break;}}
      } 
   } 
   int nlbar = iBarShift(Symbol(),Period(),nbar,false);
   for(i=3;i<nlbar;i++){
      if(Close[i]&&Open[i]<bbhi && Close[i]&&Open[i]>bblo){
         out = EMPTY_VALUE;
         break;
         
      } 
   } 
   
   return(out);  
}

Thanks

Antony

 
tonyjms2005:

Hi

I have this code as part of a function in my EA, basically it looks for breakouts of the upper and lower bands from the start time (bar) thats is specified earlier in the in the EA, up to the current bar plus 3.

By defualt the fucntion returns an empty_value unless I break out the bands is detected, I have managed to get this to work.

What I am trying to do is if there is a breakout found, another part of the function looks to see if, after the breakout time to the current bar plus 3 the price has once again gone back between to bands, this is the part that doesnt seem to work well.

Shouldn't you be using Highs and Lows rather than Opens and Closes ? also, does this work ? Close[i]&&Open[i]<bbhi have you tested it ? how can you perform a Logical AND on a double ? i'm not saying it is 100% wrong it just seems that it may well be wrong . . . instead I would do this . . .

Close[i]<bbhi && Open[i]<bbhi

rather than using a loop you can probably use iHighest and iLowest https://docs.mql4.com/series/iHighest & https://docs.mql4.com/series/iLowest

 
RaptorUK:

Shouldn't you be using Highs and Lows rather than Opens and Closes ? also, does this work ? Close[i]&&Open[i]<bbhi have you tested it ? how can you perform a Logical AND on a double ? i'm not saying it is 100% wrong it just seems that it may well be wrong . . . instead I would do this . . .

rather than using a loop you can probably use iHighest and iLowest https://docs.mql4.com/series/iHighest & https://docs.mql4.com/series/iLowest


Hi

Thanks for the reply, just tried that and still no joy :(

I am now trying to add some code to draw a vertical line to represent "nlbar", can anyone give nay pointers on the best way to do this as when I try it seems to output wrong or not at all.

Thanks

Antony

 
tonyjms2005:


Hi

Thanks for the reply, just tried that and still no joy :(

I am now trying to add some code to draw a vertical line to represent "nlbar", can anyone give nay pointers on the best way to do this as when I try it seems to output wrong or not at all.

https://docs.mql4.com/objects/ObjectCreate type OBJ_VLINE you just nee to give ObjectCreate the following values datetime time1, double price1, time1 is the only important value, price1 can be set to 0. Then use https://docs.mql4.com/objects/ObjectSet to set things like the line width, style and colour.
Reason: