Pine- Script/ Trading View Not able to get the proper code for getting high + buffer value

302 views Asked by At

I am trying to execute a strategy using Pine script where the following condition should match and a long should get executed :

Condition : crossover (ema10, ema20) and ((High of crossover + buffer) of crossover(ema10,ema20)) happens. I am not able to get the longentry, can you please help in resolving this?

Below is my code for the same :

study("Crossover and highcrossover", overlay=true)

ema10 = ema(close, 10)
ema20 = ema(close, 20)
psar = sar(0.02,0.02,.2)

crossoverval = crossover(ema10, ema20)

signalhigh = iff(crossoverval == 1, high, na)
highbufferadd = signalhigh + 3.0
plot(signalhigh, title="signalhigh", color = green, linewidth = 1, transp=1)
plot(highbufferadd, title="highbufferadd", color = yellow, linewidth = 1, transp=1)

longentry = crossoverval and (close > highbufferadd)
 
plotshape(series=crossoverval, title="Crossover", style=shape.arrowup, location=location.belowbar, color=green, text="Crossover", size=size.small)
plotshape(series=longentry, title="longentry", style=shape.triangleup, location=location.belowbar, color=green, text="longentry", size=size.small)
plot(ema10, title="Ema 10", color = green, linewidth = 1, transp=1)
plot(ema20, title="Ema 20", color = red, linewidth = 1, transp=1)

1

There are 1 answers

0
ashok On
    study("Crossover and highcrossover", overlay=true)

ema10 = ema(close, 10)
ema20 = ema(close, 20)
psar = sar(0.02,0.02,0.2)

crossoverval = crossover(ema10,ema20)

signalhigh = iff(crossoverval == 1, high, na)
highbufferadd = signalhigh + 3.0
plot(signalhigh, title="signalhigh", color = color.green, linewidth = 1, transp=1)
plot(highbufferadd, title="highbufferadd", color = color.yellow, linewidth = 1, transp=1)

longentry = crossoverval and (close > highbufferadd)
 
plotshape(series=crossoverval, title="Crossover", style=shape.arrowup, location=location.belowbar, color=color.green, text="Crossover", size=size.small)
plotshape(series=longentry, title="longentry", style=shape.triangleup, location=location.belowbar, color=color.green, text="longentry", size=size.small)
plot(ema10, title="Ema 10", color = color.green, linewidth = 1, transp=1)
plot(ema20, title="Ema 20", color = color.red, linewidth = 1, transp=1)