Download MetaTrader 5
To add comments, please log in or register
Publish your application in Cobe Base. Millions of traders will see it!
jasonchou
14
jasonchou 2014.07.15 09:04 

hi, I am just a beginner I need some help.
one simple code request 

 I tried to write it but fail, I am not sure how to write it.

here is  concept 



if (Close[0]>Close[1]>Close[2])
{
//show signal on chart
}

possible to show signal for 500 bars.

 

thanks in advance

 

.
honest_knave
960
honest_knave 2014.07.15 09:22  

You need to break the code up, as I don't think you want what you have written. I think this is what you mean:

if (Close[0]>Close[1] && Close[1]>Close[2])
{
//show signal on chart
}

 

What you have written means something quite different: if (Close[0]>Close[1]>Close[2])

 

If Close[0] is greater than Close[1], the first bit will evaluate as true (which is numerically represented as 1)

This means you are actually asking if 1 is greater than Close[2].

 

If Close[0] is less than or equal to Close[1], the first bit will evaluate as false (which is numerically represented as 0)

This means you are actually asking if 0 is greater than Close[2].

 

You would get a warning about the above code (unsafe use of bool) 


whroeder1
13610
whroeder1 2014.07.15 12:25  
honest_knave: What you have written means something quite different: if (Close[0]>Close[1]>Close[2])
Exactly. true = 1 and false = 0 so you get
if( 3 < 2 < 1 )
if( false < 1 )
if(     0 < 1 )
if(     true  )
if( 3 > 2 > 1 )
if(  true > 1 )
if(     1 > 1 )
if(     false )
/
To add comments, please log in or register