Closing single position

 

Hi,

My problem is now: I have one sell open and now I want to close it and open a buy position instant execution. Below is my solution and it seems to be doing the trick, but are there other better ways to achieve the aforementioned goal? Thank you for your help community!


         //--- close sell and open buy
         request.action=TRADE_ACTION_DEAL;
         request.price=rates[0].open;            //--- close sell at the open price of the current rightmost candle by buying an amount equal to that sell position
         request.sl=request.price-(SL*_Point*10);
         request.type=ORDER_TYPE_BUY;
         OrderSend(request,result);
         request.action=TRADE_ACTION_DEAL;
         request.price=rates[0].open;            //--- open a new buy position instant execution at the open price of the current rightmost candle
         request.sl=request.price-(SL*_Point*10);
         request.type=ORDER_TYPE_BUY;
         OrderSend(request,result);
         buy_open=true;
         sell_open=false;
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5
 
Candles:

Hi,

My problem is now: I have one sell open and now I want to close it and open a buy position instant execution. Below is my solution and it seems to be doing the trick, but are there other better ways to achieve the aforementioned goal? Thank you for your help community!


Do this manually on demo : open buy 1 lot of EURUSD and then after it opened, open sell 2 lots of EURUSD.

What trade position you have now, and what lot it has ?

Can you code that ? 

 
phi.nuts:

Do this manually on demo : open buy 1 lot of EURUSD and then after it opened, open sell 2 lots of EURUSD.

What trade position you have now, and what lot it has ?

Can you code that ? 

Thanks again, phi.nuts. Tried it and it also solves my problem. I'll try to implement that to my code. I think its good for learning to figure out alternative ways to achieve things.

 

thanks for share useful script
Reason: