Bet way to consolidate parameter flags?
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.
PanagiotisCharalampous
22 Jun 2020, 08:34
Hi iucpxleps,
You can modify the condition as follows
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous