if doesn't works well MQL5 [solved] - page 2

 
Keith Watford #:

Do as William said and edit your post to post the code properly.

At the same time it would be a good idea to remove all the unnecessary empty lines. I will not bother to try to read code with so much blank space.

ok sir , i will do that .
 
William Roeder #:
  1. Don't SHOUT at us, that is very RUDE.

  2. Don't Hijack other threads for your off-topic post. Next time, make your own, new, thread.

  3. Just look if a candle is in range.
    Not tested, not compiled, just typed.
    Not tested, not compiled, just typed.


Good day sir , i still dont understand your code . What do you suggest me ?

 
João Buta #:

 Good day everyone , i have just started programming . i programmed the strategy below and would like to know your comment on what the EA is missing and how i can make it more robust ( survive a computer and market crash as well as rectify  errors ) . The strategy is engulfing candle with room to the left it is as follow:

<Deleted>

I have deleted your code as you have not posted it properly.

If you want help, paste the code correctly and remove the unnecessary empty lines.

 
João Buta #:


Good day sir , i still dont understand your code . What do you suggest me ?

I will try to explain this code and if i'm wrong William can correct me.

bool is_empty_left(int iBar, int length){
/* you start your search at location iBar , and essentially
    you are getting the 2 edge points of that bar and store them in H and L
    When you enter the while loop those values will stick and will be what you compare 
    previous bars with.
*/
    double H=iHigh(_Symbol, _Period, iBar), L=iLow(_Symbol, _Period, iBar);
/* so now you enter a loop 
    You have provided how many bars back you want your search to be (with length). Imagine you want to land a 
    plane and you are asking the question "Is the runway free?" 
    If the runway is free this function will give you true.
    So there are 2 things you need to do for every bar you have checked : 
     a.reduce the length because you just checked a bar
     b.increase the # of the bar you are checking so as to not check the same bar always
And this is what the loop says : reduce length by one and if its above zero (the length) meaning if you are not done 
then increase the bar you are checking
*/    
while(length-- > 0){ ++iBar;
/*
and there are two occasions where you know for sure a bar does not interfere with the path of the original bar (H,L). 
If a bar's High is below the initial bar's low OR
If a bar's Low is above the initial bar's high.
And this is what the below check says , if one of the above is true then move on to the next bar (continue)
but if not it means that the bar at iBar is in the way of the path of your initial bar so return false (by letting the loop get there)
*/
        if(iHigh(_Symbol, _Period, iBar) < L
        || iLow( _Symbol, _Period, iBar) > H) continue; // Above or below signal candle.
        return false;
    }
/*
and finally if no path obstruction was found return true as the "path" of the initial bar is free
*/
    return true;
}
Reason: