diff --git a/MtApi5/MqlTradeCheckResult.cs b/MtApi5/MqlTradeCheckResult.cs index 81d1a620..d7e9e4ed 100755 --- a/MtApi5/MqlTradeCheckResult.cs +++ b/MtApi5/MqlTradeCheckResult.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MtApi5 +namespace MtApi5 { public class MqlTradeCheckResult { diff --git a/MtApi5/MqlTradeResult.cs b/MtApi5/MqlTradeResult.cs index df3514f7..793c78f8 100755 --- a/MtApi5/MqlTradeResult.cs +++ b/MtApi5/MqlTradeResult.cs @@ -1,8 +1,4 @@ -using System; -using System.Linq; -using System.Text; - -namespace MtApi5 +namespace MtApi5 { public class MqlTradeResult { diff --git a/MtApi5/Mt5CommandType.cs b/MtApi5/Mt5CommandType.cs index dcff8beb..ac62228d 100755 --- a/MtApi5/Mt5CommandType.cs +++ b/MtApi5/Mt5CommandType.cs @@ -100,6 +100,7 @@ //CTrade PositionClose = 64, PositionOpen = 65, + PositionOpenWithResult = 1065, //Backtesting BacktestingReady = 66, diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs index 8d7a6e6d..edb1b316 100755 --- a/MtApi5/MtApi5Client.cs +++ b/MtApi5/MtApi5Client.cs @@ -522,6 +522,25 @@ namespace MtApi5 return SendCommand(Mt5CommandType.PositionOpen, commandParameters); } + + /// + /// Opens a position with the specified parameters. + /// + /// symbol + /// order type to open position + /// position volume + /// execution price + /// Stop Loss price + /// Take Profit price + /// comment + /// true - successful check of the basic structures, otherwise - false. + public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, string comment , out MqlTradeResult result) + { + var commandParameters = new ArrayList { symbol, (int)orderType, volume, price, sl, tp, comment }; + + var strResult = SendCommand(Mt5CommandType.PositionOpenWithResult, commandParameters); + return strResult.ParseResult(ParamSeparator, out result); + } #endregion #region Account Information functions diff --git a/mq5/MtApi5.ex5 b/mq5/MtApi5.ex5 index d7c254e9..dfaf7b15 100755 Binary files a/mq5/MtApi5.ex5 and b/mq5/MtApi5.ex5 differ diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5 index d9b90048..7eaeb7da 100755 --- a/mq5/MtApi5.mq5 +++ b/mq5/MtApi5.mq5 @@ -479,13 +479,16 @@ int executeCommand() break; case 62: //MarketBookGet Execute_MarketBookGet(); - break; + break; case 65: //PositionOpen - Execute_PositionOpen(); + Execute_PositionOpen(false); + break; + case 1065: //PositionOpenWithResult + Execute_PositionOpen(true); break; case 66: //BacktestingReady Execute_BacktestingReady(); - break; + break; case 67: //IsTesting Execute_IsTesting(); break; @@ -2931,8 +2934,8 @@ void Execute_MarketBookGet() } } -void Execute_PositionOpen() -{ +void Execute_PositionOpen(bool isTradeResultRequired) +{ string symbol; int order_type; double volume; @@ -2990,13 +2993,25 @@ void Execute_PositionOpen() symbol, order_type, volume, price, sl, tp, comment); CTrade trade; - bool result = trade.PositionOpen(symbol, (ENUM_ORDER_TYPE)order_type, volume, price, sl, tp, comment); - if (!sendBooleanResponse(ExpertHandle, result, _response_error)) + bool ok = trade.PositionOpen(symbol, (ENUM_ORDER_TYPE)order_type, volume, price, sl, tp, comment); + if (isTradeResultRequired) { - PrintResponseError("PositionOpen", _response_error); + MqlTradeResult tradeResult={0}; + trade.Result(tradeResult); + if (!sendStringResponse(ExpertHandle, ResultToString(ok, tradeResult), _response_error)) + { + PrintResponseError("PositionOpen", _response_error); + } + } + else + { + if (!sendBooleanResponse(ExpertHandle, ok, _response_error)) + { + PrintResponseError("PositionOpen", _response_error); + } } - Print("command PositionOpen: result = ", result); + Print("command PositionOpen: result = ", ok); } void Execute_BacktestingReady()