Python / MT5, how to close half a position?
Just look at ..\Include\Trade\Trade.mqh how it closes partially a position, one for hedge, oner for netting accounts:
bool PositionClosePartial(const string symbol,const double volume,const ulong deviation=ULONG_MAX); bool PositionClosePartial(const ulong ticket,const double volume,const ulong deviation=ULONG_MAX);
I mean, where is this file in my system ? If I go in C:\Program Files\MetaTrader 5 I don't see such path
It's a sub-folder of MQL5 data folder.
Forum on trading, automated trading systems and testing trading strategies
Invalid License for all EA (even free ones)
Miguel Angel Vico Alba, 2023.04.26 20:50
Do a Crtl+Shift+D on the terminal or go to the 'File\Open Data Folder' ...
I have tried to replicate what is on this Trade.mqh file:
request = {
"type" : MetaTrader5.ORDER_TYPE_SELL,
"price" : MetaTrader5.symbol_info_tick(symbol).bid,
"action" : MetaTrader5.TRADE_ACTION_DEAL,
"symbol" : symbol,
"volume" : 0.005,
"position" : position_ticket,
} But I get "Unsupported filling mode"
Then I tried, to add
I have tried to replicate what is on this Trade.mqh file:
But I get "Unsupported filling mode"
Then I tried, to add
?? Can you read? In my version of e.g.:
//+------------------------------------------------------------------+ //| Partial close specified opened position (for hedging mode only) | //+------------------------------------------------------------------+ bool CTrade::PositionClosePartial(const string symbol,const double volume,const ulong deviation)
I read:
... //--- check volume double position_volume=PositionGetDouble(POSITION_VOLUME); if(position_volume>volume) position_volume=volume; //--- setting request m_request.action =TRADE_ACTION_DEAL; m_request.symbol =symbol; m_request.volume =position_volume; m_request.magic =m_magic; m_request.deviation=(deviation==ULONG_MAX) ? m_deviation : deviation; m_request.position =PositionGetInteger(POSITION_TICKET); ...
Hello,
I am opening an Buy order with:
I receive this response:
Then, I am sending a close order with:
request = { "action": MetaTrader5.TRADE_ACTION_CLOSE_BY, "position": 36382142, "symbol": "BTCUSD", "volume": 0.005, }Where "position" is the number of the buy order...
And I receive an error:
Any idea why I am getting this "Invalid request" error ?
Thanks