Minimum 5 Closes above SMA50

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #196679 quote
    Alex72
    Participant
    New

    Hi, i’m new with coding, want to write a condition for

    • Minimum of 5 candles that closes above SMA50
    • Detect the the last Pivot high if the first condition is true.

    Thank you for your help

    #196696 quote
    robertogozzi
    Moderator
    Master

    Only post in the language of the forumthat you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.

    Moved from the French forum.

    Thank you 🙂

    #196721 quote
    robertogozzi
    Moderator
    Master

    There you go:

    DEFPARAM DrawOnLastBarOnly = True
    ONCE x= 0
    ONCE y= 0
    N     = 5
    Sma50 = average[50,0](close)
    Above = summation[N](close > Sma50) = N
    Pivot = highest[N](high)
    IF Above THEN
       x = BarIndex-N+1
       y = Pivot
    ENDIF
    Drawsegment(x,y,BarIndex+1,y) coloured(0,0,255,255)
    RETURN
    #197057 quote
    Alex72
    Participant
    New

    Thank you

    nothing is displayed if i let this

    DEFPARAM DrawOnLastBarOnly = True

    And when i erase it , i got he signal like in the attachement.

    Can i have the signal only once when the condition is met and will repeat it when the price meet the condition once again after the next first 5 closes above SMA50?

    Thank you

    #197059 quote
    Alex72
    Participant
    New

    Sorry: here are the condition:

    • C1=First 5 Closes above SMA50
    • C2=Last Pivot high when C1 is true
    • Draw segment when price cross above this last Pivot (from the pivot  to the Barindex )

    The process restart again if price closes back under SMA50 without getting C1

    Thank you

    #197078 quote
    robertogozzi
    Moderator
    Master

    The code above works fine as it is written (see attached pic) and displays only on the last bar (if there’s a valid signal).

    This version will only plot AFTER 5 (or more) bars from the last signal:

    ONCE x      = 0
    ONCE y      = 0
    ONCE Count  = 0
    ONCE N      = 5
    Count = Count - 1
    Sma50 = average[50,0](close)
    Above = summation[N](close > Sma50) = N
    Pivot = highest[N](high)
    IF Above AND (Count <= 0) THEN
       x     = BarIndex-N+1
       y     = Pivot
       Count = 5
       Drawsegment(x,y,BarIndex,y) coloured(0,0,255,255)
    ENDIF
    RETURN
    #197114 quote
    Alex72
    Participant
    New

    Thank you, but i just want it to stay in the history, that’s why, if you can help me.

    #197115 quote
    robertogozzi
    Moderator
    Master

    What’s wrong in my last code?

    #197117 quote
    Alex72
    Participant
    New

    Ah Sorry Nicolas, i saw only the pictures attached without testing the Code, it’s wonderful, thank you a lot, you are really a Genius.

    #197120 quote
    robertogozzi
    Moderator
    Master

    Sorry, I attached a wrong picture.

    Roberto

    #197125 quote
    Alex72
    Participant
    New

    Nope

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

Minimum 5 Closes above SMA50


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Alex72 @alex72 Participant
Summary

This topic contains 10 replies,
has 2 voices, and was last updated by Alex72
3 years, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/03/2022
Status: Active
Attachments: 3 files
Logo Logo
Loading...