Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you? Code that you have not provided!
Please refer to Access to Timeseries and Indicator Data and OnCalculate
Try to understand how OnCalculate works.
rates_total
[in] Size of the price[] array or input series available to the indicator for calculation. In the second function type, the parameter value corresponds to the number of bars on the chart it is launched at.
prev_calculated
[in] Contains the value returned by the OnCalculate() function during the previous call. It is designed to skip the bars that have not changed since the previous launch of this function.
begin
[in] Index value in the price[] array meaningful data starts from. It allows you to skip missing or initial data, for which there are no correct values.
...
Note
If the OnCalculate() function is equal to zero, no indicator values are shown in the DataWindow of the client terminal.
If the price data have been changed since the last call of the OnCalculate() function (a deeper history has been loaded or gaps in the history have been filled), the value of the prev_calculated input parameter is set to zero by the terminal itself.
Good luck.
- www.mql5.com
- 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 developed an indicator to indicate time intervals where trading is favorable for my expert. It does so by producing 1.0 for all the bars where it thinks opening a trade is "allowed", and producing 0.0 for all the other bars. So when my expert logic thinks it is time to open a trade, it checks the value of this indicator and if it is 1.0, then it's ok, but when it is 0.0, it does not open the trade instead.
My indicator behaves somewhat strangely.
So I put my indicator on an M5 chart and I get this screen (I deliberately shrinked it to be as small as possible for the ease of posting): see before.JPG
Indicator is in the bottom of the screen, showing 1.0 values almost everywhere, except for the start of the screen, when it switches from 0.0 to 1.0.
So far so good.
NOW!
If I move the chart with a single RIGHT keypress (this moves it some 20 minutes or so), I get the following: see after.JPG
Everything disappeared in an instant. No indicator line.
What happened?
This is MT4 build 1260.