“//@version=5
strategy(“M EX”, overlay=true)
//inputs
E= input.int(5,title=”EMA”)
//Calcultions
E1=ta.ema(close,E)
[Macd,signal,histogram]=ta.macd(close,12,26,9)`
//Conditions
Up= E1>close and Macd<0 and signal <0 and histogram<0 and histogram>histogram[1]
Up1= E1>close and Macd>0 and signal >0 and histogram >0 and histogram >histogram[1]
Down= E10 and signal >0 and histogram>0 and histogram<histogram[1]
Down1= E1>close and Macd<0 and signal <0 and histogram <0 and histogram <histogram[1]
Upexit=closehistogram[1] and Macd>0 and signal >0
Upexit1=close<E1 and histogram <histogram[1] and Macd>0 and signal >0 and histogram>0
Downexit=E1<close and histogram<histogram[1] and Macd<0 and signal<0
Downexit1=E10 and signal>0 and histogram>0
//Buy and sell
if(Long)
strategy.entry(“Long”,strategy.long, comment=”LE”) // entrt
if(Longexit)
strategy.close(“Long”,when=Longexit,comment=”LS”)
if(short)
strategy.entry(“short”,strategy.short, comment=”SE”)
if(shortexit) //exit
strategy.close(“short”,when=shortexit,comment=”SS”)
//Plot
plot(E1)
I have created a pine script and it not working as I expect it, I have given the code to buy and sell as on trend changes according to its directions but it’s not working as expected, it buys on wrong signals
kesav rajendran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.