Global variable refuses to initialize

To add comments, please log in or register
Ernest Klokow
1292
Ernest Klokow  

I have a global bool variable (WPR_OS) that is set to "false" and I also have code that will set it to false under certain conditions but it will not be set to false when I run it in the ST.

I have even included it in the initialization function, int OnInit(), but still it refuses to be set to "false". Right from the start of running the EA in the ST on the very first Journal line it already shows "true".

I have another similar variable (WPR_OB) which gives no problem at all.

Why would something like this occur? I have now spent hours in trying everything I can but still it refuses to be changed to "false".

Here are some code and Journal transaction reports:


bool        WPR_OB = false;
bool        WPR_OS = false;

      ArrayResize(WPRArray,WPR_Period);

      for(int j = 0; j < WPR_Period; j++)
        {
         WPRArray[j] = iWPR(NULL,PERIOD_H1, WPR_Period, j);
        }
      double WPR_Average = iMAOnArray(WPRArray, 0, WPR_MAPeriod, 0, MODE_EMA, 0);

      WPR = DoubleToString(WPR_Average, 0);
      
   if(WPR_OB == true && WPR < -70.0) WPR_OB = false;
   if(WPR_OS == true && WPR > -30.0) WPR_OS = false;  // The value of WPR has gone as low as -15 but still the WPR_OS variable refusess to change to "false"
   
      
   if(WPR_OB == false && WPR_OS == false) //This never becomes true since the WPR_OS variable refuses to be set to "false"
      
      {

      if(WPR > -WPRoverbought)
         WPR_OB = true;
      else
         WPR_OB = false;
      if(WPR < -WPRoversold)
         WPR_OS = true;
      else
         WPR_OS = false;
      }   


Ernest Klokow
1292
Ernest Klokow  

I have tried just about everything!

1. I have tried to change the period that i am testing

2. I have tried changing the currency pair

3. I have changed the time frame

4. I have moved the EA to another broker's MT4 ST

5. I have changed the names of the variables

6. I have tried initializing it in the Expert initialization Function - int OnInit()

7. I have changed the code.

8. I have added additional code to change the value from "true" to "false"

NOTHING changes the value from "true" to "false". I cannot continue programming until I have solved the problem! Please help!

lippmaje
1190
lippmaje  
Please show all of your code. What's the value of WPRoverbought and oversold?
Ernest Klokow
1292
Ernest Klokow  
input int      WPRoversold = -85;      //WPR Bottom Level
input int      WPRoverbought = -15;    //WPR Top Level
input int      WPR_MAPeriod = 30;      //MA Period for WPR
input int      WPR_Period = 40;        //WPR Period
input ENUM_TIMEFRAMES WPR_Timeframe = PERIOD_H1; //WPR Timeframe
input ENUM_MA_METHOD WPR_MAMethod = MODE_EMA;    //MA Method for WPR
Ernest Klokow
1292
Ernest Klokow  
input int      StochHighLevel1 = 84;
input int      StochHighLevel2 = 74;
input int      StochLowLevel1 = 24;
input int      StochLowLevel2 = 34;
lippmaje
1190
lippmaje  

This is always true, because of the double negation:

if(WPR < -WPRoversold)

And so causes WPR_OS to be set to true on every call.

Ernest Klokow
1292
Ernest Klokow  

Bloody Hell! Two negatives make a positive!

So that is why WPR_OS will NEVER be "false"!!!

THANKS A LOT FOR YOUR HELP!

lippmaje
1190
lippmaje  

Ok, also your array size looks bogus. It should be dependent on WPR_MAPeriod not WPR_Period.

To add comments, please log in or register