Errors, bugs, questions - page 696

 

Help me out here

try multithreading but terminal crashes

Time        : 2012.03.27 14:38 (0:00:22)
Program     : Client Terminal
Version     : 500.607 (09 Mar 2012)
Revision    : 40583
OS          : Windows 7 Professional (Build 7600)
Processors  : 4 x Intel Core i5-2410 M  @ 2.30 GHz
Memory      : 1551 free of 4003 Mb
Virtual     : 1188 free of 2047 Mb
CrashMD5    : 83 B4200991F2E548704A4F35763F5DAD
Exception   : C0000005 at 400067 A4 read to 400067 A4

Modules     : 00400000 00 E38000 terminal.exe (5.0.0.607)
            : 0 F000000 00006000 detoured.dll
            : 72640000 0003 D000 nvd3d9wrap.dll (8.17.12.9573)
            : 72610000 0002 F000 nvdxgiwrap.dll (8.17.12.9573)
            : 72 F60000 00027000 wlidnsp.dll (7.250.4225.0)
            : 10000000 00265000 mql5.dll (5.0.0.607)
            : 51660000 0002 C000 pdm.dll (7.0.9466.0)
            : 51580000 0002 B000 msdbg2.dll (7.0.9466.0)
            : 013 F0000 0000 B000 borlndmm.dll

75 B73665:00012 [75 B73677] AcquireSRWLockExclusive (kernel32.dll)
77 B89F8F:00063 [77 B89FF2] RtlInsertElementGenericTableAvl (ntdll.dll)
77 B89F8F:00036 [77 B89FC5] RtlInsertElementGenericTableAvl (ntdll.dll)

Registers   : EAX=75 B73665  EIP=400067 A4  EFLGS=00010246  ES=002 b
            : EBX=32 E44168  ESP=3313 FF8C  EBP=3313 FF94    FS=0053
            : ECX=00000000  ESI=00000000  CS=0023         GS=002 b
            : EDX=400067 A4  EDI=00000000  DS=002 b         SS=002 b

I've written a C++ dll.

Here's the code

//---------------------------------------------------------------------------

#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#pragma argsused
//---------------------------------------------------------------------------
#include <Classes.hpp>
//---------------------------------------------------------------------------
class TMyThread : public TThread
        {
                private:
                protected:
                        void __fastcall Execute();
                public:
                        __fastcall TMyThread(bool CreateSuspended);
        };
//---------------------------------------------------------------------------

TMyThread *Thr = new TMyThread(true);


__fastcall TMyThread::TMyThread(bool CreateSuspended)
        : TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall TMyThread::Execute()
{

        FreeOnTerminate = true;
        for (int i=0;i<1000;i++)
                {}
}


//---------------------------------------------------------------------------
extern "C" __declspec(dllexport)    int __stdcall GetIntValue()
{
        Thr->Resume();
        return (10);
}

And the script

#import "Project1.dll"
  int GetIntValue();
#import 

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {

   Comment(GetIntValue());
  }
//+------------------------------------------------------------------+


If you change the code of the dll to this

void __fastcall TMyThread::Execute()
{
        //---- Place thread code here ----
        FreeOnTerminate = true;
        for (int i=0;i<1000;i++)
                {

                }
        MessageBox(NULL,"Ïðèâåò!","Äàé ïÿòü",MB_YESNO | //Äà íåò (êíîïêè)
        MB_DEFBUTTON1 | //Âûäåëåíàÿ êíîïêà
        MB_ICONEXCLAMATION | //Òèï èêîíêè
        MB_DEFAULT_DESKTOP_ONLY);

}

I got the number 10 on the screen in the place of the comment (it should be like this) and then I get msgbox and 2 buttons

the terminal won't crash until I press one of the buttons.

as soon as i press it, the message appears explaining why the crash occured and how to fix it...

 
papaklass:

Gentlemen, has anyone run multi-currency in opening price visualisation mode with reference to other TFs?

Here is the daily chart:


The chart has been sorted out and fixed. Thanks for the example.
 
olyakish:

The terminal doesn't crash until I press at least one of the buttons.

As soon as I press it, a message about finding the cause of crash and how to fix it appears...

Please note that the MQL5 script is automatically unloaded after the completion of OnStart, including your DLL.

That is, you have created a thread with a modal window hanging in memory, and the stool has been knocked out from under it. After closing the modal window it goes back to nowhere.

In your case, you need to explicitly wait until all DLL threads are terminated in a normal and guaranteed manner before terminating MQL5 script.

 
Renat:

Note that the MQL5 script is automatically unloaded after the completion of OnStart, including your DLL.

That is, there is a thread with a modal window hanging in memory, and the stool has been knocked out from under it. After the modal window is closed, it goes back to nowhere.

In your case, before terminating the MQL5 script, you need to explicitly wait for all the DLL threads to terminate normally and be guaranteed.

Thank you, I understand it now.
 
If there is not a single loss in a series of trades, the PROFIT FACTOR and SHARPE RATIO take some unrealistic/extreme values. Is it an error or should such moments be considered and somehow processed? How to do it correctly?
 
tol64:
If there is not a single loss in a series of trades, the PROFIT FACTOR and SHARPE RATIO take some unrealistic/extreme values. Is it an error or should such moments be considered and somehow processed? How to do it properly?

EMPTY_VALUE (same as DBL_MAX)

Of course, you can apply some undefined nan, but then you can't make comparisons.

Документация по MQL5: Стандартные константы, перечисления и структуры / Именованные константы / Прочие константы
Документация по MQL5: Стандартные константы, перечисления и структуры / Именованные константы / Прочие константы
  • www.mql5.com
Стандартные константы, перечисления и структуры / Именованные константы / Прочие константы - Документация по MQL5
 
stringo:

EMPTY_VALUE (same as DBL_MAX)

You can of course use some undefined nan, but then you can't do comparisons.

Actually such moments don't occur that often, so I'll just zero them so that the charts don't go crazy. ))
 
tol64:
If there is no loss in a series of trades, the values of PROFIT FACTOR and SHARPE RATIO take some unrealistic/extreme values. Is it an error or should such moments be considered and somehow processed? How to do it properly?

Apparently there is a mistake, because the Profit Factor should not be calculated with negative values, and as in this case with absence of negative trades.

Simply, if we take formula globally (Gross Profit/Gross Loss) then in absence of negative trades we get division by zero, and when Gross Loss is higher we get number less than 1, which is also not correct for further analysis, because the difference between two positive profit factors will be many times more than difference between two conventionally negative ones.

 
Urain:

Apparently there is an error, as the profit factor should not be calculated with negative values, and as in this case with no negative trades.

It has already been said two posts above that this is not an error, but a sign of impossibility to calculate this indicator.
 
Rosh:
It has already been said two posts above that this is not an error, but a sign of impossibility to calculate this indicator.
The questioner didn't specify a particular prohibitive value, so I assumed it was #IND. And in case of DBL_MAX, it's quite logical if you can't calculate it.
Although you can do one trick, at each calculation add 1 cent to both Gross Porofit and Gross Loss.
Then the forward formula would be ((Gross Porofit+0.01)/(Gross Loss+0.01))
The formula for calculating the reciprocal value (when Gross Loss is larger)
To do -((Gross Loss+0.01)/(Gross Porofit+0.01))
Well it's clear that Gross Loss and Gross Porofit are modules.

Then the line will be symmetrical on both sides which is good for GA and there will be no non-calculable situations at all.

But it will most likely be useful not for you, but for the people who are writing their own optimization criteria.

Reason: