In second execution (when timer_counter=2) of ExtExpert.Processing() function I set variable short_signal to true.
In third run of Processing() function all Prints must show variable short_signal true.
But Print with text "After" shows variable short_signal like false. Last Print with text "Output" shows
correctly short_signal true.
If I compare in "if" right after "-----Input" not to "RSIHighLevel-RSILowTol" but number,
the Print with text "After" shows variable short_signal correctly. Also, if inside "if" is not
command with "short_signal=false;" the variable is shown correctly too.
I suggest adding timer_counter into your trace print statements: this may assist with defining the bug. Alternatively, an easier way to debug is to use F9 (breakpoint) at the beginning of TradingExpert::Processing() and F5 to run the expert, then F10 step through with all variables of interest in the watch window.
timer_counter is in first "Print" with text "Input". This shows what I expect - every three seconds is incremented.
If I trying debug this script, it is work ok. But in real work works bad. Function TradingExpert::Processing() is so
easy that there cannot be any error (condition "rsi_current<RSIHighLevel-RSILowTol" cannot be true). Despite
all this in metatrader experts window after third run of Processing() I see "After short_signal false".
Can you try this script, if you get the same result?
Maybe problem is in variable declaration or in MQL5 ?
Thank you
timer_counter is in first "Print" with text "Input". This shows what I expect - every three seconds is incremented.
If I trying debug this script, it is work ok. But in real work works bad. Function TradingExpert::Processing() is so
easy that there cannot be any error (condition "rsi_current<RSIHighLevel-RSILowTol" cannot be true). Despite
all this in metatrader experts window after third run of Processing() I see "After short_signal false".
Can you try this script, if you get the same result?
Maybe problem is in variable declaration or in MQL5 ?
Thank you

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I have this easy expert advisor:
//---------------------------------------------------------------
input int RSIHighLevel=70; // High Level
input int RSILowLevel=30; // Low Level
input double RSITopTol=1; // RSI peak tolerance
input double RSILowTol=5; // RSI low tolerance
//---
int timer_counter=0;
//---
class TradingExpert
{
public:
TradingExpert();
~TradingExpert() { Deinit(); }
void Init();
void Deinit();
void Processing();
protected:
double rsi_current;
bool short_signal;
};
TradingExpert ExtExpert;
TradingExpert::TradingExpert()
{
rsi_current=0;
short_signal=false;
}
void TradingExpert::Init()
{
EventSetTimer(3);
}
void TradingExpert::Deinit()
{
}
void TradingExpert::Processing()
{
rsi_current=70;
Print("-----Input","short_signal",short_signal,"TIMER",timer_counter);
if (rsi_current<RSIHighLevel-RSILowTol)
{
short_signal=false;
Print("Change in if","short_signal",short_signal);
}
Print("After","short_signal",short_signal);
if (timer_counter==2)
{
short_signal=true;
Print("Change bottom","short_signal",short_signal);
}
Print("Output","short_signal",short_signal);
}
int OnInit()
{
ExtExpert.Init();
return(0);
}
void OnDeinit(const int reason)
{
ExtExpert.Deinit();
}
void OnTimer()
{
timer_counter=timer_counter+1;
ExtExpert.Processing();
}
//---------------------------------------------------------------
In second execution (when timer_counter=2) of ExtExpert.Processing() function I set variable short_signal to true.
In third run of Processing() function all Prints must show variable short_signal true.
But Print with text "After" shows variable short_signal like false. Last Print with text "Output" shows
correctly short_signal true.
If I compare in "if" right after "-----Input" not to "RSIHighLevel-RSILowTol" but number,
the Print with text "After" shows variable short_signal correctly. Also, if inside "if" is not
command with "short_signal=false;" the variable is shown correctly too.