green bars and even greener bars

 

Why aren't the following expressions synonymous?

(1) Open[0] < Close[0]

(2) Open[0] / Close[0] < 1

I would expect both expressions to describe green bars. The advantage of the second expression is that it could easily be modified to describe "different degrees of green":

(3) Open[0] / Close[0] < 0.9995

 
bjoern:

Why aren't the following expressions synonymous?

(1) Open[0] < Close[0]

(2) Open[0] / Close[0] < 1

What makes you think they aren't ? are you testing both methods on the same tick ? Close[0] == Bid and can change for each tick.
 
RaptorUK:
What makes you think they aren't ? are you testing both methods on the same tick ? Close[0] == Bid and can change for each tick.


I wrote two minimal EAs that are identical except for (1) and (2). I tested them with exactly the same parameters. (1) opened many positions. (2) did not open a single position.
 
bjoern:

I wrote two minimal EAs that are identical except for (1) and (2). I tested them with exactly the same parameters. (1) opened many positions. (2) did not open a single position.

Was the Spread the same for both runs ?

Perhaps you should create some test code to test what you assume is happening.

 

On errors the program skips compiling...

If open>0 and close=0

(1) returns false

(2) returns also false

..but there is division by 0 error so the pg wont be compiled

..try by affecting 0

 

paulselvan:

...

If open>0 and close=0

Another flash crash?
 

I attached a reasonably short EA to this posting. Try the two versions of the function 'prophecy': The EA compiles with both of them. The two versions of the function should be equivalent. But with the first version the EA opens many trades, whereas with the second version it doesn't open a single trade.

Files:
ggrr.mq4  1 kb
 
bjoern:

I attached a reasonably short EA to this posting. Try the two versions of the function prophecy: The EA compiles with both of them. The two versions of the function should be equivalent. But with the first version the EA opens many trades, whereas with the second version it doesn't open a single trade.

By the way . . .

You don't need to comment like this . . .

/* int prophecy() { */

/*   if (Open[0] > Close[0] && Open[1] > Close[1]) { */
/*     return(1); */
/*   } */
/*   if (Open[0] < Close[0] && Open[1] < Close[1]) { */
/*     return(-1); */
/*   } */
/*   return(0); */
/* } */

. . . this will suffice, it makes it quicker to un-comment.

/*int prophecy() { 

   if (Open[0] > Close[0] && Open[1] > Close[1]) { 
     return(1); 
   } 
   if (Open[0] < Close[0] && Open[1] < Close[1]) { 
     return(-1); 
   } 
   return(0); 
 } */
 
bjoern:

I attached a reasonably short EA to this posting. Try the two versions of the function 'prophecy': The EA compiles with both of them. The two versions of the function should be equivalent. But with the first version the EA opens many trades, whereas with the second version it doesn't open a single trade.


I put your function into a script and it worked with no problem at all so I can't understand why it is not working for you.

int p;

  p = prophecy();
  if (p == 1 )
      Alert("Lower");
  if (p == -1 )
      Alert("Higher");
  if (p == 0 )
      Alert("Condition not met");

//------------------------

int prophecy() {
  if (Open[0] / Close[0] > 1 && Open[1] / Close[1] > 1) {
      return(1);
  }
  if (Open[0] / Close[0] < 1 && Open[1] / Close[1] < 1) {
      return(-1);
  }
  return(0);
}

 
RaptorUK:

By the way . . .

You don't need to comment like this . . .

. . . this will suffice, it makes it quicker to un-comment.


I did not insert the comment strings. Emacs did. But next time I will remove unnecessary comment strings manually.
 

It seems that my problem was due to running the code on historical data (using the Tick Data Suite). When using historical data, one does not have any bars in the history at the first tick. To make the problem disappear, one has to make sure that at least two bars are in the history, e.g. by adding the following code at the beginning of the start function:

if (Bars < 2) {
    return(0);
}

Thanks for your help and thanks to Cristi Dumitrescu, the author of the Tick Data Suite.

Reason: