Strange phenomenon with self-developed indicator

 

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.

Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
  • www.mql5.com
Some technical indicators have several buffers drawn in the chart. Numbering of indicator buffers starts with 0. When copying indicator values using the CopyBuffer() function into an array of the double type, for some indicators one may indicate the identifier of a copied buffer instead of its number.
Files:
before.JPG  40 kb
after.JPG  39 kb
 
Sabc237: My indicator behaves somewhat strangely.

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.

Documentation on MQL5: Timeseries and Indicators Access
Documentation on MQL5: Timeseries and Indicators Access
  • www.mql5.com
These are functions for working with timeseries and indicators. A timeseries differs from the usual data array by its reverse ordering - elements of timeseries are indexed from the end of an array to its begin (from the most recent data to the oldest ones). To copy the time-series values and indicator data, it's recommended to use dynamic...
Reason: