How to make a reverse order at same bar?

 

Please can anybody help me? I will use it as stop loss, but it only closes the current order, but don't open the reverse one...

{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);

Sleep(10000);


ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"ReverzKoupeno",777,0,Blue);
if(ticket > 0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("Nakoupeno za: ",OrderOpenPrice());

}
else Print("Error opening BUY order : ",GetLastError());

return(0);
}

the error is 4051 - invalid lots amount for OrderSend function

I don't understand this, because Lots is specified and will be same as for the closed order... or should I calculate it again?


Thanks for help

maarty


PS: sorry for my english

 

Hi Martin,

I don't see an assignment for your Lots variable. Unless it is done somewhere else that you are not showing it is probably = 0. Before you close the previous order you need to do something like Lots = OrderLots() (after selecting the order of course).

Whenever you have a problem like this the best way to test it is with a Print or Alert statement - something like Alert("Lots=",Lots); Insert this statment in your code just before the OrderSend command. This will give you a dialog box that will show you the Lots value.

Hope this helps.

- Tovan

Reason: