Issue #14: Added function PositionOpen which returns MqlTradeResult

This commit is contained in:
DW
2017-09-29 18:27:36 +03:00
parent add69a4c03
commit cd24891022
6 changed files with 46 additions and 20 deletions
+1 -6
View File
@@ -1,9 +1,4 @@
using System; namespace MtApi5
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MtApi5
{ {
public class MqlTradeCheckResult public class MqlTradeCheckResult
{ {
+1 -5
View File
@@ -1,8 +1,4 @@
using System; namespace MtApi5
using System.Linq;
using System.Text;
namespace MtApi5
{ {
public class MqlTradeResult public class MqlTradeResult
{ {
+1
View File
@@ -100,6 +100,7 @@
//CTrade //CTrade
PositionClose = 64, PositionClose = 64,
PositionOpen = 65, PositionOpen = 65,
PositionOpenWithResult = 1065,
//Backtesting //Backtesting
BacktestingReady = 66, BacktestingReady = 66,
+19
View File
@@ -522,6 +522,25 @@ namespace MtApi5
return SendCommand<bool>(Mt5CommandType.PositionOpen, commandParameters); return SendCommand<bool>(Mt5CommandType.PositionOpen, commandParameters);
} }
/// <summary>
/// Opens a position with the specified parameters.
/// </summary>
/// <param name="symbol">symbol</param>
/// <param name="orderType">order type to open position </param>
/// <param name="volume">position volume</param>
/// <param name="price">execution price</param>
/// <param name="sl">Stop Loss price</param>
/// <param name="tp">Take Profit price</param>
/// <param name="comment">comment</param>
/// <returns>true - successful check of the basic structures, otherwise - false.</returns>
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<string>(Mt5CommandType.PositionOpenWithResult, commandParameters);
return strResult.ParseResult(ParamSeparator, out result);
}
#endregion #endregion
#region Account Information functions #region Account Information functions
BIN
View File
Binary file not shown.
+21 -6
View File
@@ -481,7 +481,10 @@ int executeCommand()
Execute_MarketBookGet(); Execute_MarketBookGet();
break; break;
case 65: //PositionOpen case 65: //PositionOpen
Execute_PositionOpen(); Execute_PositionOpen(false);
break;
case 1065: //PositionOpenWithResult
Execute_PositionOpen(true);
break; break;
case 66: //BacktestingReady case 66: //BacktestingReady
Execute_BacktestingReady(); Execute_BacktestingReady();
@@ -2931,7 +2934,7 @@ void Execute_MarketBookGet()
} }
} }
void Execute_PositionOpen() void Execute_PositionOpen(bool isTradeResultRequired)
{ {
string symbol; string symbol;
int order_type; int order_type;
@@ -2990,13 +2993,25 @@ void Execute_PositionOpen()
symbol, order_type, volume, price, sl, tp, comment); symbol, order_type, volume, price, sl, tp, comment);
CTrade trade; CTrade trade;
bool result = trade.PositionOpen(symbol, (ENUM_ORDER_TYPE)order_type, volume, price, sl, tp, comment); bool ok = trade.PositionOpen(symbol, (ENUM_ORDER_TYPE)order_type, volume, price, sl, tp, comment);
if (!sendBooleanResponse(ExpertHandle, result, _response_error)) 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() void Execute_BacktestingReady()