Closed ackem closed 4 years ago
I think that is not necessary. You can get the timeframe with ChartPeriod() See https://github.com/vdemydiuk/mtapi/blob/9a5acac2dbe7a33f37fde3d8bb1b12cb7126bb6a/MtApi5/MtApi5Client.cs#L1894 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); }
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.
прелесно
а как по полученному бару узнать из какого графика(chartId) он пришёл?
@ackem В ивенте OnLastTimeBar приходит объект класса Mt5TimeBarArgs, в котором есть поле ExpertHandle, которое уникально для каждого Chart (это window handle). Поэтому имея два поля Symbol и ExpertHandle можно легко различать ивенты. К сожалению, получить ChartId из ExpertHandle не возможно, и тут скорее всего вы правы, нужно добавить метод, который даст эту возможность.
Постараюсь добавить в следующий релиз метод ChartId, который будет выдавать нужное значение по ExpertHandle.
PS: просьба в следующий раз оставляйте коментарии на английском языке.
The function ChartPeriod() returns with ID = 0 the TF of the current chart. https://www.mql5.com/en/docs/chart_operations/chartperiod
So it is possible to get the TimeFrame without the real Chart ID
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
@KptKuck Thanks, but if I trade one instrument with many timeframes, this way isn't suitable.
@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.
@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().
@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
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.
@vdemydiuk Thanks, Bro, for your feedback/help.
You're my new best friend! :)
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)