INNER CODE UNIT · Python
on_bar_update
ldt9/PyOptionTrader · models/futures/short_strangle.py:564
def on_bar_update(self, bars: BarDataList, has_new_bar: bool):
self.bar_count += 1
if self.bar_count == 5:
self.bar_count = 0
try:
print(f"{self.get_timestamp()} New Bar Received...")
# Convert the BarDataList to a Pandas DataFrame
self.df = util.df(self.data)
# Check if we are in a trade and no open orders
if not self.in_trade and not self.order_placed:
# Trade a strangle
self.trade_strangle(call_delta=0.16, put_delta=-0.16, order_type='short', order_style='bracket',
take_profit_factor=0.50, stop_loss_factor=3.00, use_vix_position_sizing=False,
quantity=1, days=45)
else:
# Manage the strangle
self.manage_strangle()
except Exception as e: