Download MetaTrader 5
To add comments, please log in or register
Do you want to become a well-known developer? Execute the orders of traders in the Freelance service!
fuzzy_ltl 2012.08.12 00:56 

I've written an indicator that displays a signal in a separate window, but it's only displaying for a few hundred bars and then it just stops. Here's my code: 

int OnInit()
  SetIndexBuffer(0, Buffer, INDICATOR_DATA);
  ArraySetAsSeries(Buffer, true);
  return (0);
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[])
  ArraySetAsSeries(open, true);
  ArraySetAsSeries(high, true);
  ArraySetAsSeries(low, true); 
  ArraySetAsSeries(close, true); 
  int max_offset = 581;
  int limit = rates_total - (prev_calculated + max_offset);
  for (int t = 0; t < limit; t++)
    Buffer[t] = guess(open, high, low, close, t);
  return (rates_total - max_offset);

"guess" is my signal function which I want to display in the window.

"max_offset" is how far back the "guess" function needs to look in historical data to display a given point. To display the signal at "t", it needs the OHLC arrays to be at least "t + max_offset" long.

Any insight into why the "guess" signal stops displaying after a certain point?

EDIT: Thought I'd add that "guess" is a very heavy calculation, could this be a timeout issue?

fuzzy_ltl 2012.08.13 02:22  

Just realised the obvious test is to change to this inside the loop:

Buffer[t] = 0.5;

Now it displays correctly, so my problem was a computation timeout.

But now my new question is: how do I give the OnCalculate computation more execution time in my indicator? 

To add comments, please log in or register