mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-18 21:28:10 +00:00
Issue #14: Added function PositionOpen which returns MqlTradeResult
This commit is contained in:
@@ -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,8 +1,4 @@
|
|||||||
using System;
|
namespace MtApi5
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi5
|
|
||||||
{
|
{
|
||||||
public class MqlTradeResult
|
public class MqlTradeResult
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -100,6 +100,7 @@
|
|||||||
//CTrade
|
//CTrade
|
||||||
PositionClose = 64,
|
PositionClose = 64,
|
||||||
PositionOpen = 65,
|
PositionOpen = 65,
|
||||||
|
PositionOpenWithResult = 1065,
|
||||||
|
|
||||||
//Backtesting
|
//Backtesting
|
||||||
BacktestingReady = 66,
|
BacktestingReady = 66,
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Binary file not shown.
+24
-9
@@ -479,13 +479,16 @@ int executeCommand()
|
|||||||
break;
|
break;
|
||||||
case 62: //MarketBookGet
|
case 62: //MarketBookGet
|
||||||
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();
|
||||||
break;
|
break;
|
||||||
case 67: //IsTesting
|
case 67: //IsTesting
|
||||||
Execute_IsTesting();
|
Execute_IsTesting();
|
||||||
break;
|
break;
|
||||||
@@ -2931,8 +2934,8 @@ void Execute_MarketBookGet()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Execute_PositionOpen()
|
void Execute_PositionOpen(bool isTradeResultRequired)
|
||||||
{
|
{
|
||||||
string symbol;
|
string symbol;
|
||||||
int order_type;
|
int order_type;
|
||||||
double volume;
|
double volume;
|
||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user