mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-16 12:18:09 +00:00
Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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
|
||||||
|
|||||||
@@ -655,6 +655,34 @@ 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);
|
||||||
|
}
|
||||||
#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.22")]
|
||||||
[assembly: AssemblyFileVersion("1.0.21")]
|
[assembly: AssemblyFileVersion("1.0.22")]
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
@@ -498,11 +508,6 @@
|
|||||||
</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; }
|
||||||
@@ -75,8 +80,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 +357,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);
|
||||||
@@ -385,8 +393,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 +812,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;
|
||||||
@@ -1177,17 +1245,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 +1733,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.
+133
-34
@@ -1,7 +1,7 @@
|
|||||||
#property copyright "Vyacheslav Demidyuk"
|
#property copyright "Vyacheslav Demidyuk"
|
||||||
#property link ""
|
#property link ""
|
||||||
|
|
||||||
#property version "1.6"
|
#property version "1.7"
|
||||||
#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);
|
||||||
@@ -7521,6 +7619,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