Ok, lets get started with this one....
MQL5 reason code corrupted
Problem description
OnDeInit reason code is sometimes corrupted when changing timeframes. (Occasionally the reason code is set as 1 rather than 3)
...
Sequence of action
Create new chart (a chart with some missing history is necessary for recreating this issue rather than an up to date terminal)
Attach supplied script (below)
Change timeframes 5-10 times
...
Obtained result
Log normally shows reason code 3 - REASON_CHARTCHANGE.
Log occasionally shows reason code 1 -REASON_REMOVE
RE 0 00:16:12.008 blah2 (USDZAR,H1) OnDeinit_Deinitalization reason code =3
IQ 0 00:16:12.008 blah2 (USDZAR,H1) OnDeinit_UninitReason =Symbol or timeframe was changed
HQ 0 00:16:14.435 blah2 (USDZAR,W1) ReasonCodes: 111
KP 0 00:16:14.435 blah2 (USDZAR,W1) OnDeinit_Deinitalization reason code =1
KR 0 00:16:14.435 blah2 (USDZAR,W1) OnDeinit_UninitReason =Program blah2.mq5 was removed from chart
LF 0 00:16:40.031 blah2 (USDZAR,M15) ReasonCodes: 333
EQ 0 00:16:40.031 blah2 (USDZAR,M15) OnDeinit_Deinitalization reason code =3
HH 0 00:16:40.031 blah2 (USDZAR,M15) OnDeinit_UninitReason =Symbol or timeframe was changed
...
Expected result
reason code should ALWAYS be 3 REASON_CHARTCHANGE when changing timeframes
(the indicator was never removed from chart during this test so Reason code 111 should not be possible)
//| testdeinint.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_plots 0
int OnInit()
{
return INIT_SUCCEEDED;
}
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[])
{
return rates_total;
}
void OnDeinit(const int reason)
{
Print("ReasonCodes: ", UninitializeReason(), reason, _UninitReason);
//--- The first way to get the deinitalization reason code
Print(__FUNCTION__, "_Deinitalization reason code =", reason);
//--- The second way to get the deinitalization reason code
Print(__FUNCTION__, "_UninitReason =", ReasonText(_UninitReason));
}
string ReasonText(int reasonCode)
{
string text="";
switch(reasonCode)
{
case REASON_ACCOUNT: text="Account was changed";break;
case REASON_CHARTCHANGE: text="Symbol or timeframe was changed";break;
case REASON_CHARTCLOSE: text="Chart was closed";break;
case REASON_PARAMETERS: text="Input-parameter was changed";break;
case REASON_RECOMPILE: text="Program "+__FILE__+" was recompiled";break;
case REASON_REMOVE: text="Program "+__FILE__+" was removed from chart";break;
case REASON_TEMPLATE: text="New template was applied to chart";break;
default: text="Another reason";break;
}
return text;
}
As suggested by James Cater, I am opening this thread to centralize bugs reported on MT5 and mql5.
You can report what you found, ask for confirmation of the community, and report it to ServiceDesk. The goal of this topic is to effectively have bugs fixed, if you want to ask for improvements, please use this topic instead.