Skip to content

Commit fc54b5d

Browse files
committed
Updated test application (MT5) to perform testing functions iBullsPower, iBearsPower, BarsCalculated, CopyBuffer.
1 parent dd05804 commit fc54b5d

File tree

2 files changed

+82
-20
lines changed

2 files changed

+82
-20
lines changed

TestClients/MtApi5TestClient/MainWindow.xaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@
439439
<RowDefinition Height="Auto"/>
440440
<RowDefinition Height="Auto"/>
441441
<RowDefinition Height="Auto"/>
442+
<RowDefinition Height="Auto"/>
442443
</Grid.RowDefinitions>
443444

444445
<DockPanel Grid.Row="0" LastChildFill="True">
@@ -454,6 +455,15 @@
454455
<Button Command="{Binding IndicatorReleaseCommand}" Margin="2"
455456
Content="IndicatorRelease" HorizontalAlignment="Left" />
456457
</StackPanel>
458+
<WrapPanel Grid.Row="2" Margin="2">
459+
<Button Command="{Binding iCustomCommand}" Content="iCustom" Margin="2"/>
460+
<Button Command="{Binding iBullsPowerCommand}" Content="iBullPower" Margin="2"/>
461+
<Button Command="{Binding iBearsPowerCommand}" Content="iBearPower" Margin="2"/>
462+
</WrapPanel>
463+
<WrapPanel Grid.Row="3">
464+
<Button Command="{Binding BarsCalculatedCommand}" Content="BarsCalculated" Margin="2"/>
465+
<Button Command="{Binding CopyBufferCommand}" Content="CopyBuffer" Margin="2"/>
466+
</WrapPanel>
457467
</Grid>
458468
</Grid>
459469

@@ -498,11 +508,6 @@
498508
</Grid>
499509
</TabItem>
500510

501-
<TabItem Header="Indicators">
502-
<WrapPanel VerticalAlignment="Top" Margin="5">
503-
<Button Command="{Binding iCustomCommand}" Content="iCustom" Margin="2"/>
504-
</WrapPanel>
505-
</TabItem>
506511
<TabItem Header="Chart Functions">
507512
<Grid>
508513
<Grid.RowDefinitions>

TestClients/MtApi5TestClient/ViewModel.cs

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public class ViewModel : INotifyPropertyChanged
4444
public DelegateCommand CopyCloseCommand { get; private set; }
4545
public DelegateCommand IndicatorCreateCommand { get; private set; }
4646
public DelegateCommand IndicatorReleaseCommand { get; private set; }
47+
public DelegateCommand iCustomCommand { get; private set; }
48+
public DelegateCommand iBullsPowerCommand { get; private set; }
49+
public DelegateCommand iBearsPowerCommand { get; private set; }
50+
public DelegateCommand BarsCalculatedCommand { get; private set; }
51+
public DelegateCommand CopyBufferCommand { get; private set; }
4752

4853
public DelegateCommand CopyTickVolumeCommand { get; private set; }
4954
public DelegateCommand CopyRealVolumeCommand { get; private set; }
@@ -75,8 +80,6 @@ public class ViewModel : INotifyPropertyChanged
7580
public DelegateCommand AlertCommand { get; private set; }
7681
public DelegateCommand TesterStopCommand { get; private set; }
7782

78-
public DelegateCommand iCustomCommand { get; private set; }
79-
8083
public DelegateCommand TimeCurrentCommand { get; private set; }
8184

8285
public DelegateCommand ChartOpenCommand { get; private set; }
@@ -354,6 +357,11 @@ private void InitCommands()
354357
CopyCloseCommand = new DelegateCommand(ExecuteCopyClose);
355358
IndicatorCreateCommand = new DelegateCommand(ExecuteIndicatorCreate);
356359
IndicatorReleaseCommand = new DelegateCommand(ExecuteIndicatorRelease);
360+
iCustomCommand = new DelegateCommand(ExecuteICustom);
361+
iBullsPowerCommand = new DelegateCommand(ExecuteIBullsPowerCommand);
362+
iBearsPowerCommand = new DelegateCommand(ExecuteIBearsPowerCommand);
363+
BarsCalculatedCommand = new DelegateCommand(ExecuteBarsCalculatedCommand);
364+
CopyBufferCommand = new DelegateCommand(ExecuteCopyBufferCommand);
357365

358366
CopyTickVolumeCommand = new DelegateCommand(ExecuteCopyTickVolume);
359367
CopyRealVolumeCommand = new DelegateCommand(ExecuteCopyRealVolume);
@@ -385,8 +393,6 @@ private void InitCommands()
385393
ResetLastErrorCommand = new DelegateCommand(ExecuteResetLastError);
386394
TesterStopCommand = new DelegateCommand(ExecuteTesterStop);
387395

388-
iCustomCommand = new DelegateCommand(ExecuteICustom);
389-
390396
ChartOpenCommand = new DelegateCommand(ExecuteChartOpen);
391397
ChartTimePriceToXYCommand = new DelegateCommand(ExecuteChartTimePriceToXY);
392398
ChartXYToTimePriceCommand = new DelegateCommand(ExecuteChartXYToTimePrice);
@@ -806,6 +812,68 @@ private async void ExecuteIndicatorRelease(object o)
806812
AddLog($"IndicatorRelease [{indicatorHandle}]: result - {retVal}");
807813
}
808814

815+
private async void ExecuteICustom(object o)
816+
{
817+
const string name = @"Examples\Custom Moving Average";
818+
int[] parameters = { 0, 21, (int)ENUM_APPLIED_PRICE.PRICE_CLOSE };
819+
820+
var retVal = await Execute(() => _mtApiClient.iCustom(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, name, parameters));
821+
TimeSeriesValues.IndicatorHandle = retVal;
822+
AddLog($"Custom Moving Average: result - {retVal}");
823+
}
824+
825+
private async void ExecuteIBullsPowerCommand(object o)
826+
{
827+
const int maPeriod = 13;
828+
var retVal = await Execute(() => _mtApiClient.iBullsPower(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, maPeriod));
829+
TimeSeriesValues.IndicatorHandle = retVal;
830+
831+
AddLog($"iBullPower: result - {retVal}");
832+
}
833+
834+
private async void ExecuteIBearsPowerCommand(object o)
835+
{
836+
const int maPeriod = 13;
837+
var retVal = await Execute(() => _mtApiClient.iBearsPower(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, maPeriod));
838+
TimeSeriesValues.IndicatorHandle = retVal;
839+
840+
AddLog($"iBearsPower: result - {retVal}");
841+
}
842+
843+
private async void ExecuteBarsCalculatedCommand(object o)
844+
{
845+
var retVal = await Execute(() => _mtApiClient.BarsCalculated(TimeSeriesValues.IndicatorHandle));
846+
847+
AddLog($"BarsCalculated: result - {retVal}");
848+
}
849+
850+
private async void ExecuteCopyBufferCommand(object o)
851+
{
852+
TimeSeriesResults.Clear();
853+
854+
var result = await Execute(() =>
855+
{
856+
var count = _mtApiClient.CopyBuffer(TimeSeriesValues.IndicatorHandle, 0, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out var values);
857+
return count > 0 ? values : null;
858+
});
859+
860+
if (result == null)
861+
{
862+
AddLog("CopyRates: result is null");
863+
return;
864+
}
865+
866+
RunOnUiThread(() =>
867+
{
868+
foreach (var value in result)
869+
{
870+
TimeSeriesResults.Add($"{value:F6}");
871+
}
872+
});
873+
874+
AddLog("CopyRates: success");
875+
}
876+
809877
private async void ExecuteCopyRates(object o)
810878
{
811879
if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;
@@ -1177,17 +1245,6 @@ private void ExecuteTesterStop(object obj)
11771245
AddLog("TesterStop: executed.");
11781246
}
11791247

1180-
private async void ExecuteICustom(object o)
1181-
{
1182-
const string symbol = "EURUSD";
1183-
const ENUM_TIMEFRAMES timeframe = ENUM_TIMEFRAMES.PERIOD_H1;
1184-
const string name = @"Examples\Custom Moving Average";
1185-
int[] parameters = { 0, 21, (int)ENUM_APPLIED_PRICE.PRICE_CLOSE };
1186-
1187-
var retVal = await Execute(() => _mtApiClient.iCustom(symbol, timeframe, name, parameters));
1188-
AddLog($"Custom Moving Average: result - {retVal}");
1189-
}
1190-
11911248
private async void ExecuteTimeCurrent(object o)
11921249
{
11931250
var retVal = await Execute(() => _mtApiClient.TimeCurrent());

0 commit comments

Comments
 (0)