@backtrader Any help would be appreciated ?
Thanks in advance !!
@backtrader Any help would be appreciated ?
Thanks in advance !!
Also, I'm working with csv feed for daily data.
Hi All,
I'm working on exit conditions for my strategy and just wanted to backtest it with this great framework. Below is the brief about what i'm trying to achieve : -
Exit the the open position (or Force Exit ) when current value of portfolio drop by rules defined by RMS.
If Possible, perform this operation during intraday price move too. (Note: I've tried to achieve this through Cheat_on_open option. But, that's crazy configuration and it has changed performance of my strategy drastically.)
Below is the code snipet, which i'm trying to execute for above logic. However, respective code block for exit position is not triggering.
def next(self):
# Check if an order is pending ... if yes, we cannot send a 2nd one
if self.order:
return
# Check if we are in the market
if not self.position:
#BUY
if (self.breakout[0]>1):
self.log('BUY CREATE, %.2f' % self.dataclose[0])
# Keep track of the created order to avoid a 2nd order
self.order = self.buy()
#SELL
elif (self.breakout[0]<0):
self.log('SELL CREATE, %.2f' % self.dataclose[0])
# Keep track of the created order to avoid a 2nd order
self.order = self.sell()
else :
#self.log('No Action, %.2f' % self.dataclose[0])
return
else:
# Already in the market, Verfiy Position
#Hard Exit if Account value drop by according to Risk management
currAccVal = round(self.broker.getvalue(),2)
riskVal = round((currAccVal*0.03),2)
thresholdVal = round((currAccVal - riskVal),2)
self.log("Current value : %.2f Threshold value : %.2f "%(currAccVal,thresholdVal))
if(currAccVal < thresholdVal):
self.log("Force Exit : RMS Active !!")
self.order = self.close()
I'm able to get get current account value and able to place condition as given in below code for force exit. But, this code block is not working at all.
#Hard Exit if Account value drop by according to Risk management
currAccVal = round(self.broker.getvalue(),2)
riskVal = round((currAccVal*0.03),2)
thresholdVal = round((currAccVal - riskVal),2)
self.log("Current value : %.2f Threshold value : %.2f "%(currAccVal,thresholdVal))
if(currAccVal < thresholdVal):
self.log("Force Exit : RMS Active !!")
self.order = self.close()
Would be great, if anyone can suggest something here.
Thanks in advance !!