Protecting the value of a bool?

Created at 31 Jan 2018, 15:46
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
DR

Drummond360

Joined 22.12.2017

Protecting the value of a bool?
31 Jan 2018, 15:46


Hi,

Is it possible to protect the value of a bool ?

Here's a simplified version of what I'm trying to achieve;


bool FirstFibLevel = false;
               {
                   if (price < 7)
                   {
                       FirstFibLevel = true;
                   }
               }

               if (FirstFibLevel == true)
               {
                   Place order to enter trade at 10

Now when the price is below 7 the bool is true. If it rises from 7 to our desired level of 10 it becomes false again… but we want to remember that it has been below 7...

 

Is there a better alternative to using a bool?

Many thanks in advance,

Drummond


@Drummond360
Replies

PanagiotisCharalampous
31 Jan 2018, 16:10

Hi Drummond,

If you provide the complete code sample then we can suggest you how to do it.

Best Regards,

Panagiotis


@PanagiotisCharalampous

markae
01 Feb 2018, 09:27

RE:

Just check if it is still "false" and only then check the "price"-Value. Once it becomes true stop checking the price value

bool FirstFibLevel = false;

if(!FirstFibLevel)
{
    if (price < 7)
    {
        FirstFibLevel = true;
    }
    else
    {
         FirstFibLevel = false  // not really necessary
    }
}

if (FirstFibLevel)
{
    Place order to enter trade at 10
}

 

 


@markae

Drummond360
01 Feb 2018, 11:34

RE: RE:

Fantastic, thank you Markae...

markae said:

Just check if it is still "false" and only then check the "price"-Value. Once it becomes true stop checking the price value

bool FirstFibLevel = false;

if(!FirstFibLevel)
{
    if (price < 7)
    {
        FirstFibLevel = true;
    }
    else
    {
         FirstFibLevel = false  // not really necessary
    }
}

if (FirstFibLevel)
{
    Place order to enter trade at 10
}

 

 

 


@Drummond360