Hi
I am trying to get a piece of code that measures a close below the ema above the ema and below the ema – I have come up with :-
But its bust 🙁
Any Help gratefully appreciated
If Barindex > 229 then
For TP = 24 downto 1 do
//Loop 1 Close Below EMA
IF close[tp] < ExponentialAverage[8](close)[tp] and close[tp] < ExponentialAverage[20](close) [tp] then
//Save When the TP started
TP1=TP
//We Found The first Calculation
C1 = 1
break
else
c1=0
endif
next
For TP1 = 24 downto 1 do
//Loop 1 Close Below EMA
IF close[tp] > ExponentialAverage[8](close)[tp] and close[tp] > ExponentialAverage[20](close) [tp] then
//Save When the T2 started
TP2=TP1
//We Found The second Calculation
C2 = 1
break
else
c2=0
endif
next
For TP2 = 24 downto 1 do
//Loop 1 Close Below EMA
IF close[tp] < ExponentialAverage[8](close)[tp] and close[tp] < ExponentialAverage[20](close) [tp] then
//We Found The third Calculation
C3 = 1
break
else
c3=0
endif
next
endif
If c1 and c2 and c3 then
DRAWTEXT(“ON”,barindex,.1,SansSerif,Bold,10)coloured(0,255,0)
endif
return
Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
Thank you 🙂
Line 4:
x = summation[24](close < ExponentialAverage[8](close) and close < ExponentialAverage[20](close))
line 17:
y = summation[24](close > ExponentialAverage[8](close) and close > ExponentialAverage[20](close))
line 29:
z = summation[24](close < ExponentialAverage[8](close) and close < ExponentialAverage[20](close))
Lines 4 and 29 are identical, so I must be misunderstanding something.
Moreover, my examples won’t detect adjacent occurrences only, but any occurrence.
More detailed info on what you want to achieve would be beneficial.
Thank you Roberto
I really appreciate your help
The reason for the duplicate is that I want to detect when the close is :-
A. below both the 8 and 20 ema
B. above both the 8 and 20 ema
C. Back below both the 7 and 20 ema
In that order
I hope that’s clearer
There you go:
n = 24
p1 = 0
p2 = 0
IF BarIndex > 229 AND close < ExponentialAverage[8](close) and close < ExponentialAverage[20](close)THEN
FOR i = n - 1 DOWNTO 1
IF close[i] < ExponentialAverage[8](close[i]) and close[i] < ExponentialAverage[20](close[i]) THEN
p1 = i
Break
ENDIF
NEXT
FOR j = p1 - 1 DOWNTO 1
IF close[j] > ExponentialAverage[8](close[j]) and close[j] > ExponentialAverage[20](close[j]) THEN
p2 = j
Break
ENDIF
NEXT
If p1 > 0 and p2 > 0 then
DRAWTEXT("ON",barindex,high + range,SansSerif,Bold,10)coloured(0,128,0,255)
ENDIF
ENDIF
return