Boolean question.

 

Hello MQL4 community,

I have a condition for Boolean to be true or false.

When the condition is met, Boolean is true, BUT ;) when the condition changes, Boolean is false.

Does any coder have any ideas to keep Boolean true even when condition changes in the future?


example:

Indicator now meets condition. Boolean is now true and stays true until later code states Boolean is false.

Boolean stays true even when indicator does not meet condition AFTER Boolean is currently true.


Thank you.

 
static bool ...... have you tried that one?
 
WhooDoo22:

Hello MQL4 community,

I have a condition for Boolean to be true or false.

When the condition is met, Boolean is true, BUT ;) when the condition changes, Boolean is false.

Does any coder have any ideas to keep Boolean true even when condition changes in the future?


example:

Indicator now meets condition. Boolean is now true and stays true until later code states Boolean is false.

Boolean stays true even when indicator does not meet condition AFTER Boolean is currently true.

You need a 2nd Bool to act as a latch . . . for example:

bool SetBool = true;
bool IndicatorCondition = false;

if(SetBool)
   {
   if( iCustom(. . . . . ) >= x )
      {
      IndicatorCondition = true;
      SetBool = false;               //  <-- latch is now set
      }
   }

 

@Ubzen: I am not acquainted with the term "static bool". Please express your thoughts regarding it. I wish to understand it's terminology.

Thanks much!


@Simon: Right on! ;)

Thank you.

 

Static simply means it'll save the value. Static variables cannot survive a Terminal Restart tho. Best to save em to file.

static bool Indicator_Meet;
if( Moving_Average1 == Moving_Average2 ){ Indicator_Meet=true; }
if( OrderProfit()>0 ){ CloseAllOrders(); Indicator_Meet=false; }
 

I will code "static bool" if I obtain a spare moment. I am grateful to you for sharing your thoughts regarding "static bool".

Currently I am plowing all of my power into MMA_Breakout strategy Volume II. It will be a legendary and monumental achievement in the whole firmament of glorious moments in my life.

I hope that I do not die before its completion. The code is very difficult to sift through and organize/optimize.

Thank you ubzen.

 
You're welcome. Nah... you couldn't die before its completion. But after, now that's a different story ;). Hopefully it's not the excitement which kicks the bucket.
Reason: