Hello everyone! How are you doing?
I have some coding requests, i hope you can help me 🙂
1- The price has increased by x percent over the last x candles.
2- The price has remained within a certain range (moved sideways) over the last x candles
3- The price has remained over a moving average over the last x candles
4- Set the stop loss at the low of the last x candles.
Bonus: The price has formed higher highs over the last x candles.
Thanks.
There you go:
// 1
ONCE X = 10
ONCE PC = 5
Gap = ((close / close[X - 1]) - 1) * 100
RETURN (Gap >= PC) AS "%rise"
// 2
ONCE X = 10
HH = highest[X](high[1])
LL = lowest[X](low[1])
Signal = 0
IF high <= HH AND low >= LL THEN
Signal = 1
ENDIF
RETURN Signal AS "Signal"
// 3
ONCE X = 10
ONCE P = 20
Sma = average[P,0](close)
//Above= close > Sma
Below = close < Sma
Number = BarsSince(Below)
RETURN Number AS "Number of Bars Above"
// 4
ONCE X = 5
SET STOP PRICE lowest[X](low)
// Bonus
ONCE X = 10
Result = summation[X](high > high[1])
Thank you Roberto!
Just a question: in n.3 where is “X” used? And why did you greyed out the above condition? Since the price need to stay over the moving average the below condition should be greyed out no?
So it should be something like
Above= close > Sma
//Below = close < Sma
Number = BarsSince(Above)
RETURN Number AS "Number of Bars Above"