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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MtApi5
namespace MtApi5
{
public class MqlTradeCheckResult
{
+1 -5
View File
@@ -1,8 +1,4 @@
using System;
using System.Linq;
using System.Text;
namespace MtApi5
namespace MtApi5
{
public class MqlTradeResult
{
+1
View File
@@ -100,6 +100,7 @@
//CTrade
PositionClose = 64,
PositionOpen = 65,
PositionOpenWithResult = 1065,
//Backtesting
BacktestingReady = 66,
+19
View File
@@ -522,6 +522,25 @@ namespace MtApi5
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
#region Account Information functions
BIN
View File
Binary file not shown.
+24 -9
View File
@@ -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()