Download MetaTrader 5
To add comments, please log in or register
Share links from other resources. Now they have a description.
Maryam
78
Maryam 2012.10.31 10:52 

Hi

How can I close some of volume(lot) a position?

Equivalent   OrderClose(OrderTicket(),0.01,Ask,3,Violet)  in mql4.

Andrei Moraru
1142
Andrei Moraru 2012.10.31 10:59  

Just send an opposite direction order for the volume you want to close.
Maryam
78
Maryam 2012.10.31 11:12  
enivid:

Just send an opposite direction order for the volume you want to close.

mean, if was position sell send position buy

It's a big weakness for MQL5

phi nuts
2185
phi nuts 2012.10.31 11:47  
Maryam:

Hi

How can I close some of volume(lot) a position?

Equivalent   OrderClose(OrderTicket(),0.01,Ask,3,Violet)  in mql4.

Your question is about mql4, and it should be searched first  (click here or here) and then asked at mql4 forum http://forum.mql4.com/ - there's plenty discussion about partial close over there

In mql4 use OrderCloseBy() (http://docs.mql4.com/trading/OrderCloseBy), that is if your broker allow to close some part of position.

Its much easier in mql5, say you have 1 lot open buy then to close partial of it just send - say 0.7 lot or 0.33 lot of open sell. 

MQL4: search
  • www.mql4.com
MQL4: search
Christian Vost
641
Christian Vost 2012.10.31 12:10  
Maryam:

Hi

How can I close some of volume(lot) a position?

Equivalent   OrderClose(OrderTicket(),0.01,Ask,3,Violet)  in mql4.

To close a percentage of a position, you can replace the Trade file with this modified version. It is located in MQL5>>Include>>Trade>>Trade. This modification to the .trade file will also allow a 'partial close' of a position, when calling PositionClose().  Notice a modification to the PositionClose() method on line 95:

bool    PositionClose(const string symbol,const ulong percent = 100,const ulong deviation=ULONG_MAX);

Const ulong 'percent' stores the percentage value of the position to close out first. When calling PositionClose() without stating a percent of the total volume to close, PositionClose()  will attempt close out 100%, as normal. Also refer to line 329 and line 367. You will need to modify your EA ( the order close loop ) and perhaps include a scalar to block or permit the partial close. See the code segments below:

   
if(GetPositionInfo(symbol,pos)) // save data about pos      {       //--- close by time       if(close_all)         {             Print("close_all:",close_all);             if(m_trade.PositionClose(symbol))                 {                 close_all=false;                 alreadyPartClosed = false;                 recalc=true;             }              return;         }                if(part_close)         {             Print("part_close:",part_close);             if(m_trade.PositionClose(symbol, partially_exit_param.exit_percent))             {                 part_close=false;                 alreadyPartClosed = true;                 recalc=true;             }              return;         }
    //--- close percent of position volume by first trigger line
         if(bid>=BuyCloseBuffer[0] && !alreadyPartClosed)
           {
               if (partially_exit_param.scale_out && ScaleOutSignal) 
                   
               {            
                   part_close = true;
                   return;
               }
               else
               {
                   close_all=true;
                   return;
               }               
           }
    //--- close remaining position volume by second trigger line  
         if(alreadyPartClosed && bid>=BuyCloseBuffer2[0])
           {                   
                   close_all = true;
                   return;
           }

 

The above code is just an example, but I run a very similar EA and it works fine. 

Chris_V 

Files:
Trade.mqh 44 kb
Maryam
78
Maryam 2012.10.31 15:03  

Thank Chris_V very helpful


Maryam
78
Maryam 2012.10.31 15:05  

Thank you all
/
To add comments, please log in or register