Quote:
Originally Posted by bearfoot090
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] == 1) CloseOrders();
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 = Bars; CloseOrders();}
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(), 0, CLR_NONE);
. This is a good solution because if you have several orders to close, you have all the time needed to do it.