"Expression could not be evaluated" using debug.tpl

 

Hi there,

I am trying to write an indicator to work on Fibs on a chart. To debug this, I created debug.tpl and when I run the indicator in the Debugger, the correct template loads. The debug.tpl has as Fib and some MAs. When I step through the code that assigns some values to variables, the values for each variable in the watch window say "Expression could not be evaluated". I have no idea why and wondered whether anyone might know what is happening. In my sample code, I assigned the same value in the OnInit and OnCalculate but, the result is the same. Thoughts?


#property strict
#property indicator_chart_window
//---
enum EN_SWITCH_STATUS
  {
   SWITCH_STATUS_ON = 0,   // ON
   SWITCH_STATUS_OFF       // OFF
  };
//---
sinput string           sMain = "[ Main Fib Options ]";              //=================================
input int               Instance = 1;                                // Instance Id
input EN_SWITCH_STATUS  Status = SWITCH_STATUS_ON;                   // Status
//---
string   FibNames[];
int      ObjectsCount;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   ObjectsCount = ObjectsTotal();
//---
   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 count = ObjectsTotal();

//--- return value of prev_calculated for next call
   return(rates_total);
//---

  }
//+------------------------------------------------------------------+

Correct template loads in the background.

image1

See values in the watch window.

# Image2

 

The message for count is correct. You stopped before the line, and the variable does not yet exist. Step over the line, and then you should get a value.

 
William Roeder #:

The message for count is correct. You stopped before the line, and the variable does not yet exist. Step over the line, and then you should get a value.

Thanks for replying.

The green arrow is at line #44 - I had already stepped through line #41. I stopped at line #44 so that you can see the "Expression could not be evaluated" message for "count" after it had been stepped through. Also, the global variable "ObjectsCount" is declared at the top of the indicator and set in the OnInit. That too shows the value "Expression could not be evaluated".

 
Just a heads up, I resolved this issue. Basically, I created a brand new empty template, saved as debug.tpl, added a few Fibs and voila, it started to work as expected. I've no idea why that worked but it did so all's good :)
Reason: