4202 error

 

Why do I get 4202 error from this code? (in strategy tester it works fine!)

double trendline(int i)
{

   double trendline=ObjectGetValueByTime(ChartID(),"Trendline",iTime(NULL, PERIOD_D1, i),0);


   if(GetLastError()>0)
	{
		Print("Error :", GetLastError());
	}

   return trendline;
}

This does not make any sense.

 
Demosfen:

Why do I get 4202 error from this code? (in strategy tester it works fine!)

This does not make any sense.

Why are you calling GetLastError() ?

 
Check your return codes for errors, and report them including GLE/LE and your variable values. Don't look at GLE/LEunless you have an error. Don't just silence the compiler, it is trying to help you.
          What are Function return values ? How do I use them ? - MQL4 programming forum
          Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.
Reason: