Hi , I need some help with some coding. I want to write script to close current open order.. below is my script when I open a trade. What I want to do once the trend has changed I want to close current open trade. My script only allow open 1 trade at one time.
Please, can anyone help..
thanks
See below
>>>
if (cur_trend != pre_trend)//Trend changed
{
if (cur_val-0.01 > cur_val2 || cur_val+0.01 < cur_val1) //Setting 1
{
total =OrdersTotal();
//This where I want to close current open order if any..
if (total<1) //If no open order, proceed to buy or sell
{
if (pre_trend < cur_trend )
{
Print ("Trend has changed to UP ");
ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Ask-250*Point,Ask+300*Point,"My EA",0,0,Green);
}
if (pre_trend > cur_trend )
{
Print ("Trend has changed to DOWN ");
ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Bid+250*Point,Bid-300*Point,"My EA",0,0,Green);
}
Print ("Total Order ", OrdersTotal());
Print ("Orders Type ", OrderType ());
Print ("Orders Open ", OrderOpenPrice());
Print ("Order Ticket ", OrderTicket());
}
}
}
Please, can anyone help..
thanks
See below
>>>
if (cur_trend != pre_trend)//Trend changed
{
if (cur_val-0.01 > cur_val2 || cur_val+0.01 < cur_val1) //Setting 1
{
total =OrdersTotal();
//This where I want to close current open order if any..
if (total<1) //If no open order, proceed to buy or sell
{
if (pre_trend < cur_trend )
{
Print ("Trend has changed to UP ");
ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Ask-250*Point,Ask+300*Point,"My EA",0,0,Green);
}
if (pre_trend > cur_trend )
{
Print ("Trend has changed to DOWN ");
ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Bid+250*Point,Bid-300*Point,"My EA",0,0,Green);
}
Print ("Total Order ", OrdersTotal());
Print ("Orders Type ", OrderType ());
Print ("Orders Open ", OrderOpenPrice());
Print ("Order Ticket ", OrderTicket());
}
}
}