3 candle higher/lower break out with RSI call/put buy

@Imran sir,
I am using 3 candle breakout candle with RSI pattern for call/put buying with sym as a F&O stock symbol.


# ---------- ENTRY ----------
        for _, row in df.iterrows():

            if not is_entry_window() or len(positions) >= MAX_TRADES:
                break

            sym = row["Symbol"]
            print(f"\nChecking {sym}")         

            chart = tsl.get_historical_data(tradingsymbol=sym,exchange="NSE",timeframe="5")
            chart['rsi'] = talib.RSI(chart['close'], timeperiod=14)
            sqn_lib.sqn(df=chart, period=21)
            chart['market_type'] = chart['sqn'].apply(sqn_lib.market_type)
            chart['atr'] = talib.ATR(chart['high'], chart['low'], chart['close'], timeperiod=14)

            # cc = chart.iloc[-2]

            bc   = chart.iloc[-2] #pandas  breakout candle
            ic   = chart.iloc[-3] #pandas  inside candle
            ba_c = chart.iloc[-4] #pandas  base candle

            uptrend = bc['rsi'] > 40
            downtrend = bc['rsi'] < 39
            inside_candle_formed = (ba_c['high'] > ic['high']) and (ba_c['low'] < ic['low'])


            upper_side = bc['high'] > ba_c['high']
            down_side = bc['low']  < ba_c['low']

            
            bc2 = len(positions) is None
            bc3 = True  # cc['market_type'] != "neutral"
            bc4 = MAX_TRADES < 8

                      
            if uptrend and bc2 and bc3 and bc4 and upper_side :
                print("call-buy ", sym, "\t")

            ce_name, pe_name, ce_otm_strike, pe_otm_strike = tsl.OTM_Strike_Selection(Underlying=sym, Expiry=1, OTM_count=2)

            options_chart = tsl.get_historical_data(tradingsymbol=ce_name,exchange='NFO',timeframe="5")

            lot_size = tsl.get_lot_size(tradingsymbol=ce_name)
            qty = lot_size * MAX_LOTS
            rc_options = options_chart.iloc[-1]
            pty=qty/2
            ltp = tsl.get_ltp_data(names=[ce_name])[ce_name]
            base_sl =  rc_options['atr'] * atr_multipler
            target = round(ltp * 2.40,1)


            entry_order=tsl.order_placement(tradingsymbol=ce_name,exchange="NFO",quantity=qty,price=0,trigger_price=0,order_type="MARKET",transaction_type="BUY",trade_type="MIS")
            tg(f"BUY {sym}\nQty:{qty}\nSL:{base_sl}\nTarget:{target}")


            sl_order = tsl.order_placement(tradingsymbol=ce_name,exchange="NFO",quantity=qty,order_type="STOPMARKET",price=base_sl-0.05,trigger_price=base_sl,transaction_type="SELL",trade_type="MIS") 


            positions[sym] = {
                "qty": qty,
                "half": qty // 2,
                "sl": sl_order,
                "target": target
            }

            traded_symbols.add(sym)
            tg(f"BUY {sym}\nQty:{qty}\nSL:{base_sl}\nTarget:{target}")

        # ---------- EXIT MGMT ----------
        for sym, p in list(positions.items()):
            
           ltp = tsl.get_ltp_data(names=[ce_name])[ce_name]

            if not ltp:
                continue

            if ltp >= p["target"] and "partial" not in p:
                tsl.cancel_order(p["sl"])
                 # tsl.cancel_order(OrderID=base_sl)

                tsl.order_placement(
                    tradingsymbol=ce_name,
                    exchange="NFO",
                    quantity=p["half"],price=0,trigger_price=0,
                    order_type="MARKET",
                    transaction_type="SELL",
                    trade_type="MIS"
                )

                tsl.order_placement(
                    tradingsymbol=ce_name,
                    exchange="NFO",
                    quantity=p["half"],
                    order_type="STOPMARKET",price=trigger_price -0.05,
                    trigger_price=round(ltp - atr / 2, 1),
                    transaction_type="SELL",
                    trade_type="MIS"
                )

                sl_points                         = rc_options['atr']*atr_multipler
                options_ltp                       = sl.get_ltp_data(names=[ce_name])[ce_name]
                tsl_level                         = options_ltp - sl_points

                if tsl_level > base_sl:
                    trigger_price = round(tsl_level, 1)
                    price         = trigger_price - 0.05
                    tsl.modify_order(order_id=sl_order,order_type="STOPLIMIT",quantity=pty,price=price,trigger_price=trigger_price)
                    sl_order = tsl_level

I am getting below error: Sir, Kindly check my entry / ATR logic and guide me with correct code which i am having Data API sbuscription with recently generated token code.

Checking SAMMAANCAP
Exception in Getting OHLC data as {'status': 'failure', 'remarks': {'error_code': 'DH-905', 'error_type': 'Input_Exception', 'error_message': 'System is unable to fetch data due to incorrect parameters or no data present'}, 'data': ''}
ERROR: 'NoneType' object has no attribute 'iloc'
Traceback (most recent call last):
  File "D:\my-running-algo\new1.py", line 154, in <module>
    rc_options = options_chart.iloc[-1]
                 ^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'iloc'

Hi @Krushna_Rout ,

Do refer this thread-

yes, I have already shared it. now how to rectify it. please guide.

sir, waiting for your reply.