
09-20-2009, 08:27 AM
|
|
Junior Member
|
|
Join Date: Jun 2009
Posts: 20
|
|
Quote:
Originally Posted by Roger09
it's just my variant
Code:
int ord;
if (C2<MA2 && C1>MA1) //Trend change from down to up.
{
int total = OrdersTotal(); //Script to close all open orders.
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
if(OrderSymbol()==Simbol()&& OrderType()==1)
{
result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
if(result == false)
{
Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(3000);
}
}
if(OrderSymbol()==Simbol()&& OrderType()==0)ord++;
}
int ticket; //Place Buy Order
RefreshRates();
if(ord==0)ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-1000*Point,Ask+1000*Point,"Buy Order",9999,0,Green);
if(ticket<0)
{
Print("Buy Order failed with error #",GetLastError());
}
return;
}
//---------------------------------------------------------
}
|
Thanks. This version of closing specific trades is more efficient than using script to close all open trades.
Only thing I dont really understand what or how the new variable "ord" does or controls ?
Cheers.
|