BiParticipant
New
Hi all
I am new to PRT as well as coding, I am trying to create an indicator with the below logic but the value seems to be not continuous. I feel like I am missing an obvious point, appreciate your help.
The logic behind the indicator is
Positive signal – when EMA9 crossover EMA20 while both the line being under VWMA50
Negative signal – when EMA9 crossover EMA20 while both the line being under VWMA50
The above signals are getting created accurately but I want the value to continue even when EMA9 and EMA20 crosses above VWMA50. So essentially what I am trying to do is if a positive signal occurred then show me the signal until a negative signal appears. At the moment the signal disappears when EMA9 and EMA20 crosses above VWMA50 I want the system to ignore that event and lookback the value what it was previously.
Values would look like 0000011111111111-1-1-1-1-1-1
I am not sure whether I should be using “for loop ” to get this which I’ve tried and failed.
I would very much appreciate your expert help
ma9 = ExponentialAverage[9](close)
ma20= ExponentialAverage[20](close)
ma50 = Average[50](close*volume)/Average[50](volume)
value1 = ma9-ma20
value2 = ma9-ma50
value3 = ma20-ma50
if value1 crosses over 0 and value2 <0 and value3< 0then
direction = 1
elsif value1 crosses under 0 and value2>0 and value3>0 then
direction = -1
else
direction = 0
endif
if direction[1] = 1 and value1>0 then
value = 1
elsif direction[1] =-1 and value1<0 then
value = -1
else
value = 0
endif
return value
I think you only have to remove, or comment out, line 23.
BiParticipant
New
Legend! thank you it worked