我创建了一个 pine 脚本,但它没有按我预期的方式工作,我已经给出了根据其方向在趋势变化时买卖的代码,但它没有按预期工作,它根据错误的信号进行购买
//@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")
您的代码有多个语法错误。
例如:
0r 代表 或
E10 为 E1
//@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 = E1 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 = 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 = E1<close and signal>0 and histogram>0
//Entry
Long = Up or Up1
Longexit = Upexit or Upexit1
short = Down or Down1
shortexit = Downexit or Downexit1
//Buy and sell
if(Long)
strategy.entry("Long",strategy.long, comment="LE")
// entrt
if(Longexit)
strategy.close("Long",comment="LX")
if(short)
strategy.entry("short",strategy.short, comment="SE")
if(shortexit)
strategy.close("short",comment="SX")
您的脚本现在可以编译,但请记住使用 chatgpt 生成的代码不可靠
GPT相关代码