Bet way to consolidate parameter flags?

Created at 21 Jun 2020, 20:53
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!
IU

iucpxleps

Joined 01.11.2017

Bet way to consolidate parameter flags?
21 Jun 2020, 20:53


hi,

I'm wondering what would be the best way to consolidate parameter set flags of true/false.

I have a flag to use or not use a function ie. if set to true, take RSI into account or not etc but stuffing these onto each other with all the combinations make the code really unmanageable and a lot of if clauses.

ie:

Parameter("Include RSI Enter", DefaultValue = true)]
public bool UseRsiEnter { get; set; }

private bool rsiBlockLong = true;
private bool rsiBlockShort = true;

if (UseRsiEnter)
            {
                rsiBlockLong = (rsi.Result.Last(1) < 75);
                rsiBlockShort = (rsi.Result.Last(1) > 25);
            }

private bool enterShort(bool rsiBlockShort, double currentSlowMa, double currentMediumMa, double currentFastMa)
        {
            return mediumMa.Result.HasCrossedBelow(slowMa.Result, 3) && (currentFastMa < currentSlowMa) && (currentMediumMa < currentSlowMa) && (rsiBlockShort == true);
        }

I'm not sure how to integrate this further to make it work when true but when it's false just ignore the RSI requirement. I don't want to take (rsiBlockShort == true) out into new if and duplicate the whole line for true and false...

thanks in advance.


@iucpxleps
Replies

PanagiotisCharalampous
22 Jun 2020, 08:34

Hi iucpxleps,

You can modify the condition as follows

(!UseRsiEnter|| rsi.Result.Last(1) > 25)

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous