Thread: Ask!
View Single Post
  #1061 (permalink)  
Old 04-27-2008, 09:20 AM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 519
Michel is on a distinguished road
Quote:
Originally Posted by bearfoot090 View Post
hi there!

can some here help me add this function. Make it to close trade when the bar is completed or in another word to make it close the trade when the next bar appear.( doesnt matter the trade is profit or loss )
To detect a new bar there are several solutions:

1)
PHP Code:
if(Volume[0] == 1CloseOrders(); 
Not very reliable, for example if the terminal has to be restarted you may loose the first tick of the bar.

2)
PHP Code:
if(BarsCnt Bars) {BarsCnt BarsCloseOrders();} 
Not very reliable, for example if new bars are added to the left of the chart.

3)
PHP Code:
if(Time1 Time[0]) {Time1 Time[0]; CloseOrders();} 
Better, but again, restarting the terminal may produce wrong behaviors.

So my opinion is that the best is to write the lifetime max of each order into the order itself, using the "Comment" field :
PHP Code:
OrderSend(..., ""+(Time[0] + Period()*60), ..); 
Then you can scan the orders and check :
PHP Code:
if(TimeCurrent() > OrderComment()) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0CLR_NONE); 
. This is a good solution because if you have several orders to close, you have all the time needed to do it.
Reply With Quote