Download MetaTrader 5
To add comments, please log in or register
Launch agents on an idle PC. It is profitable!
Dominic Gilbert
1632
Dominic Gilbert 2014.09.11 13:10 

As I want my order to close based upon something like "If( BarClose 1 > BarClose 0)"  for longs, how can I write the section so that it WAITS for "Bar 0" above to close BEFORE checking the comparison?

 For a visual example:

 

In this example above, because Bar 1 Close was GREATER than Bar 2 close, DO NOT close the order. Now if Bar 0 closes < Bar 1 close price, CLOSE the order.

I know this is simple, but my brain is fried today.

 Any help will be greatly appreciated :) 

Carl Schreiber
5959
Carl Schreiber 2014.09.11 13:22  

As far as I understand you want to wait until the Bar[0] has closed?

If so you have to compare Bar[1] and Bar[2] at the open of Bar[0].

So if (in your picture) the order was opened at Bar[2] (this will become Bar[3]) and then at open of the (new) Bar[0] /* TmeOpen != Time[0]){TmeOpen = Time[0];} */

CloseOrder(..) if (Close[2]>Close[1])

Dominic Gilbert
1632
Dominic Gilbert 2014.09.11 13:42  
Thanks for your reply, you've lost me a little. Are you talking about the first screenshot or the second one?
Dominic Gilbert
1632
Dominic Gilbert 2014.09.11 13:57  
if( Time[0] > OrderOpenTime() )
  if( Close[2] > Close[1] )
I'm pretty sure this has sorted it... Thanks for your post. You basically made me think about comparing times in the bars!
/
To add comments, please log in or register