EMA RSI Strategy for Option Buying

Please Provide an EMA RSI Strategy for Option Buying (CALL) in Nifty

General Conditions:

  1. Strategy – Option Buying
  2. Indices – Nifty
  3. Time Frame – 3 Minute Candlestick
  4. Maximum Entries – 2 Nos per day
  5. Reward to Risk – Rs.20/- Points : Rs.15/- Points

Trigger Candle conditions:

  1. Trigger candle should be a strong bullish green candle, not a base candle.
  2. Trigger candle close should be above 15 EMA & 33 EMA.
  3. Triggered candle 15 EMA should be above 33 EMA.
  4. Trigger candle RSI should be above 60.
  5. Either body or atleast bottom wick of the triggered candle should touch 15 EMA.

Entry & Exit Conditions:

  1. Entry Time – After 09:45 AM and Before 2:30 PM.
  2. Strike Price – ATM strike Price.
  3. Entry should be on the next first candle of the triggered candle, if the price crosses high of the triggered candle in the Nifty chart.
  4. Live positions if any should exit at 03:00 PM.
  5. Before hitting Target or SL of the first entry no second entry should be taken.
2 Likes

Just a halfbaked amateur run. If it helps.

from kiteconnect import KiteConnect
import pandas as pd

kite = KiteConnect(api_key="your_api_key")
kite.set_access_token("your_access_token")

def ema_rsi_strategy():
    # Get historical data for Nifty
    data = pd.DataFrame(kite.historical_data(instrument_token=256265, from_date='2022-01-01', to_date='2022-02-01', interval='3minute'))
    
    # Calculate 15 EMA and 33 EMA
    data['ema_15'] = data['close'].ewm(span=15).mean()
    data['ema_33'] = data['close'].ewm(span=33).mean()
    
    # Calculate RSI
    delta = data['close'].diff()
    gain = delta.where(delta > 0, 0)
    loss = -delta.where(delta < 0, 0)
    avg_gain = gain.rolling(window=14).mean()
    avg_loss = loss.rolling(window=14).mean()
    rs = avg_gain / avg_loss
    data['rsi'] = 100 - (100 / (1 + rs))
    
    # Set initial values for entry and exit conditions
    entry_time_start = '09:45:00'
    entry_time_end = '14:30:00'
    exit_time = '15:00:00'
    
    entries_per_day_max = 2
    entries_per_day_count = 0
    
    reward_to_risk_ratio = 20 / 15
    
    for index, row in data.iterrows():
        # Check if current time is within entry time range
        current_time = row['date'].time()
        if current_time >= datetime.strptime(entry_time_start, '%H:%M:%S').time() and current_time <= datetime.strptime(entry_time_end, '%H:%M:%S').time():
            # Check if maximum number of entries per day has been reached
            if entries_per_day_count < entries_per_day_max:
                # Check trigger candle conditions
                if row['open'] < row['close'] and row['close'] > row['ema_15'] and row['close'] > row['ema_33'] and row['ema_15'] > row['ema_33'] and row['rsi'] > 60 and (row['low'] <= row['ema_15'] or (row['open']+row['close'])/2 <= row['ema_15']):
                    # Entry condition met
                    print(f"Entry condition met at {row['date']} with price {row['high']}")

                    # Calculate target price and stop loss price based on reward to risk ratio
                    target_price = round(row['high'] + reward_to_risk_ratio * abs(row['high'] - data.loc[index-1]['low']), 2)
                    stop_loss_price = round(row['high'] - abs(row['high'] - data.loc[index-1]['low']), 2)

if row[‘high’] > data.loc[index-1][‘high’]:

Place entry order if the price crosses high of the triggered candle in the Nifty chart

@trade4lyf Check out the image below to learn how to create the strategy conditions: