Здравсвуйте! Почему iBarshift() для старшего периода не работает на выходные?
Пробуйте на втором вызове
Здравсвуйте! Почему iBarshift() для старшего периода не работает на выходные?
Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий
Nikolai Semko, 2024.12.01 19:10
https://www.mql5.com/ru/forum/1111/page3277#comment_44527232Все равно не выводит значения. Вот пример простенького индикатора. запускаем на М1, чтобы получить значения с М2
#property copyright "Copyright 2025, MetaQuotes Software Corp." #property link "https://www.mql5.com" #include <iBars.mqh> //---- indicator settings #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_type1 DRAW_ARROW #property indicator_color1 DodgerBlue //---- input parameters input ENUM_TIMEFRAMES TF = 2; // Time Frame //---- indicator buffers double ExtSARBuffer[]; //---- handles for moving averages int Handle; //--- bars minimum for calculation //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //---- indicator buffers mapping SetIndexBuffer(0,ExtSARBuffer,INDICATOR_DATA); //--- set arrow symbol PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_ARROW); PlotIndexSetInteger(0,PLOT_ARROW,159); //--- set indicator digits IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //---- запрет на отрисовку индикатором пустых значений PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0); Handle=iSAR(NULL,TF,0.02,0.2); //get MA's handles if(Handle==INVALID_HANDLE) { Print("getting ParabolicSAR Handle is failed! Error",GetLastError()); return(INIT_FAILED); } //--- set accuracy IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //--- initialization done return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- индексация элементов в массивах как в таймсериях ArraySetAsSeries(time,true); ArraySetAsSeries(ExtSARBuffer,true); //--- not all data may be calculated int calculated=BarsCalculated(Handle); //--- if(calculated<=0) { Print("Not all data of ExtHandle1 is calculated (",calculated,"bars ). Error",GetLastError()); return(0); } //--- main cycle for(int i=500;i>=0 && !IsStopped();i--) { int index=fBarShift(_Symbol,TF,time[i]); ExtSARBuffer[i]=_CopyBuffer(Handle,index); } //--- return value of prev_calculated for next call return(rates_total); } //+--------- CopyBuffer MA Handle ----------------------------------+ double _CopyBuffer(int handle,int index) { double buf[]; if(CopyBuffer(handle,0,index,1,buf)>0) return(buf[0]); return(EMPTY_VALUE); }
Все равно не выводит значения. Вот пример простенького индикатора. запускаем на М1, чтобы получить значения с М2
на первом входе (сразу после OnInit и подкачке M1) в OnCalculate не получилось достучаться до старшего ТФ (например M2 ещё строится и данных нет),
а второго входа не будет до первого тика :-) Вы в выходные запустились и других обработчиков помимо OnCalc нет.
hint: работу с данными других таймфреймов и символов стоит дублировать (или вообще полностью) в OnTimer
Все равно не выводит значения. Вот пример простенького индикатора. запускаем на М1, чтобы получить значения с М2
ну конечно. Макс прав. Для старших ТФ без таймера не обойтись. У MT5 очень долбанутая система расчета ТФ. Все ТФ расчитываются из M1.
Попробуйте окрыть новый символ на MN1, котороый до этого не открывали, то для расчета пару сот бар будут загружаться сотни Мб M1 баров. Для меня загадка почему они пошли по пути такой мощной перегрузки на сервера. Точнее я понимаю почему, но это они реально тупанули. Можно с легкостью сократить общий трафик на сервера MQ минимум в 5 раз, а по факту в десятки раз без какого-либо ущерба.
Причем я не призываю вернуться к системе загрузки как в MT4.
Спасибо всем огромное! в таймере заработало.
Теперь получается про oncalculate можно забыть и все расчеты вести в таймере?
//+------------------------------------------------------------------+ //| ProjectName | //| Copyright 2020, CompanyName | //| http://www.companyname.net | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, MetaQuotes Software Corp." #property link "https://www.mql5.com" #include <iBars.mqh> //---- indicator settings #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_type1 DRAW_ARROW #property indicator_color1 DodgerBlue //---- input parameters input ENUM_TIMEFRAMES TF = 2; // Time Frame //---- indicator buffers double ExtSARBuffer[]; //---- handles for moving averages int Handle; //--- bars minimum for calculation //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //---- indicator buffers mapping SetIndexBuffer(0,ExtSARBuffer,INDICATOR_DATA); //--- set arrow symbol PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_ARROW); PlotIndexSetInteger(0,PLOT_ARROW,159); //--- set indicator digits IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //---- запрет на отрисовку индикатором пустых значений PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0); Handle=iSAR(NULL,TF,0.02,0.2); //get MA's handles if(Handle==INVALID_HANDLE) { Print("getting ParabolicSAR Handle is failed! Error",GetLastError()); return(INIT_FAILED); } //--- set accuracy IndicatorSetInteger(INDICATOR_DIGITS,_Digits); if (!EventSetTimer(1)) return(INIT_FAILED) ; //--- initialization done return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- return value of prev_calculated for next call return(rates_total); } //+--------- CopyBuffer MA Handle ----------------------------------+ double _CopyBuffer(int handle,int index) { double buf[]; if(CopyBuffer(handle,0,index,1,buf)>0) return(buf[0]); return(EMPTY_VALUE); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTimer() { //--- индексация элементов в массивах как в таймсериях ArraySetAsSeries(ExtSARBuffer,true); //--- not all data may be calculated int calculated=BarsCalculated(Handle); //--- if(calculated<=0) { Print("Not all data of ExtHandle1 is calculated (",calculated,"bars ). Error",GetLastError()); return; } for(int i=500;i>=0 && !IsStopped();i--) { int index=iBarShift(_Symbol,TF,iTime(NULL,0,i)); ExtSARBuffer[i]=_CopyBuffer(Handle,index); } } //+------------------------------------------------------------------+ void OnDeinit(const int reason) { EventKillTimer(); } //+------------------------------------------------------------------+

- Бесплатные приложения для трейдинга
- 8 000+ сигналов для копирования
- Экономические новости для анализа финансовых рынков
Вы принимаете политику сайта и условия использования
Здравсвуйте! Почему iBarshift() для старшего периода не работает на выходные?