I already (five months ago) uploaded five indicators and put them up for sale without any problems. This is the first time I have encountered this problem.
Does anyone know what the problem is?
With a 100% probability you are writing for an old terminal and at the same time you do not use modern OnInit, OnCalculate constructs.
With a 100% probability you are writing for an old terminal and at the same time you do not use modern OnInit, OnCalculate constructs.
Thank you for your answer. I put the code below. The code is very simple. please explain more.it is mql4.
#property copyright "Copyright 2021, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "2.00" #property strict #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 1 #property indicator_buffers 1 double Bufer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Bufer); SetIndexStyle( 0,DRAW_LINE ,EMPTY ,EMPTY, clrBlue ); //--- 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[]) { //--- int Counted = rates_total-prev_calculated-1; if (Counted<=1) Counted =1; for (int i=Counted ; i>=0 ;i--) { if ((High[i]-Low[i])!=0) Bufer[i]=MathAbs(Open[i]-Close[i])/(High[i]-Low[i]); else Bufer[i]=0; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
The OnCalculate event handler supplies the OHLC data as the arrays open[], high[], low[], close[], yet you are using the internal MQL4 arrays Open[], High[], Low[], Close[] .
Don't do that. Use the arrays provided by the OnCalculate parameters. In MQL the names are case sensitive.
Also your "Counted" loop can cause an "array out of range" error, when "rates_total" is less that two. You need to fix that as well.
The OnCalculate event handler supplies the OHLC data as the arrays open[], high[], low[], close[], yet you are using the internal MQL4 arrays Open[], High[], Low[], Close[] .
Don't do that. Use the arrays provided by the OnCalculate parameters. In MQL the names are case sensitive.
Also your "Counted" loop can cause an "array out of range" error, when "rates_total" is less that two. You need to fix that as well.
thank you for your attention.
I changed the code as follows. I think the problem is solved.
//+------------------------------------------------------------------+ //| Testing101.mq4 | //| Copyright 2021, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "4.00" #property strict #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 1 #property indicator_buffers 1 double Bufer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Bufer); SetIndexStyle( 0,DRAW_LINE ,EMPTY ,EMPTY, clrBlue ); //--- 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[]) { //--- int Counted = rates_total-prev_calculated-1 ; if (Counted<0) Counted =0; for (int i=Counted ; i>=0 ;i--) { if ((high[i]-low[i])!=0) Bufer[i]=MathAbs(open[i]-close[i])/(high[i]-low[i]); else Bufer[i]=0; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
No quite! It will still produce an "array out of range" error, when "rates_total" is less that one. Here is one possible correction (there are other ways) ...
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[]) { if( rates_total > 0 ) { int Counted = rates_total-prev_calculated-1 ; if (Counted<0) Counted =0; for (int i=Counted ; i>=0 ;i--) { if ((high[i]-low[i])!=0) Bufer[i]=MathAbs(open[i]-close[i])/(high[i]-low[i]); else Bufer[i]=0; } } //--- return value of prev_calculated for next call return(rates_total); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I already (five months ago) uploaded five indicators and put them up for sale without any problems. This is the first time I have encountered this problem.
Does anyone know what the problem is?