Hello,
I have placed a trading guard, set max order count, to max of 3 trades per day. But when I back-test it, it gives me a runtime error of trading control violation.
def initialize(context):
context.aapl= sid(45570)
set_max_order_count(3)
set_commission(commission.PerShare(cost=0.0000, min_trade_cost=0))
def handle_data(context,data):
hist= data.history(context.aapl,'price',20, '1m')
log.info(hist.head())
sma_20= hist.mean()
sma_10= hist[-10:].mean()
open_orders= get_open_orders()
if sma_10>1.02*sma_20:
order_target_percent(context.aapl,.025)
elif sma_10<1.05*sma_20:
order_target_percent(context.aapl,0)
record(leverage=context.account.leverage)
I've attached the code I used. Any input will be helpful!