mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-17 20:58:11 +00:00
Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a5acac2db | ||
|
|
7a776de8d3 | ||
|
|
ce7953eee0 | ||
|
|
93aed4e44c | ||
|
|
4c8c3b8766 | ||
|
|
73ebde8b6b | ||
|
|
e33ba5b51f | ||
|
|
a0a4263e24 | ||
|
|
5d18dd4ad3 | ||
|
|
03ff1f9176 | ||
|
|
f376b4e0e5 | ||
|
|
fc54b5dd4a | ||
|
|
dd05804082 | ||
|
|
4349eb3538 | ||
|
|
e0daf9a82e | ||
|
|
3997b6df74 | ||
|
|
abfe1a281a |
@@ -208,6 +208,16 @@ _DLLAPI int _stdcall sendMqlRatesArrayResponse(int expertHandle, CMqlRates value
|
|||||||
}, err, 0);
|
}, err, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_DLLAPI bool _stdcall sendErrorResponse(int expertHandle, int code, wchar_t* message, wchar_t* err)
|
||||||
|
{
|
||||||
|
return Execute<bool>([&expertHandle, &code, message]() {
|
||||||
|
MtResponseString^ res = gcnew MtResponseString(gcnew String(message));
|
||||||
|
res->ErrorCode = code;
|
||||||
|
MtAdapter::GetInstance()->SendResponse(expertHandle, res);
|
||||||
|
return true;
|
||||||
|
}, err, false);
|
||||||
|
}
|
||||||
|
|
||||||
//----------- get values -------------------------------
|
//----------- get values -------------------------------
|
||||||
|
|
||||||
_DLLAPI int _stdcall getCommandType(int expertHandle, int* res, wchar_t* err)
|
_DLLAPI int _stdcall getCommandType(int expertHandle, int* res, wchar_t* err)
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.31.0")]
|
[assembly: AssemblyVersion("1.0.32.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.31.0")]
|
[assembly: AssemblyFileVersion("1.0.32.0")]
|
||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.40.0")]
|
[assembly: AssemblyVersion("1.0.41.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.40.0")]
|
[assembly: AssemblyFileVersion("1.0.41.0")]
|
||||||
@@ -102,6 +102,8 @@ namespace MtApi5
|
|||||||
PositionClose = 64,
|
PositionClose = 64,
|
||||||
PositionOpen = 65,
|
PositionOpen = 65,
|
||||||
PositionModify = 6066,
|
PositionModify = 6066,
|
||||||
|
PositionClosePartial_bySymbol = 6067,
|
||||||
|
PositionClosePartial_byTicket = 6068,
|
||||||
//PositionOpenWithResult = 1065,
|
//PositionOpenWithResult = 1065,
|
||||||
|
|
||||||
//Backtesting
|
//Backtesting
|
||||||
|
|||||||
@@ -78,6 +78,7 @@
|
|||||||
<Compile Include="Events\Mt5EventTypes.cs" />
|
<Compile Include="Events\Mt5EventTypes.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Mt5Quote.cs" />
|
<Compile Include="Mt5Quote.cs" />
|
||||||
|
<Compile Include="Requests\BuyRequest.cs" />
|
||||||
<Compile Include="Requests\ChartTimePriceToXyRequest.cs" />
|
<Compile Include="Requests\ChartTimePriceToXyRequest.cs" />
|
||||||
<Compile Include="Requests\ChartTimePriceToXyResult.cs" />
|
<Compile Include="Requests\ChartTimePriceToXyResult.cs" />
|
||||||
<Compile Include="Requests\ChartXyToTimePriceRequest.cs" />
|
<Compile Include="Requests\ChartXyToTimePriceRequest.cs" />
|
||||||
@@ -88,6 +89,7 @@
|
|||||||
<Compile Include="Requests\MarketBookGetRequest.cs" />
|
<Compile Include="Requests\MarketBookGetRequest.cs" />
|
||||||
<Compile Include="Requests\OrderCheckRequest.cs" />
|
<Compile Include="Requests\OrderCheckRequest.cs" />
|
||||||
<Compile Include="Requests\OrderCheckResult.cs" />
|
<Compile Include="Requests\OrderCheckResult.cs" />
|
||||||
|
<Compile Include="Requests\OrderSendAsyncRequest.cs" />
|
||||||
<Compile Include="Requests\OrderSendRequest.cs" />
|
<Compile Include="Requests\OrderSendRequest.cs" />
|
||||||
<Compile Include="Requests\PositionCloseRequest.cs" />
|
<Compile Include="Requests\PositionCloseRequest.cs" />
|
||||||
<Compile Include="Requests\PositionCloseResult.cs" />
|
<Compile Include="Requests\PositionCloseResult.cs" />
|
||||||
@@ -96,6 +98,7 @@
|
|||||||
<Compile Include="Requests\RequestType.cs" />
|
<Compile Include="Requests\RequestType.cs" />
|
||||||
<Compile Include="Requests\OrderSendResult.cs" />
|
<Compile Include="Requests\OrderSendResult.cs" />
|
||||||
<Compile Include="Requests\Response.cs" />
|
<Compile Include="Requests\Response.cs" />
|
||||||
|
<Compile Include="Requests\SellRequest.cs" />
|
||||||
<Compile Include="Requests\SymbolInfoStringRequest.cs" />
|
<Compile Include="Requests\SymbolInfoStringRequest.cs" />
|
||||||
<Compile Include="Requests\SymbolInfoStringResult.cs" />
|
<Compile Include="Requests\SymbolInfoStringResult.cs" />
|
||||||
<Compile Include="Requests\SymbolInfoTickRequest.cs" />
|
<Compile Include="Requests\SymbolInfoTickRequest.cs" />
|
||||||
|
|||||||
@@ -134,6 +134,38 @@ namespace MtApi5
|
|||||||
return response != null && response.RetVal;
|
return response != null && response.RetVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
///Function is used for conducting asynchronous trade operations without waiting for the trade server's response to a sent request.
|
||||||
|
///</summary>
|
||||||
|
///<param name="request">Reference to a object of MqlTradeRequest type describing the trade activity of the client.</param>
|
||||||
|
///<param name="result">Reference to a object of MqlTradeResult type describing the result of trade operation in case of a successful completion (if true is returned).</param>
|
||||||
|
/// <returns>
|
||||||
|
/// Returns true if the request is sent to a trade server. In case the request is not sent, it returns false.
|
||||||
|
/// In case the request is sent, in the result variable the response code contains TRADE_RETCODE_PLACED value (code 10008) – "order placed".
|
||||||
|
/// Successful execution means only the fact of sending, but does not give any guarantee that the request has reached the trade server and has been accepted for processing.
|
||||||
|
/// When processing the received request, a trade server sends a reply to a client terminal notifying of change in the current state of positions,
|
||||||
|
/// orders and deals, which leads to the generation of the Trade event.
|
||||||
|
/// </returns>
|
||||||
|
public bool OrderSendAsync(MqlTradeRequest request, out MqlTradeResult result)
|
||||||
|
{
|
||||||
|
Log.Debug($"OrderSend: request = {request}");
|
||||||
|
|
||||||
|
if (request == null)
|
||||||
|
{
|
||||||
|
Log.Warn("OrderSend: request is not defined!");
|
||||||
|
result = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = SendRequest<OrderSendResult>(new OrderSendAsyncRequest
|
||||||
|
{
|
||||||
|
TradeRequest = request
|
||||||
|
});
|
||||||
|
|
||||||
|
result = response?.TradeResult;
|
||||||
|
return response != null && response.RetVal;
|
||||||
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///The function calculates the margin required for the specified order type, on the current account
|
///The function calculates the margin required for the specified order type, on the current account
|
||||||
///, in the current market environment not taking into account current pending orders and open positions
|
///, in the current market environment not taking into account current pending orders and open positions
|
||||||
@@ -655,6 +687,92 @@ namespace MtApi5
|
|||||||
{
|
{
|
||||||
return PositionOpen(symbol, orderType, volume, price, sl, tp, "", out result);
|
return PositionOpen(symbol, orderType, volume, price, sl, tp, "", out result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Partially closes a position on a specified symbol in case of a "hedging" accounting.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="symbol">Name of a trading instrument, on which a position is closed partially.</param>
|
||||||
|
/// <param name="volume"> Volume, by which a position should be decreased. If the value exceeds the volume of a partially closed position, it is closed in full. No position in the opposite direction is opened.</param>
|
||||||
|
/// <param name="deviation">The maximum deviation from the current price (in points).</param>
|
||||||
|
/// <returns>true if the basic check of structures is successful, otherwise false.</returns>
|
||||||
|
public bool PositionClosePartial(string symbol, double volume, ulong deviation = ulong.MaxValue)
|
||||||
|
{
|
||||||
|
var commandParameters = new ArrayList { symbol, volume, deviation };
|
||||||
|
|
||||||
|
return SendCommand<bool>(Mt5CommandType.PositionClosePartial_bySymbol, commandParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Partially closes a position on a specified symbol in case of a "hedging" accounting.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ticket">Closed position ticket.</param>
|
||||||
|
/// <param name="volume"> Volume, by which a position should be decreased. If the value exceeds the volume of a partially closed position, it is closed in full. No position in the opposite direction is opened.</param>
|
||||||
|
/// <param name="deviation">The maximum deviation from the current price (in points).</param>
|
||||||
|
/// <returns>true if the basic check of structures is successful, otherwise false.</returns>
|
||||||
|
public bool PositionClosePartial(ulong ticket, double volume, ulong deviation = ulong.MaxValue)
|
||||||
|
{
|
||||||
|
var commandParameters = new ArrayList { ticket, volume, deviation };
|
||||||
|
|
||||||
|
return SendCommand<bool>(Mt5CommandType.PositionClosePartial_byTicket, commandParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens a long position with specified parameters with current market Ask price
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="result">output result</param>
|
||||||
|
/// <param name="volume">Requested position volume.</param>
|
||||||
|
/// <param name="symbol">Position symbol. If it is not specified, the current symbol will be used.</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 structures, otherwise - false.</returns>
|
||||||
|
public bool Buy(out MqlTradeResult result, double volume, string symbol = null, double price = 0.0, double sl = 0.0, double tp = 0.0, string comment = null)
|
||||||
|
{
|
||||||
|
Log.Debug($"Buy: volume = {volume}, symbol = {symbol}, sl = {sl}, tp = {tp}, comment = {comment}");
|
||||||
|
|
||||||
|
var response = SendRequest<OrderSendResult>(new BuyRequest
|
||||||
|
{
|
||||||
|
Volume = volume,
|
||||||
|
Symbol = symbol,
|
||||||
|
Price = price,
|
||||||
|
Sl = sl,
|
||||||
|
Tp = tp,
|
||||||
|
Comment = comment
|
||||||
|
});
|
||||||
|
|
||||||
|
result = response?.TradeResult;
|
||||||
|
return response != null && response.RetVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens a short position with specified parameters with current market Bid price
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="result">output result</param>
|
||||||
|
/// <param name="volume">Requested position volume.</param>
|
||||||
|
/// <param name="symbol">Position symbol. If it is not specified, the current symbol will be used.</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 structures, otherwise - false.</returns>
|
||||||
|
public bool Sell(out MqlTradeResult result, double volume, string symbol = null, double price = 0.0, double sl = 0.0, double tp = 0.0, string comment = null)
|
||||||
|
{
|
||||||
|
Log.Debug($"Sell: volume = {volume}, symbol = {symbol}, sl = {sl}, tp = {tp}, comment = {comment}");
|
||||||
|
|
||||||
|
var response = SendRequest<OrderSendResult>(new SellRequest
|
||||||
|
{
|
||||||
|
Volume = volume,
|
||||||
|
Symbol = symbol,
|
||||||
|
Price = price,
|
||||||
|
Sl = sl,
|
||||||
|
Tp = tp,
|
||||||
|
Comment = comment
|
||||||
|
});
|
||||||
|
|
||||||
|
result = response?.TradeResult;
|
||||||
|
return response != null && response.RetVal;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Account Information functions
|
#region Account Information functions
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.21")]
|
[assembly: AssemblyVersion("1.0.23")]
|
||||||
[assembly: AssemblyFileVersion("1.0.21")]
|
[assembly: AssemblyFileVersion("1.0.23")]
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class BuyRequest : RequestBase
|
||||||
|
{
|
||||||
|
public override RequestType RequestType => RequestType.Buy;
|
||||||
|
|
||||||
|
public double Volume { get; set; }
|
||||||
|
public string Symbol { get; set; }
|
||||||
|
public double Price { get; set; }
|
||||||
|
public double Sl { get; set; }
|
||||||
|
public double Tp { get; set; }
|
||||||
|
public string Comment { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class OrderSendAsyncRequest : RequestBase
|
||||||
|
{
|
||||||
|
public override RequestType RequestType => RequestType.OrderSendAsync;
|
||||||
|
|
||||||
|
public MqlTradeRequest TradeRequest { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,9 @@ namespace MtApi5.Requests
|
|||||||
ChartTimePriceToXY = 9,
|
ChartTimePriceToXY = 9,
|
||||||
ChartXYToTimePrice = 10,
|
ChartXYToTimePrice = 10,
|
||||||
PositionClose = 11,
|
PositionClose = 11,
|
||||||
SymbolInfoTick = 12
|
SymbolInfoTick = 12,
|
||||||
|
Buy = 13,
|
||||||
|
Sell = 14,
|
||||||
|
OrderSendAsync = 15
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class SellRequest : RequestBase
|
||||||
|
{
|
||||||
|
public override RequestType RequestType => RequestType.Sell;
|
||||||
|
|
||||||
|
public double Volume { get; set; }
|
||||||
|
public string Symbol { get; set; }
|
||||||
|
public double Price { get; set; }
|
||||||
|
public double Sl { get; set; }
|
||||||
|
public double Tp { get; set; }
|
||||||
|
public string Comment { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,4 +20,8 @@ MQL files have been build to ex4 and stored into folders "mq4" for MetaTrader an
|
|||||||
Changing the source code of MQL expert requires recompilation with MetaEditor. Resulting in the need to copy files "hash.mqh" and "json.mqh" to the MetaEditor include folder.
|
Changing the source code of MQL expert requires recompilation with MetaEditor. Resulting in the need to copy files "hash.mqh" and "json.mqh" to the MetaEditor include folder.
|
||||||
|
|
||||||
# Home Website
|
# Home Website
|
||||||
Please visit http://mtapi4.net
|
|
||||||
|
# Telegram Channel
|
||||||
|
https://t.me/mtapi4
|
||||||
|
|
||||||
|
https://t.me/joinchat/GfnfUxvelQCLvvIvLO16-w
|
||||||
@@ -439,6 +439,7 @@
|
|||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<DockPanel Grid.Row="0" LastChildFill="True">
|
<DockPanel Grid.Row="0" LastChildFill="True">
|
||||||
@@ -454,6 +455,15 @@
|
|||||||
<Button Command="{Binding IndicatorReleaseCommand}" Margin="2"
|
<Button Command="{Binding IndicatorReleaseCommand}" Margin="2"
|
||||||
Content="IndicatorRelease" HorizontalAlignment="Left" />
|
Content="IndicatorRelease" HorizontalAlignment="Left" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
<WrapPanel Grid.Row="2" Margin="2">
|
||||||
|
<Button Command="{Binding iCustomCommand}" Content="iCustom" Margin="2"/>
|
||||||
|
<Button Command="{Binding iBullsPowerCommand}" Content="iBullPower" Margin="2"/>
|
||||||
|
<Button Command="{Binding iBearsPowerCommand}" Content="iBearPower" Margin="2"/>
|
||||||
|
</WrapPanel>
|
||||||
|
<WrapPanel Grid.Row="3">
|
||||||
|
<Button Command="{Binding BarsCalculatedCommand}" Content="BarsCalculated" Margin="2"/>
|
||||||
|
<Button Command="{Binding CopyBufferCommand}" Content="CopyBuffer" Margin="2"/>
|
||||||
|
</WrapPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
@@ -487,6 +497,7 @@
|
|||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Button Grid.Row="0" Command="{Binding PositionOpenCommand}" Content="PositionOpen" Margin="2" HorizontalAlignment="Left"/>
|
<Button Grid.Row="0" Command="{Binding PositionOpenCommand}" Content="PositionOpen" Margin="2" HorizontalAlignment="Left"/>
|
||||||
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="4">
|
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="4">
|
||||||
@@ -495,14 +506,13 @@
|
|||||||
<Button Command="{Binding PositionCloseCommand}" Content="PositionClose" Margin="2"/>
|
<Button Command="{Binding PositionCloseCommand}" Content="PositionClose" Margin="2"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Button Grid.Row="2" Command="{Binding PositionCloseAllCommand}" Content="PositionCloseAll" Margin="2" HorizontalAlignment="Left"/>
|
<Button Grid.Row="2" Command="{Binding PositionCloseAllCommand}" Content="PositionCloseAll" Margin="2" HorizontalAlignment="Left"/>
|
||||||
|
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="4">
|
||||||
|
<Button Command="{Binding BuyCommand}" Content="Buy" Width="60" Margin="2" HorizontalAlignment="Left"/>
|
||||||
|
<Button Command="{Binding SellCommand}" Content="Sell" Width="60" Margin="2" HorizontalAlignment="Left"/>
|
||||||
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
<TabItem Header="Indicators">
|
|
||||||
<WrapPanel VerticalAlignment="Top" Margin="5">
|
|
||||||
<Button Command="{Binding iCustomCommand}" Content="iCustom" Margin="2"/>
|
|
||||||
</WrapPanel>
|
|
||||||
</TabItem>
|
|
||||||
<TabItem Header="Chart Functions">
|
<TabItem Header="Chart Functions">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ namespace MtApi5TestClient
|
|||||||
public DelegateCommand CopyCloseCommand { get; private set; }
|
public DelegateCommand CopyCloseCommand { get; private set; }
|
||||||
public DelegateCommand IndicatorCreateCommand { get; private set; }
|
public DelegateCommand IndicatorCreateCommand { get; private set; }
|
||||||
public DelegateCommand IndicatorReleaseCommand { get; private set; }
|
public DelegateCommand IndicatorReleaseCommand { get; private set; }
|
||||||
|
public DelegateCommand iCustomCommand { get; private set; }
|
||||||
|
public DelegateCommand iBullsPowerCommand { get; private set; }
|
||||||
|
public DelegateCommand iBearsPowerCommand { get; private set; }
|
||||||
|
public DelegateCommand BarsCalculatedCommand { get; private set; }
|
||||||
|
public DelegateCommand CopyBufferCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand CopyTickVolumeCommand { get; private set; }
|
public DelegateCommand CopyTickVolumeCommand { get; private set; }
|
||||||
public DelegateCommand CopyRealVolumeCommand { get; private set; }
|
public DelegateCommand CopyRealVolumeCommand { get; private set; }
|
||||||
@@ -68,6 +73,8 @@ namespace MtApi5TestClient
|
|||||||
public DelegateCommand PositionOpenCommand { get; private set; }
|
public DelegateCommand PositionOpenCommand { get; private set; }
|
||||||
public DelegateCommand PositionCloseCommand { get; private set; }
|
public DelegateCommand PositionCloseCommand { get; private set; }
|
||||||
public DelegateCommand PositionCloseAllCommand { get; private set; }
|
public DelegateCommand PositionCloseAllCommand { get; private set; }
|
||||||
|
public DelegateCommand BuyCommand { get; private set; }
|
||||||
|
public DelegateCommand SellCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand GetLastErrorCommand { get; private set; }
|
public DelegateCommand GetLastErrorCommand { get; private set; }
|
||||||
public DelegateCommand ResetLastErrorCommand { get; private set; }
|
public DelegateCommand ResetLastErrorCommand { get; private set; }
|
||||||
@@ -75,8 +82,6 @@ namespace MtApi5TestClient
|
|||||||
public DelegateCommand AlertCommand { get; private set; }
|
public DelegateCommand AlertCommand { get; private set; }
|
||||||
public DelegateCommand TesterStopCommand { get; private set; }
|
public DelegateCommand TesterStopCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand iCustomCommand { get; private set; }
|
|
||||||
|
|
||||||
public DelegateCommand TimeCurrentCommand { get; private set; }
|
public DelegateCommand TimeCurrentCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand ChartOpenCommand { get; private set; }
|
public DelegateCommand ChartOpenCommand { get; private set; }
|
||||||
@@ -354,6 +359,11 @@ namespace MtApi5TestClient
|
|||||||
CopyCloseCommand = new DelegateCommand(ExecuteCopyClose);
|
CopyCloseCommand = new DelegateCommand(ExecuteCopyClose);
|
||||||
IndicatorCreateCommand = new DelegateCommand(ExecuteIndicatorCreate);
|
IndicatorCreateCommand = new DelegateCommand(ExecuteIndicatorCreate);
|
||||||
IndicatorReleaseCommand = new DelegateCommand(ExecuteIndicatorRelease);
|
IndicatorReleaseCommand = new DelegateCommand(ExecuteIndicatorRelease);
|
||||||
|
iCustomCommand = new DelegateCommand(ExecuteICustom);
|
||||||
|
iBullsPowerCommand = new DelegateCommand(ExecuteIBullsPowerCommand);
|
||||||
|
iBearsPowerCommand = new DelegateCommand(ExecuteIBearsPowerCommand);
|
||||||
|
BarsCalculatedCommand = new DelegateCommand(ExecuteBarsCalculatedCommand);
|
||||||
|
CopyBufferCommand = new DelegateCommand(ExecuteCopyBufferCommand);
|
||||||
|
|
||||||
CopyTickVolumeCommand = new DelegateCommand(ExecuteCopyTickVolume);
|
CopyTickVolumeCommand = new DelegateCommand(ExecuteCopyTickVolume);
|
||||||
CopyRealVolumeCommand = new DelegateCommand(ExecuteCopyRealVolume);
|
CopyRealVolumeCommand = new DelegateCommand(ExecuteCopyRealVolume);
|
||||||
@@ -378,6 +388,8 @@ namespace MtApi5TestClient
|
|||||||
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
|
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
|
||||||
PositionCloseCommand = new DelegateCommand(ExecutePositionClose);
|
PositionCloseCommand = new DelegateCommand(ExecutePositionClose);
|
||||||
PositionCloseAllCommand = new DelegateCommand(ExecutePositionCloseAll);
|
PositionCloseAllCommand = new DelegateCommand(ExecutePositionCloseAll);
|
||||||
|
BuyCommand = new DelegateCommand(ExecuteBuy);
|
||||||
|
SellCommand = new DelegateCommand(ExecuteSell);
|
||||||
|
|
||||||
PrintCommand = new DelegateCommand(ExecutePrint);
|
PrintCommand = new DelegateCommand(ExecutePrint);
|
||||||
AlertCommand = new DelegateCommand(ExecuteAlert);
|
AlertCommand = new DelegateCommand(ExecuteAlert);
|
||||||
@@ -385,8 +397,6 @@ namespace MtApi5TestClient
|
|||||||
ResetLastErrorCommand = new DelegateCommand(ExecuteResetLastError);
|
ResetLastErrorCommand = new DelegateCommand(ExecuteResetLastError);
|
||||||
TesterStopCommand = new DelegateCommand(ExecuteTesterStop);
|
TesterStopCommand = new DelegateCommand(ExecuteTesterStop);
|
||||||
|
|
||||||
iCustomCommand = new DelegateCommand(ExecuteICustom);
|
|
||||||
|
|
||||||
ChartOpenCommand = new DelegateCommand(ExecuteChartOpen);
|
ChartOpenCommand = new DelegateCommand(ExecuteChartOpen);
|
||||||
ChartTimePriceToXYCommand = new DelegateCommand(ExecuteChartTimePriceToXY);
|
ChartTimePriceToXYCommand = new DelegateCommand(ExecuteChartTimePriceToXY);
|
||||||
ChartXYToTimePriceCommand = new DelegateCommand(ExecuteChartXYToTimePrice);
|
ChartXYToTimePriceCommand = new DelegateCommand(ExecuteChartXYToTimePrice);
|
||||||
@@ -806,6 +816,68 @@ namespace MtApi5TestClient
|
|||||||
AddLog($"IndicatorRelease [{indicatorHandle}]: result - {retVal}");
|
AddLog($"IndicatorRelease [{indicatorHandle}]: result - {retVal}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void ExecuteICustom(object o)
|
||||||
|
{
|
||||||
|
const string name = @"Examples\Custom Moving Average";
|
||||||
|
int[] parameters = { 0, 21, (int)ENUM_APPLIED_PRICE.PRICE_CLOSE };
|
||||||
|
|
||||||
|
var retVal = await Execute(() => _mtApiClient.iCustom(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, name, parameters));
|
||||||
|
TimeSeriesValues.IndicatorHandle = retVal;
|
||||||
|
AddLog($"Custom Moving Average: result - {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteIBullsPowerCommand(object o)
|
||||||
|
{
|
||||||
|
const int maPeriod = 13;
|
||||||
|
var retVal = await Execute(() => _mtApiClient.iBullsPower(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, maPeriod));
|
||||||
|
TimeSeriesValues.IndicatorHandle = retVal;
|
||||||
|
|
||||||
|
AddLog($"iBullPower: result - {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteIBearsPowerCommand(object o)
|
||||||
|
{
|
||||||
|
const int maPeriod = 13;
|
||||||
|
var retVal = await Execute(() => _mtApiClient.iBearsPower(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, maPeriod));
|
||||||
|
TimeSeriesValues.IndicatorHandle = retVal;
|
||||||
|
|
||||||
|
AddLog($"iBearsPower: result - {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteBarsCalculatedCommand(object o)
|
||||||
|
{
|
||||||
|
var retVal = await Execute(() => _mtApiClient.BarsCalculated(TimeSeriesValues.IndicatorHandle));
|
||||||
|
|
||||||
|
AddLog($"BarsCalculated: result - {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteCopyBufferCommand(object o)
|
||||||
|
{
|
||||||
|
TimeSeriesResults.Clear();
|
||||||
|
|
||||||
|
var result = await Execute(() =>
|
||||||
|
{
|
||||||
|
var count = _mtApiClient.CopyBuffer(TimeSeriesValues.IndicatorHandle, 0, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out var values);
|
||||||
|
return count > 0 ? values : null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
AddLog("CopyRates: result is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RunOnUiThread(() =>
|
||||||
|
{
|
||||||
|
foreach (var value in result)
|
||||||
|
{
|
||||||
|
TimeSeriesResults.Add($"{value:F6}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AddLog("CopyRates: success");
|
||||||
|
}
|
||||||
|
|
||||||
private async void ExecuteCopyRates(object o)
|
private async void ExecuteCopyRates(object o)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;
|
if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;
|
||||||
@@ -1143,6 +1215,26 @@ namespace MtApi5TestClient
|
|||||||
AddLog($"PositionCloseAll: count = {retVal}");
|
AddLog($"PositionCloseAll: count = {retVal}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void ExecuteBuy(object obj)
|
||||||
|
{
|
||||||
|
const string symbol = "EURUSD";
|
||||||
|
const double volume = 0.1;
|
||||||
|
MqlTradeResult tradeResult = null;
|
||||||
|
|
||||||
|
var retVal = await Execute(() => _mtApiClient.Buy(out tradeResult, volume, symbol));
|
||||||
|
AddLog($"Buy: symbol EURUSD retVal = {retVal}, result = {tradeResult}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteSell(object obj)
|
||||||
|
{
|
||||||
|
const string symbol = "EURUSD";
|
||||||
|
const double volume = 0.1;
|
||||||
|
MqlTradeResult tradeResult = null;
|
||||||
|
|
||||||
|
var retVal = await Execute(() => _mtApiClient.Sell(out tradeResult, volume, symbol));
|
||||||
|
AddLog($"Sell: symbol EURUSD retVal = {retVal}, result = {tradeResult}");
|
||||||
|
}
|
||||||
|
|
||||||
private async void ExecutePrint(object obj)
|
private async void ExecutePrint(object obj)
|
||||||
{
|
{
|
||||||
var message = MessageText;
|
var message = MessageText;
|
||||||
@@ -1177,17 +1269,6 @@ namespace MtApi5TestClient
|
|||||||
AddLog("TesterStop: executed.");
|
AddLog("TesterStop: executed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void ExecuteICustom(object o)
|
|
||||||
{
|
|
||||||
const string symbol = "EURUSD";
|
|
||||||
const ENUM_TIMEFRAMES timeframe = ENUM_TIMEFRAMES.PERIOD_H1;
|
|
||||||
const string name = @"Examples\Custom Moving Average";
|
|
||||||
int[] parameters = { 0, 21, (int)ENUM_APPLIED_PRICE.PRICE_CLOSE };
|
|
||||||
|
|
||||||
var retVal = await Execute(() => _mtApiClient.iCustom(symbol, timeframe, name, parameters));
|
|
||||||
AddLog($"Custom Moving Average: result - {retVal}");
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void ExecuteTimeCurrent(object o)
|
private async void ExecuteTimeCurrent(object o)
|
||||||
{
|
{
|
||||||
var retVal = await Execute(() => _mtApiClient.TimeCurrent());
|
var retVal = await Execute(() => _mtApiClient.TimeCurrent());
|
||||||
@@ -1676,7 +1757,7 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
private void _mtApiClient_OnLastTimeBar(object sender, Mt5TimeBarArgs e)
|
private void _mtApiClient_OnLastTimeBar(object sender, Mt5TimeBarArgs e)
|
||||||
{
|
{
|
||||||
AddLog($"OnBookEvent: ExpertHandle = {e.ExpertHandle}, Symbol = {e.Symbol}, open = {e.Rates.open}, close = {e.Rates.close}, time = {e.Rates.time}, high = {e.Rates.high}, low = {e.Rates.low}");
|
AddLog($"OnLastTimeBarEvent: ExpertHandle = {e.ExpertHandle}, Symbol = {e.Symbol}, open = {e.Rates.open}, close = {e.Rates.close}, time = {e.Rates.time}, high = {e.Rates.high}, low = {e.Rates.low}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _mtApiClient_OnLockTicks(object sender, Mt5LockTicksEventArgs e)
|
private void _mtApiClient_OnLockTicks(object sender, Mt5LockTicksEventArgs e)
|
||||||
|
|||||||
Binary file not shown.
+258
-34
@@ -1,7 +1,7 @@
|
|||||||
#property copyright "Vyacheslav Demidyuk"
|
#property copyright "Vyacheslav Demidyuk"
|
||||||
#property link ""
|
#property link ""
|
||||||
|
|
||||||
#property version "1.6"
|
#property version "1.9"
|
||||||
#property description "MtApi (MT5) connection expert"
|
#property description "MtApi (MT5) connection expert"
|
||||||
|
|
||||||
#include <json.mqh>
|
#include <json.mqh>
|
||||||
@@ -50,6 +50,12 @@ enum LockTickType
|
|||||||
|
|
||||||
input int Port = 8228;
|
input int Port = 8228;
|
||||||
input LockTickType BacktestingLockTicks = NO_LOCK;
|
input LockTickType BacktestingLockTicks = NO_LOCK;
|
||||||
|
input group "Disable Events "
|
||||||
|
input bool Enable_OnBookEvent = true;
|
||||||
|
input bool Enable_OnTickEvent = true;
|
||||||
|
input bool Enable_OnTradeTransactionEvent = true;
|
||||||
|
input bool Enable_OnLastBarEvent = true;
|
||||||
|
|
||||||
|
|
||||||
int ExpertHandle;
|
int ExpertHandle;
|
||||||
|
|
||||||
@@ -89,27 +95,31 @@ void OnTick()
|
|||||||
long lastbar_time = SeriesInfoInteger(symbol, Period(), SERIES_LASTBAR_DATE);
|
long lastbar_time = SeriesInfoInteger(symbol, Period(), SERIES_LASTBAR_DATE);
|
||||||
if (_last_bar_open_time != lastbar_time)
|
if (_last_bar_open_time != lastbar_time)
|
||||||
{
|
{
|
||||||
if (_last_bar_open_time != 0)
|
if (_last_bar_open_time != 0 )
|
||||||
{
|
{
|
||||||
MqlRates rates_array[];
|
if(Enable_OnLastBarEvent)
|
||||||
CopyRates(symbol, Period(), 1, 1, rates_array);
|
{
|
||||||
|
MqlRates rates_array[];
|
||||||
|
CopyRates(symbol, Period(), 1, 1, rates_array);
|
||||||
|
|
||||||
MtTimeBarEvent* time_bar = new MtTimeBarEvent(symbol, rates_array[0]);
|
MtTimeBarEvent* time_bar = new MtTimeBarEvent(symbol, rates_array[0]);
|
||||||
SendMtEvent(ON_LAST_TIME_BAR_EVENT, time_bar);
|
SendMtEvent(ON_LAST_TIME_BAR_EVENT, time_bar);
|
||||||
delete time_bar;
|
delete time_bar;
|
||||||
|
}
|
||||||
lastbar_time_changed = true;
|
lastbar_time_changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_last_bar_open_time = lastbar_time;
|
_last_bar_open_time = lastbar_time;
|
||||||
}
|
}
|
||||||
|
if (Enable_OnTickEvent)
|
||||||
MqlTick last_tick;
|
{
|
||||||
SymbolInfoTick(Symbol(),last_tick);
|
MqlTick last_tick;
|
||||||
|
SymbolInfoTick(Symbol(),last_tick);
|
||||||
|
|
||||||
MtOnTickEvent * tick_event = new MtOnTickEvent(symbol, last_tick);
|
MtOnTickEvent * tick_event = new MtOnTickEvent(symbol, last_tick);
|
||||||
SendMtEvent(ON_TICK_EVENT, tick_event);
|
SendMtEvent(ON_TICK_EVENT, tick_event);
|
||||||
delete tick_event;
|
delete tick_event;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsTesting())
|
if (IsTesting())
|
||||||
{
|
{
|
||||||
@@ -132,29 +142,37 @@ void OnTradeTransaction(
|
|||||||
const MqlTradeRequest& request, // request structure
|
const MqlTradeRequest& request, // request structure
|
||||||
const MqlTradeResult& result // result structure
|
const MqlTradeResult& result // result structure
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
#ifdef __DEBUG_LOG__
|
if(!Enable_OnTradeTransactionEvent) return;
|
||||||
PrintFormat("%s:", __FUNCTION__);
|
|
||||||
#endif
|
#ifdef __DEBUG_LOG__
|
||||||
|
PrintFormat("%s:", __FUNCTION__);
|
||||||
MtOnTradeTransactionEvent* trans_event = new MtOnTradeTransactionEvent(trans, request, result);
|
#endif
|
||||||
SendMtEvent(ON_TRADE_TRANSACTION_EVENT, trans_event);
|
|
||||||
delete trans_event;
|
|
||||||
}
|
MtOnTradeTransactionEvent* trans_event = new MtOnTradeTransactionEvent(trans, request, result);
|
||||||
|
SendMtEvent(ON_TRADE_TRANSACTION_EVENT, trans_event);
|
||||||
|
delete trans_event;
|
||||||
|
|
||||||
|
}
|
||||||
void OnBookEvent(const string& symbol)
|
void OnBookEvent(const string& symbol)
|
||||||
{
|
{
|
||||||
#ifdef __DEBUG_LOG__
|
|
||||||
PrintFormat("%s: %s", __FUNCTION__, symbol);
|
if(!Enable_OnBookEvent) return;
|
||||||
#endif
|
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
|
PrintFormat("%s: %s", __FUNCTION__, symbol);
|
||||||
|
#endif
|
||||||
|
|
||||||
MtOnBookEvent * book_event = new MtOnBookEvent(symbol);
|
MtOnBookEvent * book_event = new MtOnBookEvent(symbol);
|
||||||
SendMtEvent(ON_BOOK_EVENT, book_event);
|
SendMtEvent(ON_BOOK_EVENT, book_event);
|
||||||
delete book_event;
|
delete book_event;
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
int preinit()
|
int preinit()
|
||||||
{
|
{
|
||||||
|
StringInit(_error,1000,0);
|
||||||
StringInit(_response_error,1000,0);
|
StringInit(_response_error,1000,0);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
@@ -555,6 +573,12 @@ int executeCommand()
|
|||||||
case 6066: //PositionModify
|
case 6066: //PositionModify
|
||||||
Execute_PositionModify();
|
Execute_PositionModify();
|
||||||
break;
|
break;
|
||||||
|
case 6067: //PositionClosePartial_bySymbol
|
||||||
|
Execute_PositionClosePartial_bySymbol();
|
||||||
|
break;
|
||||||
|
case 6068: //Execute_PositionClosePartial_byTicket
|
||||||
|
Execute_PositionClosePartial_byTicket();
|
||||||
|
break;
|
||||||
case 66: //BacktestingReady
|
case 66: //BacktestingReady
|
||||||
Execute_BacktestingReady();
|
Execute_BacktestingReady();
|
||||||
break;
|
break;
|
||||||
@@ -3296,6 +3320,80 @@ void Execute_PositionModify()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Execute_PositionClosePartial_bySymbol()
|
||||||
|
{
|
||||||
|
string symbol;
|
||||||
|
double volume;
|
||||||
|
ulong deviation;
|
||||||
|
|
||||||
|
if (!getStringValue(ExpertHandle, 0, symbol, _error))
|
||||||
|
{
|
||||||
|
PrintParamError("PositionClosePartial (1)", "symbol", _error);
|
||||||
|
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!getDoubleValue(ExpertHandle, 1, volume, _error))
|
||||||
|
{
|
||||||
|
PrintParamError("PositionClosePartial (1)", "volume", _error);
|
||||||
|
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!getULongValue(ExpertHandle, 2, deviation, _error))
|
||||||
|
{
|
||||||
|
PrintParamError("PositionClosePartial (1)", "deviation", _error);
|
||||||
|
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CTrade trade;
|
||||||
|
bool ok = trade.PositionClosePartial(symbol, volume, deviation);
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
|
Print("command PositionClosePartial (1): result = ", ok);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!sendBooleanResponse(ExpertHandle, ok, _response_error))
|
||||||
|
{
|
||||||
|
PrintResponseError("PositionClosePartial (1)", _response_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Execute_PositionClosePartial_byTicket()
|
||||||
|
{
|
||||||
|
ulong ticket;
|
||||||
|
double volume;
|
||||||
|
ulong deviation;
|
||||||
|
|
||||||
|
if (!getULongValue(ExpertHandle, 0, ticket, _error))
|
||||||
|
{
|
||||||
|
PrintParamError("PositionClosePartial (2)", "ticket", _error);
|
||||||
|
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!getDoubleValue(ExpertHandle, 1, volume, _error))
|
||||||
|
{
|
||||||
|
PrintParamError("PositionClosePartial (2)", "volume", _error);
|
||||||
|
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!getULongValue(ExpertHandle, 2, deviation, _error))
|
||||||
|
{
|
||||||
|
PrintParamError("PositionClosePartial (2)", "deviation", _error);
|
||||||
|
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CTrade trade;
|
||||||
|
bool ok = trade.PositionClosePartial(ticket, volume, deviation);
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
|
Print("command PositionClosePartial (2): result = ", ok);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!sendBooleanResponse(ExpertHandle, ok, _response_error))
|
||||||
|
{
|
||||||
|
PrintResponseError("PositionClosePartial (2)", _response_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Execute_PositionOpen(bool isTradeResultRequired)
|
void Execute_PositionOpen(bool isTradeResultRequired)
|
||||||
{
|
{
|
||||||
string symbol;
|
string symbol;
|
||||||
@@ -4457,7 +4555,7 @@ void Execute_iBullsPower()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sendIntResponse(ExpertHandle,
|
if (!sendIntResponse(ExpertHandle,
|
||||||
iBearsPower(symbol, (ENUM_TIMEFRAMES)period, ma_period),
|
iBullsPower(symbol, (ENUM_TIMEFRAMES)period, ma_period),
|
||||||
_error))
|
_error))
|
||||||
{
|
{
|
||||||
PrintResponseError("iBullsPower", _response_error);
|
PrintResponseError("iBullsPower", _response_error);
|
||||||
@@ -6858,6 +6956,15 @@ string OnRequest(string json)
|
|||||||
case 12: //SymbolInfoTick
|
case 12: //SymbolInfoTick
|
||||||
response = ExecuteRequest_SymbolInfoTick(jo);
|
response = ExecuteRequest_SymbolInfoTick(jo);
|
||||||
break;
|
break;
|
||||||
|
case 13: //Buy
|
||||||
|
response = ExecuteRequest_Buy(jo);
|
||||||
|
break;
|
||||||
|
case 14: //Sell
|
||||||
|
response = ExecuteRequest_Sell(jo);
|
||||||
|
break;
|
||||||
|
case 15: //OrderSendAsync
|
||||||
|
response = ExecuteRequest_OrderSendAsync(jo);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
PrintFormat("%s [WARNING]: Unknown request type %d", __FUNCTION__, requestType);
|
PrintFormat("%s [WARNING]: Unknown request type %d", __FUNCTION__, requestType);
|
||||||
response = CreateErrorResponse(-1, "Unknown request type");
|
response = CreateErrorResponse(-1, "Unknown request type");
|
||||||
@@ -7067,6 +7174,30 @@ string ExecuteRequest_OrderSend(JSONObject *jo)
|
|||||||
return CreateSuccessResponse("Value", result_value_jo);
|
return CreateSuccessResponse("Value", result_value_jo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string ExecuteRequest_OrderSendAsync(JSONObject *jo)
|
||||||
|
{
|
||||||
|
CHECK_JSON_VALUE(jo, "TradeRequest", CreateErrorResponse(-1, "Undefinded mandatory parameter TradeRequest"));
|
||||||
|
JSONObject* trade_request_jo = jo.getObject("TradeRequest");
|
||||||
|
|
||||||
|
MqlTradeRequest trade_request = {0};
|
||||||
|
bool converted = JsonToMqlTradeRequest(trade_request_jo, trade_request);
|
||||||
|
if (converted == false)
|
||||||
|
return CreateErrorResponse(-1, "Failed to parse parameter TradeRequest");
|
||||||
|
|
||||||
|
MqlTradeResult trade_result = {0};
|
||||||
|
bool ok = OrderSendAsync(trade_request, trade_result);
|
||||||
|
|
||||||
|
JSONObject* result_value_jo = new JSONObject();
|
||||||
|
result_value_jo.put("RetVal", new JSONBool(ok));
|
||||||
|
result_value_jo.put("TradeResult", MqlTradeResultToJson(trade_result));
|
||||||
|
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
|
PrintFormat("%s: return value = %s", __FUNCTION__, ok ? "true" : "false");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return CreateSuccessResponse("Value", result_value_jo);
|
||||||
|
}
|
||||||
|
|
||||||
string ExecuteRequest_PositionOpen(JSONObject *jo)
|
string ExecuteRequest_PositionOpen(JSONObject *jo)
|
||||||
{
|
{
|
||||||
//Symbol
|
//Symbol
|
||||||
@@ -7389,6 +7520,98 @@ string ExecuteRequest_SymbolInfoTick(JSONObject *jo)
|
|||||||
return CreateSuccessResponse("Value", MqlTickToJson(tick));
|
return CreateSuccessResponse("Value", MqlTickToJson(tick));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string ExecuteRequest_Buy(JSONObject *jo)
|
||||||
|
{
|
||||||
|
//Symbol
|
||||||
|
string symbol=Symbol();
|
||||||
|
if (jo.getValue("Symbol") != NULL)
|
||||||
|
symbol = jo.getString("Symbol");
|
||||||
|
|
||||||
|
//Volume
|
||||||
|
CHECK_JSON_VALUE(jo, "Volume", CreateErrorResponse(-1, "Undefinded mandatory parameter Volume"));
|
||||||
|
double volume = jo.getDouble("Volume");
|
||||||
|
|
||||||
|
//Price
|
||||||
|
CHECK_JSON_VALUE(jo, "Price", CreateErrorResponse(-1, "Undefinded mandatory parameter Price"));
|
||||||
|
double price = jo.getDouble("Price");
|
||||||
|
|
||||||
|
//Sl
|
||||||
|
CHECK_JSON_VALUE(jo, "Sl", CreateErrorResponse(-1, "Undefinded mandatory parameter Sl"));
|
||||||
|
double sl = jo.getDouble("Sl");
|
||||||
|
|
||||||
|
//Tp
|
||||||
|
CHECK_JSON_VALUE(jo, "Tp", CreateErrorResponse(-1, "Undefinded mandatory parameter Tp"));
|
||||||
|
double tp = jo.getDouble("Tp");
|
||||||
|
|
||||||
|
//Comment
|
||||||
|
string comment="";
|
||||||
|
if (jo.getValue("Comment") != NULL)
|
||||||
|
comment = jo.getString("Comment");
|
||||||
|
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
|
PrintFormat("%s: symbol = %s, volume = %f, price = %f, sl = %f, tp = %f, comment = %s",
|
||||||
|
__FUNCTION__, symbol, volume, price, sl, tp, comment);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CTrade trade;
|
||||||
|
bool ok = trade.Buy(volume, symbol, price, sl, tp, comment);
|
||||||
|
|
||||||
|
MqlTradeResult trade_result={0};
|
||||||
|
trade.Result(trade_result);
|
||||||
|
|
||||||
|
JSONObject* result_value_jo = new JSONObject();
|
||||||
|
result_value_jo.put("RetVal", new JSONBool(ok));
|
||||||
|
result_value_jo.put("TradeResult", MqlTradeResultToJson(trade_result));
|
||||||
|
|
||||||
|
return CreateSuccessResponse("Value", result_value_jo);
|
||||||
|
}
|
||||||
|
|
||||||
|
string ExecuteRequest_Sell(JSONObject *jo)
|
||||||
|
{
|
||||||
|
//Symbol
|
||||||
|
string symbol=Symbol();
|
||||||
|
if (jo.getValue("Symbol") != NULL)
|
||||||
|
symbol = jo.getString("Symbol");
|
||||||
|
|
||||||
|
//Volume
|
||||||
|
CHECK_JSON_VALUE(jo, "Volume", CreateErrorResponse(-1, "Undefinded mandatory parameter Volume"));
|
||||||
|
double volume = jo.getDouble("Volume");
|
||||||
|
|
||||||
|
//Price
|
||||||
|
CHECK_JSON_VALUE(jo, "Price", CreateErrorResponse(-1, "Undefinded mandatory parameter Price"));
|
||||||
|
double price = jo.getDouble("Price");
|
||||||
|
|
||||||
|
//Sl
|
||||||
|
CHECK_JSON_VALUE(jo, "Sl", CreateErrorResponse(-1, "Undefinded mandatory parameter Sl"));
|
||||||
|
double sl = jo.getDouble("Sl");
|
||||||
|
|
||||||
|
//Tp
|
||||||
|
CHECK_JSON_VALUE(jo, "Tp", CreateErrorResponse(-1, "Undefinded mandatory parameter Tp"));
|
||||||
|
double tp = jo.getDouble("Tp");
|
||||||
|
|
||||||
|
//Comment
|
||||||
|
string comment="";
|
||||||
|
if (jo.getValue("Comment") != NULL)
|
||||||
|
comment = jo.getString("Comment");
|
||||||
|
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
|
PrintFormat("%s: symbol = %s, volume = %f, price = %f, sl = %f, tp = %f, comment = %s",
|
||||||
|
__FUNCTION__, symbol, volume, price, sl, tp, comment);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CTrade trade;
|
||||||
|
bool ok = trade.Sell(volume, symbol, price, sl, tp, comment);
|
||||||
|
|
||||||
|
MqlTradeResult trade_result={0};
|
||||||
|
trade.Result(trade_result);
|
||||||
|
|
||||||
|
JSONObject* result_value_jo = new JSONObject();
|
||||||
|
result_value_jo.put("RetVal", new JSONBool(ok));
|
||||||
|
result_value_jo.put("TradeResult", MqlTradeResultToJson(trade_result));
|
||||||
|
|
||||||
|
return CreateSuccessResponse("Value", result_value_jo);
|
||||||
|
}
|
||||||
|
|
||||||
//------------ Events -------------------------------------------------------
|
//------------ Events -------------------------------------------------------
|
||||||
|
|
||||||
enum MtEventTypes
|
enum MtEventTypes
|
||||||
@@ -7521,6 +7744,7 @@ void SendMtEvent(MtEventTypes eventType, MtEvent* mtEvent)
|
|||||||
if (sendEvent(ExpertHandle, (int)eventType, json.toString(), _error))
|
if (sendEvent(ExpertHandle, (int)eventType, json.toString(), _error))
|
||||||
{
|
{
|
||||||
#ifdef __DEBUG_LOG__
|
#ifdef __DEBUG_LOG__
|
||||||
|
PrintFormat("%s: event = %s", __FUNCTION__, EnumToString(eventType));
|
||||||
PrintFormat("%s: payload = %s", __FUNCTION__, json.toString());
|
PrintFormat("%s: payload = %s", __FUNCTION__, json.toString());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user