Search code examples
pine-scriptpine-script-v5tradingview-apipine-script-v4

Pinescript error when using strategy entry


I'm using this indicator and trying to modified it to make alert. Its done.
Then when I'm trying to add strategy entry it says
error : compiling script
and the indicator doesn't work; it disappears, without any detail.
I've tried 5-10 code about strategy entry and strategy error no one working.
I want to test this indicator into tradingview strategy tester.

enter image description here

// Tradingview.com Pinescript @author Ni6HTH4wK [LAVA]
study(title="[LAVA] Heiken Ashi Oscillator")

// Inputs
n1  = input(10, title="Multiplier", minval=1)
n2  = input(42, title="RSI Length", minval=2)
q1  = input(false, title="Show as RSI")

// Sources
hk_open = security(heikenashi(tickerid), tostring((interval*n1)), open)
hk_stop = security(heikenashi(tickerid), tostring((interval*n1)), close)
hk_local_open = na(hk_open[1])?open:(hk_open[1]+ohlc4[1])/2
hk_local_stop = ohlc4

// Source logic
oc_hi = max(hk_local_open,hk_local_stop)
oc_lo = min(hk_local_open,hk_local_stop)
oc_dif = avg(oc_hi-oc_lo, high-low)
dif_ema = ema(oc_dif, 14)
std_dev = stdev(dif_ema, 20)

// Heiken Ashi Logic
hk_bull = hk_stop>hk_open?low>=hk_open?3*std_dev+hk_bull[1]:1*std_dev+hk_bull[1]:0
hk_bear = hk_open>hk_stop?high<=hk_open?3*std_dev+hk_bear[1]:1*std_dev+hk_bear[1]:0

// Heiken Ashi RSI
hk_rsi = rsi(cum(hk_bull)-cum(hk_bear), 14)

// Coloring
hk_cci = cci(ohlc4, n2)>0

// Plotting
plot(q1?na:hk_bull>0?hk_bull:na, title="Bullish Heiken Ashi", style=areabr, color=#339933, transp=50)
plot(q1?na:hk_bear>0?hk_bear:na, title="Bearish Heiken Ashi", style=areabr, color=#ff0f0f, transp=50)
plot(q1?hk_rsi:na, title="Heiken Ashi RSI", linewidth=2, color=hk_cci?#459915:#cf0023, transp=50)
plot(q1?70:na, color=#222222)
plot(q1?30:na, color=#222222)


changeToGreen = hk_bull <=0
changeToRed = hk_bear <=0


alertcondition(changeToGreen, title = "AO color changed to green", message = "Awesome Oscillator's color has changed to green")
alertcondition(changeToRed, title = "AO color changed to red", message = "Awesome Oscillator's color has changed to red")

// Order conditions
enterLong = hk_bull <=0

// Submit long orders
if (enterLong)
    strategy.order(id="Enter Long", long=true)

I'm trying to make long when the green start and short when red start. Close when it change colour

I can backtest this strategy using trading view


Solution

  • You need to add the version identifier //@version=2 and change your script to a strategy.

    //@version=2
    strategy(title="[LAVA] Heiken Ashi Oscillator")