Errors, bugs, questions - page 2575

 
Roman:

The memory is allocated in the mql code as

out and passed as a pointer to allocated memory, since string in mql is wichar_t* in dll

Oh how messed up...

I don't know the string implementation, I can only guess, but judging by the error, string out creates a pointer on the stack that is initialized to 0x0000000000 and you safely dereference a null pointer in the dll.

 
Vladimir Simakov:

Oh, it's so complicated...

I don't know the string implementation, I can only guess, but judging by the error, string out creates a pointer on the stack that is initialized to 0x0000000000 and you safely dereference a null pointer in the dll.

Sorry, didn't notice StringInit (((.
 
Roman:

The memory is allocated in the mql code as

out and passed as a pointer to allocated memory, as string in mql is wchar_t* in dll

Dig into the dll itself, something is most likely there. Lately, I've been feeding data from mql to third party C++/C# applications, no problems at all.

 
Vladimir Simakov:

Dig into the dll itself, there's probably something there. Lately, I've been feeding data from mql to third party C++/C# applications, no problems at all.

The dll is very simple, it's not needed for clarity, the idea itself is shown.

wchar_t* out        = L"";
const wchar_t* data = L"";

while(condition)
{
   data = getData();  //getData библиотечная функция возвращает const wchar_t*
   wcscpy(out, data);
}

Output the result data to the console, all lines in the console are clear, no gaps and no glitches.
I pass the result to mql through wcscpy(out, data), but now I get problems.
But if I pass a check string written by hand.

wchar_t* out        = L"";
const wchar_t* data = L"";

while(condition)
{
   data = L"{\"p\":\"2000\"}";  //проверочная строка
   wcscpy(out, data);
}

I don't have problems for some reason.

Hm, does type string in mql consider terminal null wchar_t * ??

 

Suggestion to expand a little the possibility of OnTimer() event

At the moment the OnTimer() event starts to occur when the periodicity of call is set with the EventSetTimer() function.

It turns out the following Expert Advisor:

bool timer_set = false;
int OnInit()
{
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   EventKillTimer();
}
//+------------------------------------------------------------------+
void OnTick()
{
   if (!timer_set)
      {
         // -- имитация включения советника в какое-то
         // -- случайное время
         string time = TimeToString(TimeTradeServer(), TIME_DATE | TIME_MINUTES | TIME_SECONDS);
         if (TimeCurrent() >= D'2019.09.24 3:47:40')
            {
               EventSetTimer(600);
               timer_set = true;
            }
      }
}
//+------------------------------------------------------------------+
void OnTimer()
{
//---
   string time = TimeToString(TimeTradeServer(), TIME_DATE | TIME_MINUTES | TIME_SECONDS);
   printf("Current time: %s", time);
}
//+------------------------------------------------------------------+

Outputs approximately the following:

QJ      0       07:53:10.369    test_timer (GBPUSD_i,D1)        2019.09.24 03:57:41   Current time: 2019.09.24 03:57:41
NF      0       07:53:11.246    test_timer (GBPUSD_i,D1)        2019.09.24 04:07:41   Current time: 2019.09.24 04:07:41

However, it is often enough to check for the occurrence of the signal after the appearance of another bar.

For example, it turns out that for example for PERIOD_M15, the bar appears at 00:15:00, but the check by the Expert Advisor can check it only at 00:29:59.

So, for more or less stable and equal results, regardless of Expert Advisor's start time,

you will need to set a timer for a shorter time interval or additionally use OnTick().

As experiments have shown, it dramatically slows down the speed of testing in the strategy tester.

Suggestion:

To add a function which would allow to set the initial time from which the OnTimer event is counted.

For example, some function EventSetTimerFrom(const datetime SinceDT) that would allow you to set the timer call a few seconds after a new bar.

 
Roman:

The dll is simple, the extra stuff has been removed for clarity, the idea is shown.

I paste the result to the console, all lines are ok, no gaps, no glitches.
I pass the result to mql through wcscpy(out, data), but now I get problems.
But if I pass a check string written by hand.

I don't have problems for some reason.

Hm, does type string in mql consider terminal null wchar_t * ??

But this function works.

wcsncpy(out, data, wcslen(data));

But it's a bit messy, it looks like there's an extra } at the end of a line, an extra parenthesis keeps appearing and disappearing.
wcslen(data)+1
wcslen(data)+2
didn't help,
and gets parsed without errors, without leaks.

no idea what is the length or size of one character in mql-looking string
there is certainly an error in the string type.

And in a long ago article in paragraph 3.3 Passing and modifying strings, the example most likely made an error.

_DLLAPI void fnReplaceString(wchar_t *text, wchar_t *from, wchar_t *to)
  {
   wchar_t *cp;
    
   //проверка параметров
   if(text==NULL || from==NULL || to==NULL) return;
   if(wcslen(from)!=wcslen(to))             return;
   
   //поищем подстроку
   if((cp=wcsstr(text,from))==NULL)         return;
   
   //заменим
   memcpy(cp,to,wcslen(to)*sizeof(wchar_t));  //в этой строке должен быть указатель sizeof(wchar_t *)
  }

Perhaps somewhere in the terminal code, mql string conversion works the same way, without a pointer.

 
Maksim Emeliashin:

set the initial time from which the OnTimer event is counted down.

You can do this yourself through repeated call of EventSetTimer. Note that in the account (not in the Tester) the timer floats and needs constant adjustment.

 
fxsaber:

You can do this yourself via repeated call to EventSetTimer. Keep in mind that on the account (not in the Tester) the timer floats and needs constant adjustment.

Thank you, useful thing!

Very strange, of course, that such a simple point is not taken into account in the terminal "out of the box".

 
Roman:

But this function works.

But it seems to be a bit awkward, an extra parenthesis } appears or disappears at the end of the string.
wcslen(data)+1
wcslen(data)+2
didn't help,
and gets parsed without errors, without leaks.

no idea what is the length or size of one character in mql-looking string
there is certainly an error in the string type.

And in a long ago article in paragraph 3.3 Passing and modifying strings, the example most likely made an error.

Perhaps somewhere in the terminal code, the mql string conversion works the same way, without the pointer.

getData() dig. I have a feeling there's a problem somewhere.
 
Roman:

The dll is simple, it has been removed for clarity and the idea is shown

Your examples are funny, you removed everything, left UB (modification of string literals), and everyone has to telepathize. If you expect to get some smart advice, give minimal working code (on two sides), otherwise it's just rubbish.

Reason: