I’m struggling with a custom indicator I’m trying to code. It will be great if you can guide me how to handle this. The idea is:
1. If “Condition 1” occurs
2. Start counting the number of instances “Condition 2” occurs
3. Assign the number of occurrences to “X”
4. Draw ArrowUp when “Condition 3” occurs
5. Keep counting until “Condition 1” occurs again (and Reset “X”)
6. Make “X” available for other custom indicators
Condition 1: EMA(20) is the highest value among EMA(20), DEMA(20), and TEMA(20)
Condition 2: Open > SMA(Open, 10) AND Close >SMA(Open, 10)
Condition 3: Value of X is 1 AND Value of X one bar ago is not 1
The basic structure I can think of is:
if (Math.Max(EMA(20), DEMA(20), TEMA(20)) = EMA(20))) { Double X = CountIf(() => Open[0] > SMA(Open, 10) && Close[0] > SMA(Open, 10) , “int period”) }; else { X = 0; } if (X == 1 && “Value of X one bar ago” !=1 ) { Draw.ArrowUp(this, "tag1", true, 0, Low[0] - (2*TickSize), Brushes.Red); }
Reference:
CountIf()
Draw.ArrowUp()
Math.Max
Comment