A quick question about the use of brackets.

 

This is a quick one, no diagnosing or complicated code to look through.

Would the following piece of code, which bas been bracketed at each line, have each line be read by MetaEditor4, or will the brackets have the effect of terminating the programme after the first bracketed condition?

In this instance, I'm needing each bracketed line to be satisfied in order to execute a trade.


if(
      
      shiftOneClose               <    shiftOneOpen
      && (OoTMax                  >= ( bearHammer / ( shiftOneOpen - shiftOneLow ) ))
      && (OoTMax                  >= ( bearHammer / bullNail))
      && (Transform( PCM, 2 )     <=   bearHammer)                       
      && ((bearScrew / bullNail)  <=   pfr)
      && (bullNail                >=   Transform(PCM,2))
      && (iClose(NULL,0,1)        <    iMA(NULL,0,maPeriod,0,MODE_SMA,PRICE_CLOSE,1))
      && (NewBar)
      && (InitOrders              ==   true)
      && (spread                  <=   MaxSpread)
      && ((dayOfWeek              ==   1 && hourOfDay >= 8)|| dayOfWeek == 2 || dayOfWeek == 3 || dayOfWeek == 4 || (dayOfWeek == 5 && hourOfDay < 20))
      && (hourOfDay               >=   8  && hourOfDay < 20)
      && (OrdersTotal()           ==   0)
      && (InitTime                =    true)
      
   )
{

/*Take action*/

}

Happy trading! :) 

 
      && (InitTime                =    true)

This is not testing for true, it's an assignment and will never be false.

 
BCCI:

This is a quick one, no diagnosing or complicated code to look through.

Would the following piece of code, which bas been bracketed at each line, have each line be read by MetaEditor4, or will the brackets have the effect of terminating the programme after the first bracketed condition?

In this instance, I'm needing each bracketed line to be satisfied in order to execute a trade.


Happy trading! :) 

int a = (shiftOneClose<shiftOneOpen) ? 1 : 0;
int b = (OoTMax>=(bearHammer/(shiftOneOpen-shiftOneLow))) ? (OoTMax>=(bearHammer/bullNail)) ? 1 : 0 : 0;
int c = (Transform(PCM,2)<bearHammer) ? 1 : 0;
int d = ((bearScrew/bullNail)<=pfr) ? 1 : 0;
int e = (iClose(NULL,0,1) < iMA(NULL,0,maPeriod,0,MODE_SMA,PRICE_CLOSE,1)) ? 1 : 0;
int f = (NewBar) ? 1 : 0;
int g = (spread <= MaxSpread) ? 1 : 0;
int h = ((dayOfWeek==1)&&(hourOfDay>=8))||((dayOfWeek>1)&&(dayOfWeek<5)||((dayOfWeek==5)&&(hourOfDay<20)) ? 1 : 0;
int i = ((hourOfDay>=8)&&(hourOfDay<20)) ? 1 : 0;
int j = (OrdersTotal()== 0) ? 1 : 0;
int k = (InitTime) ? 1 : 0;

int finaldecision = a + b + c + d + e + f + g + h + i + j + k;

if (finaldecision==11)
{
  /*Take action*/
}

just typed..not tested...

 
This is why I say:

You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.