mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-28 11:07:48 +00:00
Issue #14: Added function PositionOpen which returns MqlTradeResult
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MtApi5
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlTradeCheckResult
|
||||
{
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MtApi5
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlTradeResult
|
||||
{
|
||||
|
||||
@@ -100,6 +100,7 @@
|
||||
//CTrade
|
||||
PositionClose = 64,
|
||||
PositionOpen = 65,
|
||||
PositionOpenWithResult = 1065,
|
||||
|
||||
//Backtesting
|
||||
BacktestingReady = 66,
|
||||
|
||||
@@ -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
|
||||
|
||||
Binary file not shown.
+24
-9
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user