How can that be ??

 

I have declared the following global variable:

bool        SellMiddle = false;

But as soon as the program starts - long before it reaches any code that could change that status - and even if it reached that code it would still not change because the condition stays false to change the value -

the value of this variable is "TRUE" !!

17:57:24 2012.08.21 00:33  CCITrendReversal EURUSD,H1: SellMiddle is 1

How can that be???

 

Ernest, you shouldn't need to initialize the variable 'SellMiddle' as false. Boolean data type begins initialization as false. Here's an example-

bool SellMiddle; // its initialization is currently false assuming no condition has been met to make it true.
Thank you.
 
WhooDoo22:

Ernest, you shouldn't need to initialize the variable 'SellMiddle' as false. Boolean data type begins initialization as false. Here's an example-

Thank you.
It aids clarity though.
 

Simon,

There's no sense in initializing a Boolean data type to false. It's redundant.

Thank you.

 
ernest02:


How can that be???

The only explanation is that something in your code changes it . . .  search for SellMiddle in your code in MetaEditor using  Ctrl + F   . . .  check ever instance,  maybe it is used in function ?  and find what changes the variable,  add a debugging Print()  before and after the statement so you can see when the state changes . . . .  then kick yourself for not finding it sooner.  

We all make errors,  the key is to develop the skills to be able to track them down quickly and efficiently.
 

Simon,

We all make errors but it is important to code thoughts to a simple and orderly format so as to find those pesky buggies we all "love" so, very much. ;)

Thank you.

 
WhooDoo22:

Simon,

There's no sense in initializing a Boolean data type to false. It's redundant.

Thank you.

Clarity. Readability.

There is no functional point in adding spaces in this code . . .

double a, b, c;

a = 5.0; b = 2.0;

c = a / b;

  . . .  but if you find you have a divide by zero one day and you have a couple of thousand lines of code and plenty of comments you will be glad that you are able to find all the division operators by searching for    space / space

  instead of just   / which will find all your many comments . . .

 
RaptorUK:
The only explanation is that something in your code changes it . . .  search for SellMiddle in your code in MetaEditor using  Ctrl + F   . . .  check ever instance,  maybe it is used in function ?  and find what changes the variable,  add a debugging Print()  before and after the statement so you can see when the state changes . . . .  then kick yourself for not finding it sooner.  

We all make errors,  the key is to develop the skills to be able to track them down quickly and efficiently.

Well, that is just the thing! The very FIRST time the variable is reported in the Journal it is already "true" before ANY condition in the code can change it status only in a bar days later in time.

Is there anything wrong in declaring a double global variable as minus ?, e.g.

extern double     SellMiddleLevel=-100;

because i use the following code to change the status of this variable:

double CCIMiddleS = iCCI(NULL,PERIOD_H1,CCI,PRICE_TYPICAL,1);

    if (CCIMiddleS < SellMiddleLevel) SellMiddle = true;
 

Simon,

Initializing a Boolean to false when coding declaration code blocks is redundant OR I 'm just crazy ;) Both are true statements so either way. Hahaha!

As for your next point regarding division operators ("/"), you'll find no argument with me. Good advice.

Thank you.

 
ernest02:

Well, that is just the thing! The very FIRST time the variable is reported in the Journal it is already "true" before ANY condition in the code can change it status only in a bar days later in time.

Is there anything wrong in declaring a double global variable as minus ?, e.g. 

I don't believe that is a problem,  if it was you should get an error or warning at compile time . . .   it's easy to find out though,  add a debugging Print() just before that line and print it's value,  if it is -100 then it's an OK thing to do . . 

You need to find where in your code SellMiddle is changed, for example,  if you did SellMiddle++; by mistake it would probably change it from false to true  :-)
 

I think I have found the problem.

I had the global variable SellMiddleLevel initialized to 100 at the beginning but later changed it to -100.

I was under the impression that when I recompile this new value would be picked up and become part of the new .exe, but that did not happen.

I seem to have no other option but to change it in the Expert Properties before i run the test.

Is my conclusion correct?

Reason: