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
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 🙂
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
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
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
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
Thank you, but i just want it to stay in the history, that’s why, if you can help me.
What’s wrong in my last code?
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.
Sorry, I attached a wrong picture.
Roberto