RC2_PARAM_RANGE_INVERTED
תוכן זה אינו זמין עדיין בשפה שלך.
Param
<name>declaresminabovemax(oropt_minaboveopt_max). A range that runs backwards is empty.
What it means
min is the smallest value the parameter may hold and max is the largest. Written the other way round they describe a range with nothing in it: there is no value the parameter may take, no stop for a slider to offer, and no dimension for the optimizer to walk.
It used to compile green. The attribute took the two numbers as written, the optimizer’s from > to grid produced no dimension at all, and the control drew a slider whose thumb could not move — a parameter that looked tunable and was not.
Why it happens
Two numbers typed in the order they came to mind:
class BackwardsRange(Strategy): period = Param(20, min=200, max=2) trade = Symbol() sizing = FixedCapital()
def execute(self): sma = SMA(self.period, on=self.trade) if sma.value > 0 and self.trade.is_flat: self.buy(self.trade)The optimizer pair has the same rule:
class BackwardsOptRange(Strategy): period = Param(20, min=2, max=200, opt_min=100, opt_max=10) trade = Symbol() sizing = FixedCapital()
def execute(self): sma = SMA(self.period, on=self.trade) if sma.value > 0 and self.trade.is_flat: self.buy(self.trade)How to fix it
Swap them. A range where the two ends are EQUAL is legal — it is a constant, which is a thing an author sometimes means.
class FixedRange(Strategy): period = Param(20, min=2, max=200, opt_min=10, opt_max=100) trade = Symbol() sizing = FixedCapital()
def execute(self): sma = SMA(self.period, on=self.trade) if sma.value > 0 and self.trade.is_flat: self.buy(self.trade)Related
Param()RC2_PARAM_DEFAULT_OUT_OF_RANGE— the ends are the right way round, but the default is not between them.RC2_PARAM_INT_BOUND— the ends are fractional on an integer parameter.