Correct brackets/bracers {}

 

Hi have an EA question, what is the correct way of using icustom. Why i am asking is becuase both ways are working for me with no issues.? :S

Like this?

int start()
  {  
      int n, i;

   double p0, p1, p2, p3, p4, p5;
   i=0;
      while(n<5)
      {
      if(p0>0) {p5=p4; p4=p3; p3=p2; p2=p1; p1=p0; }
      p0=iCustom(Symbol(),0,"mycustomindicator",0,0,3,0,i);
      if(p0>0) {n+=1; }
      i++;
      } 

other code
bla bla bla bla bla

 return(0);
}

Or like this with brackets wrapping the custom indicator.

int start()
  { { 
      int n, i;

   double p0, p1, p2, p3, p4, p5;
   i=0;
      while(n<5)
      {
      if(p0>0) {p5=p4; p4=p3; p3=p2; p2=p1; p1=p0; }
      p0=iCustom(Symbol(),0,"mycustomindicator",0,0,3,0,i);
      if(p0>0) {n+=1; }
      i++;
      } }

other code
bla bla bla bla bla

 return(0);
}

 

Using brackets helps determine which group it goes. Something like ..

// - without brackets
if(2+1>2)Print("1");Print("2");

// - with brackets
if(2+1>2){ Print("3");Print("4"); }
 
deysmacro:

Using brackets helps determine which group it goes. Something like ..


Hi thanks for the fast reply!

Im not that good in cooding. But do you mean that the result in your example would print out only "1" without brackets and "3" and "4" with brackets?

 
Or is it just for helping the coder to see what group it belongs to?
 
Try to play around so that you know what would happens.
 
deysmacro:
Try to play around so that you know what would happens.

=) thanks! Tested just now, and my conclution, - the results is the same and the extra brackets are for the coder to see witch group it belongs to. Or am i wrong??
 
For the coder and machine. Wrong brackets usage will result in wrong executions.
 
deysmacro:
For the coder and machine. Wrong brackets usage will result in wrong executions.

Ok but in this example, the outcome/result is the same? In witch case do you mean that the machine will do something different with these two examples?


// - without brackets
if(2+1>2)Print("1");Print("2");

// - with brackets
if(2+1>2){ Print("3");Print("4"); }
 
deysmacro:

Not much differences since this is simple logic. When it is involved with complex logic, you will see how the brackets works the magic.

Try doing some complex logic and you will see.


Nice =)  Do you know where i can find examples?
 
// - with brackets
if(2+1>4){ Print("3"); } Print("4");

// - with brackets
if(2+1>4){ Print("3"); Print("4"); }

There you have it. Not complex but good enough.
 

So first example returns 4 and second returns 3 & 4

 if(2+1>4){ Print("3"); } Print("4");   //returns 4

 if(2+1<4){ Print("3"); } Print("4");   //returns 3 and 4

And when i play around accordingly to the original question, i get the same results.

 {if(2+1>4){ Print("3"); } Print("4");}   //returns 4

 {if(2+1<4){ Print("3"); } Print("4");}   //returns 3 and 4


Correct me if im wrong. If wrapping in the whole icustom function with brackets, wont do any diffrence, unless its not a part of a complex logic.?

Reason: