Hello everybody,
I’d like to change the following code so that only the first Green after Red appears (or first Red after Green), i.e. I’d like only the Signals with arrows to appear. The idea is to include this into an Algo where only the first Signal is taken.
I tried with the “CondLongExclusive”, but it didn’t work.
Thanks
StoK = Stochastic[14,3](close)
StoD = Stochasticd[14,3,5](close)
MyRSI = RSI[14](close)
Cond1 = StoK > StoK[1] and StoK[2] > StoK[1]
Cond2 = StoK > StoD
Cond3 = MyRSI > MyRSI[1]
Cond10 = StoK < StoK[1] and StoK[2] < StoK[1]
Cond20 = StoK < StoD
Cond30 = MyRSI < MyRSI[1]
SignalLong = 0
SignalShort = 0
if cond1 and cond2 and cond3 then
SignalLong = +1
endif
if cond10 and cond20 and cond30 then
SignalShort = -1
endif
CondLongExclusive=0
CondLongExclusive = SignalLong=1 and (SignalShort[1]=-1 or SignalShort[2]=-1 or SignalShort[3]=-1 or SignalShort[4]=-1 or SignalShort[5]=-1 or SignalShort[6]=-1 or SignalShort[7]=-1 or SignalShort[8]=-1)
RETURN SignalLong as "Long", SignalShort as "Short"
There you go:
StoK = Stochastic[14,3](close)
StoD = Stochasticd[14,3,5](close)
MyRSI = RSI[14](close)
Cond1 = StoK > StoK[1] and StoK[2] > StoK[1]
Cond2 = StoK > StoD
Cond3 = MyRSI > MyRSI[1]
Cond10 = StoK < StoK[1] and StoK[2] < StoK[1]
Cond20 = StoK < StoD
Cond30 = MyRSI < MyRSI[1]
SignalLong = 0
SignalShort = 0
if cond1 and cond2 and cond3 then
SignalLong = +1
endif
if cond10 and cond20 and cond30 then
SignalShort = -1
endif
//CondLongExclusive=0
//
//CondLongExclusive = SignalLong=1 and (SignalShort[1]=-1 or SignalShort[2]=-1 or SignalShort[3]=-1 or SignalShort[4]=-1 or SignalShort[5]=-1 or SignalShort[6]=-1 or SignalShort[7]=-1 or SignalShort[8]=-1)
IF SignalLong THEN
MySignal = SignalLong
ENDIF
IF SignalShort THEN
MySignal = SignalShort
ENDIF
x = MySignal
IF MySignal = MySignal[1] THEN
x = 0
ENDIF
RETURN (x = 1) as "Long", -(x = -1) as "Short"
Excellent, thank you so much Roberto and Merry Christmas !
Merry Christmas Khaled, thank you 😊