Just a quick note; I was trying to debug this strategy and the size was a bit overwhelming. Every line of code we don't write is by definition correct, and makes the program easier to debug.
So the following long if/else construct in the strategy...
- Code: Select all
Price=instance.parameters.Price;
if Price=="close" then
LR = core.indicators:create("LOGARITHMIC_REGRESSION", Source.close, instance.parameters.Period, instance.parameters.Deviation);
elseif Price=="open" then
LR = core.indicators:create("LOGARITHMIC_REGRESSION", Source.open, instance.parameters.Period, instance.parameters.Deviation);
elseif Price=="high" then
LR = core.indicators:create("LOGARITHMIC_REGRESSION", Source.high, instance.parameters.Period, instance.parameters.Deviation);
elseif Price=="low" then
LR = core.indicators:create("LOGARITHMIC_REGRESSION", Source.low, instance.parameters.Period, instance.parameters.Deviation);
elseif Price=="typical" then
LR = core.indicators:create("LOGARITHMIC_REGRESSION", Source.typical, instance.parameters.Period, instance.parameters.Deviation);
elseif Price=="median" then
LR = core.indicators:create("LOGARITHMIC_REGRESSION", Source.median, instance.parameters.Period, instance.parameters.Deviation);
else
LR = core.indicators:create("LOGARITHMIC_REGRESSION", Source.weighted, instance.parameters.Period, instance.parameters.Deviation);
end
...is functionally equivalent to this much shorter code:
- Code: Select all
Price = instance.parameters.Price or 'weighted'
LR = core.indicators:create("LOGARITHMIC_REGRESSION", Source[Price], instance.parameters.Period, instance.parameters.Deviation)