Skip to content

Commit

Permalink
Updated test application (MT5) to perform testing functions iBullsPow…
Browse files Browse the repository at this point in the history
…er, iBearsPower, BarsCalculated, CopyBuffer.
  • Loading branch information
vdemydiuk committed Aug 26, 2020
1 parent dd05804 commit fc54b5d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 20 deletions.
15 changes: 10 additions & 5 deletions TestClients/MtApi5TestClient/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<DockPanel Grid.Row="0" LastChildFill="True">
Expand All @@ -454,6 +455,15 @@
<Button Command="{Binding IndicatorReleaseCommand}" Margin="2"
Content="IndicatorRelease" HorizontalAlignment="Left" />
</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>

Expand Down Expand Up @@ -498,11 +508,6 @@
</Grid>
</TabItem>

<TabItem Header="Indicators">
<WrapPanel VerticalAlignment="Top" Margin="5">
<Button Command="{Binding iCustomCommand}" Content="iCustom" Margin="2"/>
</WrapPanel>
</TabItem>
<TabItem Header="Chart Functions">
<Grid>
<Grid.RowDefinitions>
Expand Down
87 changes: 72 additions & 15 deletions TestClients/MtApi5TestClient/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public class ViewModel : INotifyPropertyChanged
public DelegateCommand CopyCloseCommand { get; private set; }
public DelegateCommand IndicatorCreateCommand { 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 CopyRealVolumeCommand { get; private set; }
Expand Down Expand Up @@ -75,8 +80,6 @@ public class ViewModel : INotifyPropertyChanged
public DelegateCommand AlertCommand { get; private set; }
public DelegateCommand TesterStopCommand { get; private set; }

public DelegateCommand iCustomCommand { get; private set; }

public DelegateCommand TimeCurrentCommand { get; private set; }

public DelegateCommand ChartOpenCommand { get; private set; }
Expand Down Expand Up @@ -354,6 +357,11 @@ private void InitCommands()
CopyCloseCommand = new DelegateCommand(ExecuteCopyClose);
IndicatorCreateCommand = new DelegateCommand(ExecuteIndicatorCreate);
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);
CopyRealVolumeCommand = new DelegateCommand(ExecuteCopyRealVolume);
Expand Down Expand Up @@ -385,8 +393,6 @@ private void InitCommands()
ResetLastErrorCommand = new DelegateCommand(ExecuteResetLastError);
TesterStopCommand = new DelegateCommand(ExecuteTesterStop);

iCustomCommand = new DelegateCommand(ExecuteICustom);

ChartOpenCommand = new DelegateCommand(ExecuteChartOpen);
ChartTimePriceToXYCommand = new DelegateCommand(ExecuteChartTimePriceToXY);
ChartXYToTimePriceCommand = new DelegateCommand(ExecuteChartXYToTimePrice);
Expand Down Expand Up @@ -806,6 +812,68 @@ private async void ExecuteIndicatorRelease(object o)
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)
{
if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;
Expand Down Expand Up @@ -1177,17 +1245,6 @@ private void ExecuteTesterStop(object obj)
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)
{
var retVal = await Execute(() => _mtApiClient.TimeCurrent());
Expand Down

0 comments on commit fc54b5d

Please sign in to comment.