Algorithmic Trading & Indicators
Intermediate
Supertrend + Intraday VWAP + RSI Confluence Strategy in Python (Single-Trade Per Trend)
Combine Supertrend (10,3), Intraday Session VWAP, and RSI(14) in Python Pandas with strict single-trade-per-trend state lock to prevent overtrading.
#pandas#numpy
Problem Statement
Standalone indicators trigger multiple whipsaw entries during choppy market hours. Combining Supertrend direction, VWAP institutional bias, and RSI momentum (>55 for Long, <45 for Short) with a state lock eliminates duplicate entries.
Formula / Core Logic
Bull_Entry = (Supertrend == 1) & (Close > VWAP) & (RSI > 55) & (Prev_Position != 1)
Bear_Entry = (Supertrend == -1) & (Close < VWAP) & (RSI < 45) & (Prev_Position != -1)
Installation
pip install pandas numpy
supertrend-vwap-rsi-intraday-confluence-strategy-python.py
import pandas as pd
import numpy as np
def supertrend_vwap_rsi_confluence(df):
# Assumes df already has columns: 'Close', 'ST_Trend' (1/-1), 'VWAP', 'RSI'
df = df.copy()
raw_long = (df['ST_Trend'] == 1) & (df['Close'] > df['VWAP']) & (df['RSI'] > 55)
raw_short = (df['ST_Trend'] == -1) & (df['Close'] < df['VWAP']) & (df['RSI'] < 45)
signals = np.zeros(len(df), dtype=int)
current_state = 0
for i in range(len(df)):
if raw_long.iloc[i] and current_state != 1:
signals[i] = 1
current_state = 1
elif raw_short.iloc[i] and current_state != -1:
signals[i] = -1
current_state = -1
df['Confluence_Signal'] = signals
return df
Get the Complete 100+ Python Quant & Automation Bundle
Instant lifetime access to all production-ready scripts, valuation models, and trading bots ($19).
Buy Full Bundle on Gumroad ($19) →Frequently Asked Questions
Q: Why use a `current_state` lock in the loop?
It guarantees that once a Long trade is taken, the bot will not fire another Long signal until a valid Short reversal occurs first.