Having trouble combining conditions

To add comments, please log in or register
david
460
david  
 if  (
     (c1>0 && c2>0 && c3>0 && (Close[i]>High[i+1])&& (iSAR(NULL,0,0.01,0.2,i)<Low[i])) &&                
     ((c4>BB_min_Width && c5<c6 && c5>c7 && (Close[i]<c7)) &&
                    (Close[i+1]<(iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,i+1)-2*iStdDev(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i+1))) ||
                    (Close[i+2]<(iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,i+2)-2*iStdDev(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i+2))) || 
                    (Close[i+3]<(iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,i+3)-2*iStdDev(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i+3))) ||
                    (Close[i+4]<(iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,i+4)-2*iStdDev(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i+4))) ||
                    (Close[i+5]<(iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,i+5)-2*iStdDev(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i+5))) 
                    )

                    ) 
                    ExtMapBuffer1[i]=(Low[i]-(PipBuffer)*Point);

Hoping someone might point out to me what I am doing wrong here.
I want to express the Buffer condition such that it is true if (all the conditions in the 2nd line are true) and at the same time 
conditions in the (3rd line combined with the 4th) or (3rd combined with the 5th) or (3rd combined with the 6th)
or (3rd combined with 7th)  or (3rd combined with the 8th) are true
The code compiles ok but I am not achieving my desired outcome.

I am obviously expressing it wrong and need some help
Thanks in advance

Simon Gniadkowski
17274
Simon Gniadkowski  
pullend:

Hoping someone might point out to me what I am doing wrong here. I want to express the Buffer condition such that it is true if (all the conditions in the 2nd line are true) and at the same time conditions in the (3rd line combined with the 4th) or (3rd combined with the 5th) or (3rd combined with the 6th) or (3rd combined with 7th) or (3rd combined with the 8th) are true The code compiles ok but I am not achieving my desired outcome.

I am obviously expressing it wrong and need some help

Thanks in advance


Without rigorously checking your ( ) braces . . . it looks OK to me.

Scott
68
Scott  

Try breaking the logic into parts and then recombine them later:

bool mandatory = false, optional = false;

//must satisfy ALL of these conditions
mandatory =
    c1>0 &&
    c2>0 &&
    c3>0 &&
    Close[i]>High[i+1] &&
    iSAR(NULL,0,0.01,0.2,i)<Low[i] &&
    c4>BB_min_Width &&
    c5<c6 &&
    c5>c7 &&
    Close[i]<c7;

//must satisfy ONE OR MORE of these conditions
optional =
    Close[i+1]<(iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,i+1)-2*iStdDev(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i+1)) ||
    Close[i+2]<(iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,i+2)-2*iStdDev(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i+2)) || 
    Close[i+3]<(iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,i+3)-2*iStdDev(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i+3)) ||
    Close[i+4]<(iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,i+4)-2*iStdDev(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i+4)) ||
    Close[i+5]<(iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,i+5)-2*iStdDev(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i+5));

if(mandatory && optional)
    ExtMapBuffer1[i]=Low[i]-(PipBuffer)*Point;

Untested code crudely thrown together in notepad... but you should get the idea?

david
460
david  
wabbit:

Try breaking the logic into parts and then recombine them later:

Untested code crudely thrown together in notepad... but you should get the idea?




brilliant thanks for help
david
460
david  
RaptorUK:
Without rigorously checking your ( ) braces . . . it looks OK to me.

thanks Raptor, you were right.

I am not sure how you experts do it, but by cutting and pasting the code into Microsoft word and using the find function, I eventually found and evened up the missing brackets

now I can start working on getting the working code a lot less sloppy

thanks

dave

To add comments, please log in or register