from bhav.strategy import indicators as ta
def initialize(ctx):
    ctx.set_universe(["IN_EQ:NSE:RELIANCE"])
    ctx.set_frequency("1d")
    ctx.set_warmup(60)
    ctx.set_product("DELIVERY")
    ctx.set_protection(stop_loss_pct=0.05, take_profit_pct=0.12)
def handle_data(ctx, data):
    symbol = ctx.manifest.universe[0]
    closes = data.history(symbol, 200)
    holding = ctx.has_position(symbol)
    fast, slow = ta.ema(closes, 20), ta.ema(closes, 50)
    enter = ta.crossed_above(fast, slow)
    leave = ta.crossed_below(fast, slow)
    if not holding and enter:
        ctx.order_target_percent(symbol, 0.3)
    elif holding and leave:
        ctx.close(symbol)
