Interesting situation happened to me and I want to share

 

So I have created a cap hedge EA (mq4). I ran it on backtest and it worked perfect the first time than I made some extra changes for limit loss, max lot etc...

Then I got some well performing parameters(using optimisation) and decided to put it live on small account with microlots. I was backtesting it on forex but I decided I rather set it to work with Nasdaq. So It started with two positions buy and sell stop it opened correctly eveything. After the first order got activated it didn't closed the other stop order to replace it and went on. So I checked once again and same version and again backtest fine. Code was error and warning free.

So I found that I declared a variable as global without setting it a value. I had somewhere in the code to check and backtest as default got it as false but the live performance wasn't taking it in consideration at all. 

I wouldn't call it a bug or something rather my error but seemed interesting so I decided to share with you

bool AllowOpen,hedge,maxlot;
int slippage = 3;
double MyPoint;

datetime InitTime;

void OnInit()
{
/*

*/
}
void OnTick()

{
/*

*/
if(OpenOrder()==2 && hedge==false && !maxlot)
/*

*/
}
 
Nikolay Georgiev:

So I have created a cap hedge EA (mq4). I ran it on backtest and it worked perfect the first time than I made some extra changes for limit loss, max lot etc...

Then I got some well performing parameters(using optimisation) and decided to put it live on small account with microlots. I was backtesting it on forex but I decided I rather set it to work with Nasdaq. So It started with two positions buy and sell stop it opened correctly eveything. After the first order got activated it didn't closed the other stop order to replace it and went on. So I checked once again and same version and again backtest fine. Code was error and warning free.

So I found that I declared a variable as global without setting it a value. I had somewhere in the code to check and backtest as default got it as false but the live performance wasn't taking it in consideration at all. 

I wouldn't call it a bug or something rather my error but seemed interesting so I decided to share with you

a Boolean returns false if not initialized.

 
Paul Anscombe:

a Boolean returns false if not initialized.

In backtest yes in real environment not so sure
 
Paul Anscombe: a Boolean returns false if not initialized.

Uninitialized variables are random in MT5 and MT4 with strict.

Initialization of Variables

Any variable can be initialized during definition. If a variable is not initialized explicitly, the value stored in this variable can be any. Implicit initialization is not used.

          Initialization of Variables - Variables - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: