btoandav20 sizers
-
Hi !
Does anyone have experience using the btoandav20.sizers.OandaV20Risk ?I think it needs to run in strategy class, next method and not in the run strat right?
I say this because this sizer requires stoploss pips which is dynamic.I tried this which probably is rubbish.
# in Strategy class I have params dict(sizer = None) # and in initi the below. I am just following bt docs. def __init__(self): if self.p.sizer is not None: self.sizer = self.p.sizer def next(self): if self.one_test_trade: globe.action = 'long' self.one_test_trade = False price = self.data0.close[0] - 0.0001 sl_px = price - self.atr[0] * 1.5 sl_pips = abs(sl_px - price) / 0.0001 limit_px = price + self.atr[0] self.ATR_at_exe = self.atr[0] self.exe_size = self.sizer.getsizing(btoandav20.sizers.OandaV20Risk, risk_percents=2, stoploss=sl_pips)
the above returns error although risk_percents is a valid param for this sizer:
TypeError: getsizing() got an unexpected keyword argument 'risk_percents'
Would some kind souls pls help me with some sample code how this is to be used?
source code of the sizer is here: https://github.com/ftomassetti/backtrader-oandav20/blob/master/btoandav20/sizers/oandav20sizer.py
Thanks a miliion!
-
changed to this:
self.exe_size = btoandav20.sizers.OandaV20Risk(risk_percents=2, stoploss=sl_pips).getsizing(data=self.data0.close[0], isbuy=True)
which returns error:
comminfo = self.broker.getcommissioninfo(data) AttributeError: 'NoneType' object has no attribute 'getcommissioninfo'
and added this in runstrat:
comminfo = forexSpreadCommisionScheme(spread=3, acc_counter_currency=False) cerebro.broker.addcommissioninfo(comminfo)
Error is still the same.
comminfo = self.broker.getcommissioninfo(data) AttributeError: 'NoneType' object has no attribute 'getcommissioninfo'
-
-
@J-T from your code examples, it is not clear what you are doing.
in a strategy, you could do the following:
self.sizer = btoandav20.sizers.OandaV20Risk(risk_percents=2, stoploss=10) print(self.sizer.getsizing(data=self.data0, isbuy=True))
which will work, when data is a oanda feed