Ошибки, баги, вопросы - страница 3465

 

Все сделки сделаны советником, а в отчете Manual?


Из отчета терминала.

 
Glory #:

It has always been this way. After returning a non-zero value from OnInit (in particular, INIT_FAILED), the indicator remains on the chart, but does not receive Calculate events (that is, OnCalculate does not work). This was done specifically so that the indicators would not disappear from the charts, for example, in the event of a lack of connection with the trading server

Пожалуйста, посмотрите этот пост:

https://www.mql5.com/en/forum/461408#comment_51952236

Obviously bug in indicators OnInit() return value effect
Obviously bug in indicators OnInit() return value effect
  • 2024.01.28
  • www.mql5.com
It seems return value of indicators is not being respected by terminal. It works for Experts, but not for indicators...
[Удален]  
Slava # : Так было всегда. После возврата ненулевого значения из OnInit (в частности INIT_FAILED) индикатор остаётся на графике, но не получает событий Calculate (то есть OnCalculate не отрабатывает). Делали специально, чтобы индикаторы не пропадали с графиков, например, в случае отсутствия связи с торговым сервером

Это абсолютно смешно (не вы, я имею в виду MetaQuotes).

Если на МТ4 оно работает корректно, то это не фича — это явный баг. Это даже не объяснено в документации, а объясняется так, как это практикуется в реализации МТ4.

Когда советник выходит из строя, он также удаляется с графика. Почему бы индикатору не следовать той же процедуре?

That is absolutely ridiculous (not you, I mean MetaQuotes).

If it works correctly on MT4, then it is not a feature — it is a blatant bug. It is not even explained in the documentation, and it is explained in the way it is practice in the MT4 implementation.

When an EA fails, it is also removed from the chart. Why would an indicator not follow the same procedure.

 
Fernando Carreiro #:

Это абсолютно смешно

Допустим, пользователь настроил свой график с индикатором, где индикатор работает только на определенном счете.
#property indicator_chart_window
#property indicator_plots 0

int OnInit()
{
  return(AccountInfoInteger(ACCOUNT_LOGIN) != 12345);    
}

int  OnCalculate( const int, const int, const int, const double &[] )
{
  return(0);
}

Если индикатор будет выгружаться при INIT_FAILED, то график будет терять индикатор при переключении с рабочего счета на другой и обратно.

 
fxsaber # :
Let's say the user has configured his chart with an indicator, where the indicator only works on a certain account.

If the indicator is unloaded at INIT_FAILED, then the chart will lose the indicator when switching from a working account to another and back.

Agree. - But the return value must be reflected in the journal, just like the experts.

Изменить: см. этот пример кода...

//+------------------------------------------------------------------+
//|                                                  Playground2.mq5 |
//|             Copyright 2024, Freie Netze UG (haftungsbeschraenkt) |
//|                                       https://www.freie-netze.de |
//+------------------------------------------------------------------+


int     indicator_handle    = INVALID_HANDLE;
int     indicator_subwnd_id = -1;
string  indicator_shortname = NULL;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
    printf("GetTickCount: %llu", GetTickCount());


    indicator_shortname = ::MQLInfoString(MQL_PROGRAM_NAME);
    const int wnd_count  = (int)ChartGetInteger(ChartID(), CHART_WINDOWS_TOTAL);        
    for(int wndptr = NULL; (wndptr < wnd_count) && (indicator_handle == INVALID_HANDLE); wndptr++)
    {
        for(int ind_cnt = ChartIndicatorsTotal(ChartID(), wndptr) - 1; (ind_cnt >= NULL) && (indicator_handle == INVALID_HANDLE); ind_cnt--)
        { indicator_handle = (ChartIndicatorName(ChartID(), wndptr, ind_cnt) == indicator_shortname) ? ChartIndicatorGet(ChartID(), wndptr, indicator_shortname) : indicator_handle; }
        indicator_subwnd_id = (indicator_handle != INVALID_HANDLE) ? wndptr : indicator_subwnd_id;
    }
    printf("Indicator handle: %i", indicator_handle);
    
    return((indicator_subwnd_id != -1) ? INIT_SUCCEEDED : INIT_FAILED);
}


void OnDeinit(const int reason)
{
    ChartIndicatorDelete(ChartID(), indicator_subwnd_id, indicator_shortname);
    IndicatorRelease(indicator_handle);

    string text = "Another reason";
    switch(reason)
    {
        case REASON_ACCOUNT:        text="Account was changed";                         break;
        case REASON_CHARTCHANGE:    text="Symbol or timeframe was changed";             break;
        case REASON_CHARTCLOSE:     text="Chart was closed";                            break;
        case REASON_PARAMETERS:     text="Input-parameter was changed";                 break;
        case REASON_RECOMPILE:      text="Program "+__FILE__+" was recompiled";         break;
        case REASON_REMOVE:         text="Program "+__FILE__+" was removed from chart"; break;
        case REASON_TEMPLATE:       text="New template was applied to chart";           break;
    }
    printf("OnDeInit reason: %s; GetTickCount: %llu", text, GetTickCount());
}



//+------------------------------------------------------------------+
//| 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[])
{
    printf("OnCalculate call: %s; GetTickCount: %llu", TimeToString(time[rates_total - 1]), GetTickCount());

    return(rates_total);
}
//+------------------------------------------------------------------+

Невозможно удалить. OnDeInit не вызывается

 
Dominik Egert #:

Соглашаться. - Но возвращаемая стоимость должна быть отражена в журнале, как и у экспертов.

#property indicator_chart_window
#property indicator_plots 0

int OnInit()
{
  return(!TerminalInfoInteger(TERMINAL_CONNECTED));
}

int  OnCalculate( const int, const int, const int, const double &[] )
{
  return(0);
}

Перезагружаю терминал и получаю потерю индикатора. Вы так хотите?!

[Удален]  
fxsaber # : Допустим, пользователь настроил свой график с индикатором, где индикатор работает только на определенном счете.

Если индикатор будет выгружаться при INIT_FAILED, то график будет терять индикатор при переключении с рабочего счета на другой и обратно.

И та же логика, которую вы представили, может быть применима и к советнику (EA). Это не убедительный аргумент.

And the same logic that you have presented could apply to an Expert Advisor (EA) as well. It is not a convincing argument.
 
fxsaber #:

I reboot the terminal and get a loss of the indicator. Is that what you want?!

Нет. Я хочу, чтобы он вел себя последовательно. Также попробуйте мой пример кода.

 
Dominik Egert #:

OnDeInit не вызывается

#property indicator_chart_window
#property indicator_plots 0

int OnInit() { return(INIT_FAILED); }

void OnDeinit( const int ) { Print(__FUNCSIG__); }

int  OnCalculate( const int, const int, const int, const double &[] ) { return(0); }


Результат.

void OnDeinit(const int)
 
Fernando Carreiro #:

И та же логика, которую вы представили, может быть применима и к советнику (EA).

Советник торгует, у него гораздо выше требования к безопасности, чем у индикатора.

Это не убедительный аргумент.

Это же субъективная вещь.