Errors, bugs, questions - page 1868

 

build 1589

How to make OnTimer in an indicator stop working when the account/broker changes, if it does not have such a ticker, or it is not added to market overview, without using IndicatorDelete?

Errata in the documentation - there is no IndicatorDelete function, there is ChartIndicatorDelete!

https://www.mql5.com/ru/docs/standardlibrary/cchart/cchartindicatordelete

bool  IndicatorDelete(
   int            sub_win      // номер подокна
   const string   name         // короткое имя индикатора
   );

The situation is as follows - I run the attached indicator on the futures. I switch to another broker, but the timer keeps ticking, although the chart becomes black and does not update.

it does not write the reason for deinitialization

REASON_ACCOUNT

6

Another account has been activated or reconnection to the trade server due to a change in account settings


2017.04.21 12:10:31.810 TF through OnTimer (DDM7,M1)    Работаем
2017.04.21 12:10:31.810 TF through OnTimer (DDM7,M1)    Аккаунт = AMPGlobalClearing-Demo-CQG
тут сменили брокера,причины деинициализации нет
2017.04.21 12:10:36.809 TF through OnTimer (DDM7,M1)    Работаем
2017.04.21 12:10:36.809 TF through OnTimer (DDM7,M1)    Аккаунт = FXOpen-MT5
//+------------------------------------------------------------------+
//|                                           TF through OnTimer.mq5 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
string server;
//| 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);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   EventKillTimer();
   Print("Причина деинициализации = ",reason);
   
  }
//+------------------------------------------------------------------+
int OnInit()
  {
  server=AccountInfoString(ACCOUNT_SERVER);
   EventSetMillisecondTimer(5000);
   IndicatorSetString(INDICATOR_SHORTNAME,"name");
   
//--- indicator buffers mapping
//---
   return(INIT_SUCCEEDED);
  }  
  
  ////////////
  void OnTimer ()
  {
  Print("Работаем");
  Print("Аккаунт = ",AccountInfoString(ACCOUNT_SERVER));
//  if ( server!=AccountInfoString(ACCOUNT_SERVER) ) ChartIndicatorDelete(0,0,"name");
  }
Документация по MQL5: Стандартная библиотека / Ценовые графики / IndicatorDelete
Документация по MQL5: Стандартная библиотека / Ценовые графики / IndicatorDelete
  • www.mql5.com
Стандартная библиотека / Ценовые графики / IndicatorDelete - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
kaus_bonus:

build 1589

OnDeinit is not called.
 
what do you mean
fxsaber:
OnDeinit is not called.

What do you mean? Not called at all, or in this code?

 
kaus_bonus:

build 1589

How to make OnTimer in an indicator stop working when the account/broker changes, if it does not have such a ticker, or it is not added to market overview, without using IndicatorDelete?

Errata in the documentation - there is no IndicatorDelete function, there is ChartIndicatorDelete!

https://www.mql5.com/ru/docs/standardlibrary/cchart/cchartindicatordelete

The situation is as follows - I run the attached indicator on the futures. I switch to another broker, but the timer keeps ticking, although the chart becomes black and does not update.

it does not write the reason for deinitialization

REASON_ACCOUNT

6

Another account is activated or reconnection to a trade server was caused by a change in the account settings



Loading and unloading of indicators

Indicators are uploaded in the following cases

  • attaching an indicator to a chart
  • start of the terminal (if an indicator was attached to a chart before the terminal was closed previously)
  • loading of a template (if an indicator is attached to a chart)
  • Profile change (if the indicator is attached to one of the profile charts);
  • change of the symbol and/or period of the chart, to which the indicator is attached;
  • after the successful recompilation of an indicator, if this indicator has been attached to a chart.
  • change of indicatorinput parameters.

Indicators are unloaded in the following cases

  • when the indicator is detached from the chart;
  • closing of the terminal (if an indicator has been attached to a chart)
  • loading of a template if an indicator is attached to a chart;
  • close the chart to which the indicator has been attached
  • profile change, if the indicator is attached to one of the charts of the profile to be changed;
  • change of the symbol and/or period of the chart, to which the indicator is attached;
  • change of indicator input parameters.


The reason "change of account" does not exist, it means that the indicator is not unloaded at account switching and consequently OnDeinit() for the indicator, when you change the trading account won't be either.

 
kaus_bonus:

What do you mean? Not called at all, or in this code?

In your situation.
 
Vladimir Karputov:

Loading and unloading indicators


Indicators are unloaded in the following cases

  • when the indicator is detached from the chart;
  • closing of the terminal (if an indicator is attached to a chart)
  • loading of a template, if an indicator is attached to the chart
  • close the chart to which the indicator has been attached
  • profile change, if the indicator is attached to one of the charts of the profile to be changed;
  • change of the symbol and/or period of the chart, to which the indicator is attached;
  • change of indicator input parameters.


The reason "account switch" does not exist, it means that the indicator is not unloaded at account switching and consequently there will be no OnDeinit() for the indicator when you change the trading account.

In fact, the reason I mentioned works only for Expert Advisors.

Коды причины деинициализации эксперта ....

Then the question remains - how to make the timer stop working without radically removing the indicator from the chart?

Документация по MQL5: Стандартные константы, перечисления и структуры / Именованные константы / Причины деинициализации
Документация по MQL5: Стандартные константы, перечисления и структуры / Именованные константы / Причины деинициализации
  • www.mql5.com
Стандартные константы, перечисления и структуры / Именованные константы / Причины деинициализации - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
kaus_bonus:

In fact, the reason I mentioned only works for experts

Then the question remains - how to get the timer to stop working without drastically removing the indicator from the chart?


In OnInit() memorize the score. In the timer check the account number. If the score has changed - exit the timer.
 
kaus_bonus:

Then the question remains - how do you get the timer to stop working without drastically removing the indicator from the chart?

Use ACCOUNT_LOGIN and ACCOUNT_SERVER.
 

don't you think that's a crooked solution?!

suppose we doACCOUNT_LOGIN!=ACCOUNT_LOGIN_NEW, kill the timer, and then go back to this account, what happens? the timer will not start again?

it is easier to add the reason "change of account" to the indicators in the same way, or am i wrong in some way and it will lead to some difficulties?

 
kaus_bonus:

you have to admit, it's a crooked solution?!

It's a horse move!

Suppose we doACCOUNT_LOGIN!=ACCOUNT_LOGIN_NEW, kill the timer, and then go back to that count, what happens?

When an account change is detected, you remember the new characteristics already.

You can design it as a small library on the principle that here(macros). Then the "crooked" stuff won't be a nuisance.

Reason: