mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-17 04:38:10 +00:00
Issue #186: Implemented function PositionClosePartial
This commit is contained in:
@@ -102,6 +102,8 @@ namespace MtApi5
|
|||||||
PositionClose = 64,
|
PositionClose = 64,
|
||||||
PositionOpen = 65,
|
PositionOpen = 65,
|
||||||
PositionModify = 6066,
|
PositionModify = 6066,
|
||||||
|
PositionClosePartial_bySymbol = 6067,
|
||||||
|
PositionClosePartial_byTicket = 6068,
|
||||||
//PositionOpenWithResult = 1065,
|
//PositionOpenWithResult = 1065,
|
||||||
|
|
||||||
//Backtesting
|
//Backtesting
|
||||||
|
|||||||
@@ -655,6 +655,34 @@ namespace MtApi5
|
|||||||
{
|
{
|
||||||
return PositionOpen(symbol, orderType, volume, price, sl, tp, "", out result);
|
return PositionOpen(symbol, orderType, volume, price, sl, tp, "", out result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Partially closes a position on a specified symbol in case of a "hedging" accounting.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="symbol">Name of a trading instrument, on which a position is closed partially.</param>
|
||||||
|
/// <param name="volume"> Volume, by which a position should be decreased. If the value exceeds the volume of a partially closed position, it is closed in full. No position in the opposite direction is opened.</param>
|
||||||
|
/// <param name="deviation">The maximum deviation from the current price (in points).</param>
|
||||||
|
/// <returns>true if the basic check of structures is successful, otherwise false.</returns>
|
||||||
|
public bool PositionClosePartial(string symbol, double volume, ulong deviation = ulong.MaxValue)
|
||||||
|
{
|
||||||
|
var commandParameters = new ArrayList { symbol, volume, deviation };
|
||||||
|
|
||||||
|
return SendCommand<bool>(Mt5CommandType.PositionClosePartial_bySymbol, commandParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Partially closes a position on a specified symbol in case of a "hedging" accounting.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ticket">Closed position ticket.</param>
|
||||||
|
/// <param name="volume"> Volume, by which a position should be decreased. If the value exceeds the volume of a partially closed position, it is closed in full. No position in the opposite direction is opened.</param>
|
||||||
|
/// <param name="deviation">The maximum deviation from the current price (in points).</param>
|
||||||
|
/// <returns>true if the basic check of structures is successful, otherwise false.</returns>
|
||||||
|
public bool PositionClosePartial(ulong ticket, double volume, ulong deviation = ulong.MaxValue)
|
||||||
|
{
|
||||||
|
var commandParameters = new ArrayList { ticket, volume, deviation };
|
||||||
|
|
||||||
|
return SendCommand<bool>(Mt5CommandType.PositionClosePartial_byTicket, commandParameters);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Account Information functions
|
#region Account Information functions
|
||||||
|
|||||||
Binary file not shown.
@@ -572,6 +572,12 @@ int executeCommand()
|
|||||||
case 6066: //PositionModify
|
case 6066: //PositionModify
|
||||||
Execute_PositionModify();
|
Execute_PositionModify();
|
||||||
break;
|
break;
|
||||||
|
case 6067: //PositionClosePartial_bySymbol
|
||||||
|
Execute_PositionClosePartial_bySymbol();
|
||||||
|
break;
|
||||||
|
case 6068: //Execute_PositionClosePartial_byTicket
|
||||||
|
Execute_PositionClosePartial_byTicket();
|
||||||
|
break;
|
||||||
case 66: //BacktestingReady
|
case 66: //BacktestingReady
|
||||||
Execute_BacktestingReady();
|
Execute_BacktestingReady();
|
||||||
break;
|
break;
|
||||||
@@ -3313,6 +3319,80 @@ void Execute_PositionModify()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Execute_PositionClosePartial_bySymbol()
|
||||||
|
{
|
||||||
|
string symbol;
|
||||||
|
double volume;
|
||||||
|
ulong deviation;
|
||||||
|
|
||||||
|
if (!getStringValue(ExpertHandle, 0, symbol, _error))
|
||||||
|
{
|
||||||
|
PrintParamError("PositionClosePartial (1)", "symbol", _error);
|
||||||
|
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!getDoubleValue(ExpertHandle, 1, volume, _error))
|
||||||
|
{
|
||||||
|
PrintParamError("PositionClosePartial (1)", "volume", _error);
|
||||||
|
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!getULongValue(ExpertHandle, 2, deviation, _error))
|
||||||
|
{
|
||||||
|
PrintParamError("PositionClosePartial (1)", "deviation", _error);
|
||||||
|
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CTrade trade;
|
||||||
|
bool ok = trade.PositionClosePartial(symbol, volume, deviation);
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
|
Print("command PositionClosePartial (1): result = ", ok);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!sendBooleanResponse(ExpertHandle, ok, _response_error))
|
||||||
|
{
|
||||||
|
PrintResponseError("PositionClosePartial (1)", _response_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Execute_PositionClosePartial_byTicket()
|
||||||
|
{
|
||||||
|
ulong ticket;
|
||||||
|
double volume;
|
||||||
|
ulong deviation;
|
||||||
|
|
||||||
|
if (!getULongValue(ExpertHandle, 0, ticket, _error))
|
||||||
|
{
|
||||||
|
PrintParamError("PositionClosePartial (2)", "ticket", _error);
|
||||||
|
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!getDoubleValue(ExpertHandle, 1, volume, _error))
|
||||||
|
{
|
||||||
|
PrintParamError("PositionClosePartial (2)", "volume", _error);
|
||||||
|
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!getULongValue(ExpertHandle, 2, deviation, _error))
|
||||||
|
{
|
||||||
|
PrintParamError("PositionClosePartial (2)", "deviation", _error);
|
||||||
|
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CTrade trade;
|
||||||
|
bool ok = trade.PositionClosePartial(ticket, volume, deviation);
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
|
Print("command PositionClosePartial (2): result = ", ok);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!sendBooleanResponse(ExpertHandle, ok, _response_error))
|
||||||
|
{
|
||||||
|
PrintResponseError("PositionClosePartial (2)", _response_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Execute_PositionOpen(bool isTradeResultRequired)
|
void Execute_PositionOpen(bool isTradeResultRequired)
|
||||||
{
|
{
|
||||||
string symbol;
|
string symbol;
|
||||||
|
|||||||
Reference in New Issue
Block a user