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.
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);