Bizzare error from uber-simple ChartXYToTimePrice function

 

Recently I asked a coder why I was having trouble implementing some sweet code he'd written up. His response was priceless.

"If you are sitting at the old terminal, this is your and only your problem. It's a shame to still sit at the old terminal. While you are sitting at the old terminal - do not write to me."


This bug just might be the straw that breaks my back as I've tried to bear under MT4/MQL4 and all its glitches and dumb omissions. (Just as a minor example, give us a CHART_FIRST_VISIBLE_BAR but no CHART_LAST_VISIBLE_BAR? smh)

Enough whining, to the bug. Anyone know of a fix?

Here's the code:

#property strict
//---
void OnStart()
{
   datetime dtDTM;
   double   dPRC;
   int      X = 900;
   int      Y = 300;
   int      iSWndw = 0;
   ResetLastError();
   bool bWhy = ChartXYToTimePrice(0,X,Y,iSWndw,dtDTM,dPRC);
   int iErr = _LastError;
   return;
}

Simple enough, right?

Here's what happens if I start debugging with a break on the ResetLastError(); line and step down to the return; line.


Works great, right?

And here's what happens if I remove that first break, leaving only the one on the return; line. 

In other words, here's what happens if I just let the sucker run.

A 4051 error is #define ERR_INVALID_FUNCTION_PARAMVALUE            4051 from stderror.mqh.

So how can my param values be valid one time and not another time, using the exact same compiled code, the only difference being the time intervening the execution of each line of code?

By the way, this was run on a clean chart, no indicators, objects, whatever, no modifications:



I've lost the better part of a week dogging this bug under the assumption that a native MQL4 function could not be the culprit, so it must be somewhere in my code.

Holy shmoly Batman, what will they have forgotten next?


 

    MT4 is not the problem. You don't understand what you are looking at.

   In the first case you are Debugging with a program break at Line 12; so it only executes up to Line 11 (Everything else is ignored). However, Lines 1 thru 11 are only inputs

  and it returns the default values or "last memory values" in the case of Lines 7 and 8. In the 2nd case you remove the break and it then goes further and tries to execute your function

  at Line 13. But since variables dPRC and dtDTM are not initialized (not assigned an initial value) , it returns an Error 4051.

 
The chart has not loaded jet. Put a sleep where you had the breakpoint, let it be 250ms and see if it works then.
 
CHARLESS11:

    MT4 is not the problem. You don't understand what you are looking at.

   In the first case you are Debugging with a program break at Line 12; so it only executes up to Line 11 (Everything else is ignored). However, Lines 1 thru 11 are only inputs

  and it returns the default values or "last memory values" in the case of Lines 7 and 8. In the 2nd case you remove the break and it then goes further and tries to execute your function

  at Line 13. But since variables dPRC and dtDTM are not initialized (not assigned an initial value) , it returns an Error 4051.

Sorry, that's not the case, it's the other way around. As you can see the pointer marking the next line to execute is on line 15. Code break was on 12, sure, but I stepped through the code so I can watch each variable change.

This is a bona fide problem.



 
Dominik Egert:
The chart has not loaded jet. Put a sleep where you had the breakpoint, let it be 250ms and see if it works then.

Thanks man I'll give that a try.

 

Not reproducible. Build 1340.


 
Alain Verleyen:

Not reproducible. Build 1340.


Me too.`


It's a nit to me now that I'm on MQL5. Thanks for checking tho.