SuperTrend + RSI Trigger

mailbagman2000

Member
VIP
Hello Experts,

I am fairly new to coding but managed to build this query based on some snippets around and need help in finalizing it.

IDEA : Trigger a signal on the chart when

1) UP Signal -> when -> Super trend is green and RSI is > 60 for the first time during its run before it changes to red
2) Down Arrow - > when -> Super trend is red and RSI is < 40 for the first time during its run before it changes to green

ISSUE: I have is that the below code signals only when RSI condition is met when the Super trend signal changes and not during its run.

7IcPFZ2.png



def ATR = ATR(10, AverageType.HULL);
def UP_Band_Basic = HL2 + (2 * ATR);
def LW_Band_Basic = HL2 + (-2 * ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > UP_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;

def Long = if close > ST then ST else Double.NaN;
def Short = if close < ST then ST else Double.NaN;

def LongPrev = Long[1];
def ShortPrev = Short[1];

#def LongTrigger = IsNaN(Long[1]) and !IsNaN(Long);
#def ShortTrigger = IsNaN(Short[1]) and !IsNaN(Short);
#def bullcrossovercondST = LongTrigger;
#def bearcrossovercondST = ShortTrigger;

def bullcrossovercondST = Long and ShortPrev;
def bearcrossovercondST = Short and LongPrev;

def NetChange = MovingAverage(AverageType.WILDERS, close - close[1], 14);
def TotChange = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), 14);
def ChgRatio = if TotChange != 0 then NetChange / TotChange else 0;
def RSI = 50 * (ChgRatio + 1);
def bullcrossovercondRSI = RSI > 60;
def bearcrossovercondRSI = RSI < 40;

plot Bullish = bullcrossovercondST and bullcrossovercondRSI;
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(8));
Bullish.SetLineWeight(2);

plot Bearish = bearcrossovercondST and bearcrossovercondRSI;
Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bearish.SetDefaultColor(GetColor(8));
Bearish.SetLineWeight(2);
nothing shows up when I copy the script
 
Hello Experts,

I am fairly new to coding but managed to build this query based on some snippets around and need help in finalizing it.

IDEA : Trigger a signal on the chart when

1) UP Signal -> when -> Super trend is green and RSI is > 60 for the first time during its run before it changes to red
2) Down Arrow - > when -> Super trend is red and RSI is < 40 for the first time during its run before it changes to green

ISSUE: I have is that the below code signals only when RSI condition is met when the Super trend signal changes and not during its run.

7IcPFZ2.png


Code:
def ATR = ATR(10, AverageType.HULL);
def UP_Band_Basic = HL2 + (2 * ATR);
def LW_Band_Basic = HL2 + (-2 * ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > UP_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;

def Long = if close > ST then ST else Double.NaN;
def Short = if close < ST then ST else Double.NaN;

def LongPrev = Long[1];
def ShortPrev = Short[1];

#def LongTrigger = IsNaN(Long[1]) and !IsNaN(Long);
#def ShortTrigger = IsNaN(Short[1]) and !IsNaN(Short);
#def bullcrossovercondST = LongTrigger;
#def bearcrossovercondST = ShortTrigger;

def bullcrossovercondST = Long and ShortPrev;
def bearcrossovercondST = Short and LongPrev;

def NetChange = MovingAverage(AverageType.WILDERS, close - close[1], 14);
def TotChange = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), 14);
def ChgRatio = if TotChange != 0 then NetChange / TotChange else 0;
def RSI = 50 * (ChgRatio + 1);
def bullcrossovercondRSI = RSI > 60;
def bearcrossovercondRSI = RSI < 40;

plot Bullish = bullcrossovercondST and bullcrossovercondRSI;
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(8));
Bullish.SetLineWeight(2);

plot Bearish = bearcrossovercondST and bearcrossovercondRSI;
Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bearish.SetDefaultColor(GetColor(8));
Bearish.SetLineWeight(2);

Any luck experts !! is this not doable?
 
Last edited by a moderator:
Let me know if this helps. just add this to the bottom of the code

Code:
# ... (unchanged code)

# New variables to track if the condition was met during the run
def metBullishRSI = if !IsNaN(Long) then bullcrossovercondRSI else metBullishRSI[1];
def metBearishRSI = if !IsNaN(Short) then bearcrossovercondRSI else metBearishRSI[1];

# Reset the tracking variables when the Super Trend flips
def resetBullish = !IsNaN(Short) and IsNaN(Short[1]);
def resetBearish = !IsNaN(Long) and IsNaN(Long[1]);

def metBullishRSIReset = if resetBullish then 0 else metBullishRSI;
def metBearishRSIReset = if resetBearish then 0 else metBearishRSI;

# New conditions for BullishSignal and BearishSignal signals
plot BullishSignal = bullcrossovercondST and !metBullishRSIReset and bullcrossovercondRSI;
BullishSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BullishSignal.SetDefaultColor(GetColor(8));
BullishSignal.SetLineWeight(2);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Thread starter Similar threads Forum Replies Date
F SuperTrend RSI Strategy Help Questions 1
N Looking For SuperTrend Questions 1
rvaidyamath TTM with SuperTrend Questions 0
PAYtience Supertrend with 2 timeframes Questions 0
M Supertrend indicator Questions 3

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
477 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top