Please Provide an EMA RSI Strategy for Option Buying (CALL) in Nifty
General Conditions:
- Strategy – Option Buying
- Indices – Nifty
- Time Frame – 3 Minute Candlestick
- Maximum Entries – 2 Nos per day
- Reward to Risk – Rs.20/- Points : Rs.15/- Points
Trigger Candle conditions:
- Trigger candle should be a strong bullish green candle, not a base candle.
- Trigger candle close should be above 15 EMA & 33 EMA.
- Triggered candle 15 EMA should be above 33 EMA.
- Trigger candle RSI should be above 60.
- Either body or atleast bottom wick of the triggered candle should touch 15 EMA.
Entry & Exit Conditions:
- Entry Time – After 09:45 AM and Before 2:30 PM.
- Strike Price – ATM strike Price.
- 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.
- Live positions if any should exit at 03:00 PM.
- 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: