//--- main cycle int i=prev_calculated-1; if(i<Per) i=Per; while(i<rates_total) { for(int j=1;j<=Per;j++) { if(Price==PRICE_CLOSE) x[j]=Close[i-j]; if(Price==PRICE_OPEN) x[j]=Open[i-j]; if(Price==PRICE_HIGH) x[j]=High[i-j]; if(Price==PRICE_LOW) x[j]=Low[i-j]; if(Price==PRICE_MEDIAN) x[j]=(Low[i-j]+High[i-j])/2.; if(Price==PRICE_TYPICAL) x[j]=(Low[i-j]+High[i-j]+Close[i-j])/3.; if(Price==PRICE_WEIGHTED) x[j]=(Low[i-j]+High[i-j]+Close[i-j]+Open[i-j])/4.; } lrs[i]=LinRegrSlope(Per); i++; }
The indicator may work as expected for the first call, when prev_calculated is zero.
But after that i will be either Bars-1 or Bars-2, so as new bars are opened, no value is calculated for them
The indicator may work as expected for the first call, when prev_calculated is zero.
But after that i will be either Bars-1 or Bars-2, so as new bars are opened, no value is calculated for them
Keith, Thanks for your comment. The strange thing is that the indicator draws apparently normally, both attached to a chart and in the strategy tester!!! Try it. It has to be something else...
There indicator is wrongly coded, it uses future price and doesn't have a value for the last "LRSPeriod" bars. Completely useless.
Alain, Thanks for your comment. But the indicator actually draws apparently normally. How can you explain that?
What is normal for you ?
- It always returns EMPTY_VALUE for index=1 as with default settings (Per=40), it doesn't draw a value for the last 40 candles.
- More. It doesn't draw anything for the 40 last candles, as it uses future values:
for(int j=1;j<=Per;j++) { ... // default setting is PRICE_MEDIAN if(Price==PRICE_MEDIAN) x[j]=(Low[i-j]+High[i-j])/2.; ... } lrs[i]=LinRegrSlope(Per);
For candle i, it uses Low/High of candle i-1 to i-40, these are future values.
- This indicator is coded in reverse. It updates the oldest value on each tick as reported by Gumrai.
- As it's poorly coded (buffer not initialized) you can have illusion that it draws "normally".
I concur, there is no way that this indicator draws normally.
I am wondering if it is someone's attempt to convert an mq5 code to mq4?
This is confusing, why the use of capital letters?
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[]) {
I concur, there is no way that this indicator draws normally.
I am wondering if it is someone's attempt to convert an mq5 code to mq4?
This is confusing, why the use of capital letters?
Good catch. I came to the same conclusion but without finding a clue.
EDIT: It's not even an attempt to convert, only thing changed is extension .mq5 to .mq4. Original is here https://www.mql5.com/en/code/127
![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
Hi all,
My name is Harry.
I am trying to use attached linear regression slope indicator in my EA, but I'm having trouble retrieving the values of the indicator in my EA.
It is returning always EMPTY_VALUE.
I have to use this indicator with MT4, so I have compiled the indicator in MT4 and seems to draw fine. (attached in a chart, as well as in the strategy tester)
The problem that I have is when I try to retrieve values to process in my EA, I get always EMPTY_VALUE.
That's how I 'm trying to retrieve:
double LRS1 = iCustom(NULL, RunningTF, "lrs", LRSPeriod, 0, 1); // linear regression slope
I need the previous bar value in my EA.
I do not have the same issue with other indicators I call similarly.
If anyone could help mde with this, I will be really obliged.
Greetings from Greece,
Harry