Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The timeframe of the received bar #209

Closed
ackem opened this issue Oct 16, 2020 · 12 comments
Closed

The timeframe of the received bar #209

ackem opened this issue Oct 16, 2020 · 12 comments

Comments

@ackem
Copy link

ackem commented Oct 16, 2020

Hello Bro!

The MtApi5Client.OnLastTimeBar event is a good idea, but how can we identify the timeframe of the received bar?

Can you add any property in the Mt5TimeBarArgs class for this?

Thanks)

@KptKuck
Copy link

KptKuck commented Oct 18, 2020

I think that is not necessary.
You can get the timeframe with ChartPeriod()
See

public ENUM_TIMEFRAMES ChartPeriod(long chartId)

LastTimeBarEvent TimeFrame = CurrentPeriod
Does that fit.
If it does, it only makes sense in ExpertInit
as a response.

_DLLAPI int _stdcall initExpert(int expertHandle, int port, wchar_t* symbol, double bid, double ask, int isTestMode, wchar_t* err)
{
return Execute(&expertHandle, &port, symbol, TIMEFRAME, &bid, &ask, &isTestMode {
bool isTesting = (isTestMode != 0) ? true : false;
auto expert = gcnew Mt5Expert(expertHandle, gcnew String(symbol), TIMEFRAME, bid, ask, gcnew MT5Handler(), isTesting);
MtAdapter::GetInstance()->AddExpert(port, expert);
return 1;
}, err, 0);
}

@vdemydiuk
Copy link
Owner

I agree with Christian that there is no reason to load events with additional information that can be easy received by calling function ChartPeriod() once.

I will close the issue as non-relevant.

@ackem
Copy link
Author

ackem commented Oct 25, 2020

прелесно

а как по полученному бару узнать из какого графика(chartId) он пришёл?

@vdemydiuk
Copy link
Owner

@ackem
В ивенте OnLastTimeBar приходит объект класса Mt5TimeBarArgs, в котором есть поле ExpertHandle, которое уникально для каждого Chart (это window handle). Поэтому имея два поля Symbol и ExpertHandle можно легко различать ивенты.
К сожалению, получить ChartId из ExpertHandle не возможно, и тут скорее всего вы правы, нужно добавить метод, который даст эту возможность.

Постараюсь добавить в следующий релиз метод ChartId, который будет выдавать нужное значение по ExpertHandle.

PS: просьба в следующий раз оставляйте коментарии на английском языке.

@vdemydiuk vdemydiuk reopened this Oct 25, 2020
@KptKuck
Copy link

KptKuck commented Oct 25, 2020

The function ChartPeriod() returns with ID = 0 the TF of the current chart.
https://www.mql5.com/en/docs/chart_operations/chartperiod

grafik

So it is possible to get the TimeFrame without the real Chart ID

@KptKuck
Copy link

KptKuck commented Oct 25, 2020

There might be a small error in the MtApi5 test client.

The result is CURRENT but the Client get H1

DR 0 15:22:00.607 MtApi5 (EURUSD,H1) Expert Handle = 330518
LK 0 15:22:00.607 MtApi5 (EURUSD,H1) IsTesting: false
HI 0 15:22:09.077 MtApi5 (EURUSD,H1) executeCommand: commnad type = 67
LS 0 15:22:24.442 MtApi5 (EURUSD,H1) executeCommand: commnad type = 246
CN 0 15:22:24.445 MtApi5 (EURUSD,H1) Execute_ChartPeriod: chart_id = 0
EG 0 15:22:37.184 MtApi5 (EURUSD,H1) Execute_ChartPeriod: period = PERIOD_H1

grafik

@ackem
Copy link
Author

ackem commented Oct 25, 2020

@KptKuck
Thanks, but if I trade one instrument with many timeframes, this way isn't suitable.

@KptKuck
Copy link

KptKuck commented Oct 25, 2020

@ackem
Then the "LastTimeBar Event" is of no use to you anymore.

The TimeFrame for the Chart(MtApi5Client) is fixed.
If it is changed the connection will be terminated.

@vdemydiuk
Copy link
Owner

vdemydiuk commented Oct 25, 2020

@KptKuck
ackem has told about case when he opened several charts with same instruments (for example. EURUSD) but with different timeframes (M1, H1, etc). This is real case and he need information what chart sent event LastTimeBar.
The event already has information about sender (ExpertHandle) so we just have to link this info with ChartId.
I will add function
public long ChartId(int expertHandle)

@ackem
By the way, it is possible to get ChartID of ExpertHandle in current version of MtApi.
MtApi5Client has property ExecutorHandle that means what chart (window) will execute commands.
ExecutorHandle has the same type as ExpertHandle from event.
So you can set ExecutorHandle with needed value and call ChartId().

@KptKuck
Copy link

KptKuck commented Oct 25, 2020

@vdemydiuk
Ok, one client and multiple charts.

There might be a small error in the MtApi5 test client.

With real ChartID the responded timeframe is correct
There is no issue
grafik

@vdemydiuk
Copy link
Owner

Another way to get specific chart id or timeframe is using several instances of MtApi5Client (multiple mode) when each client will connect to expert with defined timeframe. Each experts must have different port for connection.
It this case clients will receive events LastTimeBar related to required timeframe.

@ackem
Copy link
Author

ackem commented Oct 25, 2020

@vdemydiuk
Thanks, Bro, for your feedback/help.

You're my new best friend! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
MtApi MT5
Awaiting triage
Development

No branches or pull requests

3 participants