Errors, bugs, questions - page 1390

 

Do not wait in the indicator init to fully create the indicator.

Create the indicator and return control and all environment and history will be prepared later and your recalculation code will be called.

 
Renat Fatkhullin:

Do not wait in the initia for the complete creation of the indicator.

Create the indicator and return control and all environment and history will be prepared later and your recalculation code will be called.

Thanks, i.e. check for 4806 should be done each time data is received already after return from OnInit()?
 
At each data reading point
 

This is where the indicator is called and its values are calculated within OnCalculate. You can wait indefinitely, no recalculation takes place. To run on the period chart D1

int i_ich=INVALID_HANDLE;
double ind_buf[];

int OnInit(){
   i_ich=iIchimoku(Symbol(), PERIOD_H4, 9, 26, 52);
   if(i_ich==INVALID_HANDLE){
      Print("Невозможно создать индиктор Ишимоку!");
      return(INIT_FAILED);
   }
   SetIndexBuffer(0, ind_buf, INDICATOR_DATA);
   ArraySetAsSeries(ind_buf, true);
   return(INIT_SUCCEEDED);
}


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[]){
   double temp[];
   int copied=CopyBuffer(i_ich,0,0,1,temp);
   if(copied<=0){
      datetime now=TimeLocal();
      while(BarsCalculated(i_ich)<=0 && !IsStopped()){  
         Comment("Ждем пересчета индикатора Ишимоку... ",int(TimeLocal()-now));
      }
      if(BarsCalculated(i_ich)>0){
         Print("Расчитано ", BarsCalculated(i_ich), " баров за ",int(TimeLocal()-now)," секунд");
      }
      Comment("");
   } 

   return(rates_total);
}

Please explain why the Ishimoku reading is not calculated.

 
Ilya Malev:

This is where the indicator is called and its values are calculated within OnCalculate. You can wait indefinitely, no recalculation takes place. To run on the period chart D1

Please explain why the Ishimoku reading is not calculated.

How about this:

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   0
int i_ich=INVALID_HANDLE;
double ind_buf[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   i_ich=iIchimoku(Symbol(),PERIOD_H4,9,26,52);
   if(i_ich==INVALID_HANDLE)
     {
      Print("Невозможно создать индиктор Ишимоку!");
      return(INIT_FAILED);
     }
   SetIndexBuffer(0,ind_buf,INDICATOR_DATA);
   ArraySetAsSeries(ind_buf,true);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[])
  {
   static int count;
   Print(count);
   double temp[];
   datetime now=TimeLocal();
   int copied=CopyBuffer(i_ich,0,0,1,temp);
   if(copied>0)
      Print("Расчитано ",BarsCalculated(i_ich)," баров за ",int(TimeLocal()-now)," секунд");
   count++;
   return(rates_total);
  }
//+------------------------------------------------------------------+
?
 

You should never loop the expectation in the indicator code. In scripts and Expert Advisors you can, but in indicators you absolutely cannot.

The strategy for calculations and requests for foreign data in the indicators should be as follows: if the data request was not successful, then we exit immediately, postponing the calculations for the next tick. In the next tick/call, we will try again to request the necessary data.

 
Karputov Vladimir:

And if so:

?
Outputs "0" (as it is Sunday, there is no restart of OnCalculate )
 
Renat Fatkhullin:

You should never loop the expectation in the indicator code. In scripts and Expert Advisors you can, but in indicators you absolutely cannot.

The strategy for calculations and requests for external data in indicators should be as follows: if the data request was unsuccessful, then we exit immediately, postponing the calculations for the next tick. In the next tick/call, we will try again to request the necessary data.

Ok, but what if the indicator readings should be calculated during one run, without waiting for the next tick? For example, if there is a weekend or just a low-liquidity period, when the tick is out of a minute? Use OnTimer instead of OnCalculate?
 
Ilya Malev:
Outputs "0" (since it's Sunday, no OnCalculate re-run )
In the tester, in the tester! And at the weekend you need to right-click on the graph and "Refresh".
 

After pressing "refresh" everything is calculated. It would be more convenient if indicator data, created in the inite, was calculated before the first call of OnCalculate/OnTimer etc.

It would be useful to have a possibility to wait for their calculation after the initialization in the loop inside the indicator.

To calculate the indicator, the user should press "refresh" on the chart several times. Does he need it. He will remember good old MT4 and will stay on it, despite some advantages of MT5.

Reason: