Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MtApi5/Mt5CommandType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ internal enum Mt5CommandType
CopySpread = 49,
CopySpread1 = 1049,
CopySpread2 = 1149,
iOpen = 500,
iClose = 501,

//Market Information
SymbolsTotal = 50,
Expand Down
26 changes: 26 additions & 0 deletions MtApi5/MtApi5Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,32 @@ public int CopyRates(string symbolName, ENUM_TIMEFRAMES timeframe, DateTime star
return ratesArray?.Length ?? 0;
}

///<summary>
///Returns the Open price of the bar (indicated by the 'shift' parameter) on the corresponding chart.
///</summary>
///<param name="symbolName">The symbol name of the financial instrument. NULL means the current symbol.</param>
///<param name="timeframe">Period. It can be one of the values of the ENUM_TIMEFRAMES enumeration. 0 means the current chart period.</param>
///<param name="shift">The index of the received value from the timeseries (backward shift by specified number of bars relative to the current bar).</param>
public double iOpen(string symbolName, ENUM_TIMEFRAMES timeframe, int shift)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, shift };

return SendCommand<double>(Mt5CommandType.iOpen, commandParameters);
}

///<summary>
///Returns the Close price of the bar (indicated by the 'shift' parameter) on the corresponding chart.
///</summary>
///<param name="symbolName">The symbol name of the financial instrument. NULL means the current symbol.</param>
///<param name="timeframe">Period. It can be one of the values of the ENUM_TIMEFRAMES enumeration. 0 means the current chart period.</param>
///<param name="shift">The index of the received value from the timeseries (backward shift by specified number of bars relative to the current bar).</param>
public double iClose(string symbolName, ENUM_TIMEFRAMES timeframe, int shift)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, shift };

return SendCommand<double>(Mt5CommandType.iClose, commandParameters);
}

///<summary>
///The function gets to time_array history data of bar opening time for the specified symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar.
///</summary>
Expand Down
4 changes: 4 additions & 0 deletions TestClients/MtApi5TestClient/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@
<WrapPanel Grid.Row="1" Grid.Column="0" Margin="5">
<Button Command="{Binding CopyRatesCommand}" Margin="1"
Content="CopyRates" HorizontalAlignment="Left" />
<Button Command="{Binding iOpenCommand}" Margin="1"
Content="iOpen" HorizontalAlignment="Left" />
<Button Command="{Binding iCloseCommand}" Margin="1"
Content="iClose" HorizontalAlignment="Left" />
<Button Command="{Binding CopyTimesCommand}" Margin="1"
Content="CopyTimes" HorizontalAlignment="Left" />
<Button Command="{Binding CopyOpenCommand}" Margin="1"
Expand Down
20 changes: 20 additions & 0 deletions TestClients/MtApi5TestClient/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class ViewModel : INotifyPropertyChanged
public DelegateCommand TerminalInfoStringCommand { get; private set; }

public DelegateCommand CopyRatesCommand { get; private set; }
public DelegateCommand iOpenCommand { get; private set; }
public DelegateCommand iCloseCommand { get; private set; }
public DelegateCommand CopyTimesCommand { get; private set; }
public DelegateCommand CopyOpenCommand { get; private set; }
public DelegateCommand CopyHighCommand { get; private set; }
Expand Down Expand Up @@ -355,6 +357,8 @@ private void InitCommands()
TerminalInfoStringCommand = new DelegateCommand(ExecuteTerminalInfoString);

CopyRatesCommand = new DelegateCommand(ExecuteCopyRates);
iOpenCommand = new DelegateCommand(ExecuteIOpen);
iCloseCommand = new DelegateCommand(ExecuteIClose);
CopyTimesCommand = new DelegateCommand(ExecuteCopyTime);
CopyOpenCommand = new DelegateCommand(ExecuteCopyOpen);
CopyHighCommand = new DelegateCommand(ExecuteCopyHigh);
Expand Down Expand Up @@ -916,6 +920,22 @@ private async void ExecuteCopyRates(object o)

}

private async void ExecuteIOpen(object o)
{
if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;

var retVal = await Execute(() => _mtApiClient.iOpen(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, 0));
AddLog($"iOpen({TimeSeriesValues.SymbolValue}, {TimeSeriesValues.TimeFrame}, 0): result = {retVal}");
}

private async void ExecuteIClose(object o)
{
if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;

var retVal = await Execute(() => _mtApiClient.iClose(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, 0));
AddLog($"iClose({TimeSeriesValues.SymbolValue}, {TimeSeriesValues.TimeFrame}, 0): result = {retVal}");
}

private async void ExecuteCopyTickVolume(object o)
{
if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;
Expand Down
Binary file modified mq5/MtApi5.ex5
Binary file not shown.
72 changes: 71 additions & 1 deletion mq5/MtApi5.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,13 @@ int executeCommand()
break;
case 1149: //CopySpread2
Execute_CopySpread2();
break;
break;
case 500: //iOpen
Execute_iOpen();
break;
case 501: //iClose
Execute_iClose();
break;
case 50: //SymbolsTotal
Execute_SymbolsTotal();
break;
Expand Down Expand Up @@ -3024,6 +3030,70 @@ void Execute_CopySpread2()
}
}

void Execute_iOpen()
{
string symbol;
int timeframe;
int shift;
StringInit(symbol, 100, 0);

if (!getStringValue(ExpertHandle, 0, symbol, _error))
{
PrintParamError("iOpen", "symbol", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!getIntValue(ExpertHandle, 1, timeframe, _error))
{
PrintParamError("iOpen", "timeframe", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!getIntValue(ExpertHandle,2, shift, _error))
{
PrintParamError("iOpen", "shift", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}

if (!sendDoubleResponse(ExpertHandle, iOpen(symbol, (ENUM_TIMEFRAMES)timeframe, shift), _response_error))
{
PrintResponseError("iOpen", _response_error);
}
}

void Execute_iClose()
{
string symbol;
int timeframe;
int shift;
StringInit(symbol, 100, 0);

if (!getStringValue(ExpertHandle, 0, symbol, _error))
{
PrintParamError("iClose", "symbol", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!getIntValue(ExpertHandle, 1, timeframe, _error))
{
PrintParamError("iClose", "timeframe", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!getIntValue(ExpertHandle,2, shift, _error))
{
PrintParamError("iClose", "shift", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}

if (!sendDoubleResponse(ExpertHandle, iClose(symbol, (ENUM_TIMEFRAMES)timeframe, shift), _response_error))
{
PrintResponseError("iClose", _response_error);
}
}

void Execute_SymbolsTotal()
{
bool selected;
Expand Down