Selection for the first Signal only – help please

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #183711 quote
    Khaled
    Participant
    Veteran

    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"
    Capture-décran-2021-12-21-à-20.29.08.png Capture-décran-2021-12-21-à-20.29.08.png
    #183790 quote
    robertogozzi
    Moderator
    Master

    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"
    Khaled thanked this post
    #183831 quote
    Khaled
    Participant
    Veteran

    Excellent, thank you so much Roberto and Merry Christmas !

    robertogozzi thanked this post
    #183836 quote
    robertogozzi
    Moderator
    Master

    Merry Christmas Khaled, thank you 😊

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Selection for the first Signal only – help please


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Khaled @khaled Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by robertogozzi
4 years, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/21/2021
Status: Active
Attachments: 1 files
Logo Logo
Loading...