Sizer calculating ATR indicator values
Is there a way for a sizer to hold the ATR calculation without initializing ATR in the strategy init?
For design decoupling purposes I would like the sizer to calculate a specific ticker's ATR value and then compute the position size,the ATR calculation should be the sizer's "head ache",not the strategies init ..
Can a sizer calculate ATR values for data without that ATR been initialized in the strategy?
this does not seem to calculate ATR values :
# inside the sizer def _getsizing(self, comminfo, cash, data, isbuy): atr = bt.indicators.ATR(data, period=self.atr_parameter) # not initialized in __init__,**always empty ...** return position_size_that_depends_on_atr # crash ..
Sizerinstance is created inside the Strategy and the indicator will look for such Strategy to register itself. It has to do it or it wouldn't else work.
Bottomline: It will still be as if you had done inside the Strategy
Caveat Emptor: never tried.
Thank you for your reply ( and kudos on the incredible work ..)
Has this been solved? If so is it possible to post the Sizer code? Thanks!
class AtrBasedPositionSize(bt.Sizer): def __init__(self, atr_parameter, one_bar_risk, atrs): self.atr_parameter = atr_parameter self.atrs = atrs def _getsizing(self, comminfo, cash, data, isbuy): if(len(data)<=self.atr_parameter):return 0 ticker = data._name position_size = int((self.broker.getvalue()) / self.atrs[ticker]) return position_size