1

I want to trigger an alert after 2 or more conditions are satisfied, but are not occurring at the same time.

For example:

  • Stage 1: RSI above 70
  • Stage 2: Close above Keltner Channel
  • Stage 3 & trigger: Close below EMA10

For stage 3 to trigger, it must occur less than 10 bars after stage 1. The process should continue on a rolling basis.

Adam Lambert
  • 1,311
  • 3
  • 24
  • 45

1 Answers1

1

You could try something like this (roughly) [adapt variable names to whatever your RSI, Keltner Channel, and EMA are saved as]:

var bool stage1 = false
var bool stage2 = false
var bool stage3 = false

if (rsi > 70)
  stage1 := true
if (stage1 and close > keltnerChanel)
  stage2 := true
if (stage2 and close < ema and ta.barssince(stage1) < 10)
  stage3 := true
if (stage3)
  alert("Stage 3")
if (ta.barssince(stage1) > 9)
  stage1 := false
  stage2 := false
  stage3 := false