Pine script 对于pine脚本,我有一个关于链接条件的问题

Pine script 对于pine脚本,我有一个关于链接条件的问题,pine-script,Pine Script,我是新来的松树脚本。一直在使用FX dreema。但我想转向交易观点 希望在EMA的顺序正确时,在EMA发生回调时编写警报。但不确定如何将这两个条件联系起来 没有找到易于遵循的参考手册 //@version=1 study(title="MA Cross ATTEMPT", overlay=true) s20ema = ema(close, 20) s50ema = ema(close, 50) s80ema = ema(close, 80) plot(s2

我是新来的松树脚本。一直在使用FX dreema。但我想转向交易观点

希望在EMA的顺序正确时,在EMA发生回调时编写警报。但不确定如何将这两个条件联系起来

没有找到易于遵循的参考手册

//@version=1
study(title="MA Cross ATTEMPT", overlay=true)

    s20ema = ema(close, 20)
    s50ema = ema(close, 50)
    s80ema = ema(close, 80)


    plot(s20ema, title="Ema 20", color = yellow, linewidth = 1, transp=0)
    plot(s50ema, title="Ema 50", color = red, linewidth = 1, transp=0)
    plot(s80ema, title="Ema 80", color = white, linewidth = 2, transp=0)


    longCond = crossover(s20ema, s50ema) and (s20ema > s80ema) and (s50ema > s80ema)
    shortCond = crossunder(s20ema, s50ema) and (s20ema < s80ema) and (s50ema < s80ema)

    buy_pullback = open > s20ema and low < s20ema
    sell_pullback = open < s20ema and low > s20ema

    alertcondition(buy_pullback, title='Long', message='EURAUD_buy')
    alertcondition(sell_pullback, title='Short', message='EURAUD_sell')
/@version=1
研究(title=“MA交叉尝试”,叠加=真)
s20ema=ema(关闭,20)
s50ema=ema(关闭,50)
s80ema=ema(关闭,80)
绘图(s20ema,title=“Ema 20”,颜色=黄色,线宽=1,传输=0)
绘图(s50ema,title=“Ema 50”,颜色=红色,线宽=1,传输=0)
绘图(s80ema,title=“Ema 80”,颜色=白色,线宽=2,传输=0)
longCond=交叉(s20ema、s50ema)和(s20ema>s80ema)以及(s50ema>s80ema)
shortCond=交叉(s20ema,s50ema)和(s20emas20ema,低位s20ema
alertcondition(买入回调,标题为“长”,消息为“买入欧元”)
alertcondition(卖出回撤,title='Short',message='EURAUD\u卖出')

最好学习当前版本的Pine v4,因此此代码使用v4(参见第一行)。您的代码被修改,以便跟踪两种不同的状态:
longCond
shortCond
,图表的背景反映了这两种状态。当处于状态
longCond
时,可能会发生
buy\u回调
。当处于状态
shortCond
时,可能会发生
sell\u回调
。在您的
sell\u回调
条件下,我将
low
更改为
high
。代码中的注释解释发生了什么。不确定这是你需要的,但它可能会帮助你走上正轨

//@version=4
study(title="MA Cross ATTEMPT", overlay=true)

s20ema = ema(close, 20)
s50ema = ema(close, 50)
s80ema = ema(close, 80)

plot(s20ema, title="Ema 20", color = color.yellow, linewidth = 1, transp=0)
plot(s50ema, title="Ema 50", color = color.red, linewidth = 1, transp=0)
plot(s80ema, title="Ema 80", color = color.white, linewidth = 2, transp=0)

// ————— This switches between long and short conditions.
// The declarations with "var" allow the variable's value to be preserved throughout bars.
var longCond = false
var shortCond = false
if not longCond and crossover(s20ema, s50ema) and (s20ema > s80ema) and (s50ema > s80ema)
    // These ":=" assignment operators are required because we are changing the value of previously declared variables.
    // If we used "=" here, we would be declaring new variables local to each "if" block that would disappear once out of it.
    longCond := true
    shortCond := false
if not shortCond and crossunder(s20ema, s50ema) and (s20ema < s80ema) and (s50ema < s80ema)
    shortCond := true
    longCond := false
// This colors the background to show which state you are in.
bgcolor(longCond ? color.green : shortCond ? color.red : na, transp = 85)

// The entry triggers only occur when we are in the proper state.
buy_pullback = longCond and crossover(open, s20ema) and low < s20ema
sell_pullback = shortCond and crossunder(open, s20ema) and high > s20ema

// These plot when your entries occur, so that you can verify where they trigger.
plotchar(buy_pullback, "buy_pullback", "▲", location.belowbar, color.lime, size = size.tiny)
plotchar(sell_pullback, "sell_pullback", "▼", location.abovebar, color.fuchsia, size = size.tiny)

alertcondition(buy_pullback, title='Long', message='EURAUD_buy')
alertcondition(sell_pullback, title='Short', message='EURAUD_sell')
/@version=4
研究(title=“MA交叉尝试”,叠加=真)
s20ema=ema(关闭,20)
s50ema=ema(关闭,50)
s80ema=ema(关闭,80)
绘图(s20ema,title=“Ema 20”,颜色=color.yellow,线宽=1,传输=0)
绘图(s50ema,title=“Ema 50”,颜色=color.red,线宽=1,传输=0)
绘图(s80ema,title=“Ema 80”,颜色=color.white,线宽=2,传输=0)
//-----这将在长时间和短时间条件之间切换。
//带有“var”的声明允许在整个条中保留变量的值。
var longCond=false
var shortCond=false
如果不是长秒和交叉(s20ema、s50ema)和(s20ema>s80ema)以及(s50ema>s80ema)
//这些“:=”赋值运算符是必需的,因为我们正在更改以前声明的变量的值。
//如果我们在这里使用“=”,我们将为每个“如果”块声明新的局部变量,一旦退出该块就会消失。
longCond:=真
shortCond:=假
如果不是短接和交叉(s20ema、s50ema)和(s20emas20ema
//当您的条目出现时,将绘制这些图,以便您可以验证它们在何处触发。
plotchar(买回,“买回”▲", location.belowbar,color.lime,size=size.tiny)
plotchar(卖出回撤,“卖出回撤”▼,location.overbar,color.fuchsia,size=size.tiny)
alertcondition(买入回调,标题为“长”,消息为“买入欧元”)
alertcondition(卖出回撤,title='Short',message='EURAUD\u卖出')

最好学习当前版本的Pine v4,因此此代码使用v4(请参见第一行)。您的代码被修改,以便跟踪两种不同的状态:
longCond
shortCond
,图表的背景反映了这些情况。当处于
longCond
状态时,可以发生
buy\u回调
。当处于
shortCond
状态时,可以发生
sell\u回调
。我将
low
更改为在您的
sell\u回调
条件中出现
high
。代码中的注释解释了发生了什么。不确定这是您需要的,但它可能会帮助您上路

//@version=4
study(title="MA Cross ATTEMPT", overlay=true)

s20ema = ema(close, 20)
s50ema = ema(close, 50)
s80ema = ema(close, 80)

plot(s20ema, title="Ema 20", color = color.yellow, linewidth = 1, transp=0)
plot(s50ema, title="Ema 50", color = color.red, linewidth = 1, transp=0)
plot(s80ema, title="Ema 80", color = color.white, linewidth = 2, transp=0)

// ————— This switches between long and short conditions.
// The declarations with "var" allow the variable's value to be preserved throughout bars.
var longCond = false
var shortCond = false
if not longCond and crossover(s20ema, s50ema) and (s20ema > s80ema) and (s50ema > s80ema)
    // These ":=" assignment operators are required because we are changing the value of previously declared variables.
    // If we used "=" here, we would be declaring new variables local to each "if" block that would disappear once out of it.
    longCond := true
    shortCond := false
if not shortCond and crossunder(s20ema, s50ema) and (s20ema < s80ema) and (s50ema < s80ema)
    shortCond := true
    longCond := false
// This colors the background to show which state you are in.
bgcolor(longCond ? color.green : shortCond ? color.red : na, transp = 85)

// The entry triggers only occur when we are in the proper state.
buy_pullback = longCond and crossover(open, s20ema) and low < s20ema
sell_pullback = shortCond and crossunder(open, s20ema) and high > s20ema

// These plot when your entries occur, so that you can verify where they trigger.
plotchar(buy_pullback, "buy_pullback", "▲", location.belowbar, color.lime, size = size.tiny)
plotchar(sell_pullback, "sell_pullback", "▼", location.abovebar, color.fuchsia, size = size.tiny)

alertcondition(buy_pullback, title='Long', message='EURAUD_buy')
alertcondition(sell_pullback, title='Short', message='EURAUD_sell')
/@version=4
研究(title=“MA交叉尝试”,叠加=真)
s20ema=ema(关闭,20)
s50ema=ema(关闭,50)
s80ema=ema(关闭,80)
绘图(s20ema,title=“Ema 20”,颜色=color.yellow,线宽=1,传输=0)
绘图(s50ema,title=“Ema 50”,颜色=color.red,线宽=1,传输=0)
绘图(s80ema,title=“Ema 80”,颜色=color.white,线宽=2,传输=0)
//-----这将在长时间和短时间条件之间切换。
//带有“var”的声明允许在整个条中保留变量的值。
var longCond=false
var shortCond=false
如果不是长秒和交叉(s20ema、s50ema)和(s20ema>s80ema)以及(s50ema>s80ema)
//这些“:=”赋值运算符是必需的,因为我们正在更改以前声明的变量的值。
//如果我们在这里使用“=”,我们将为每个“如果”块声明新的局部变量,一旦退出该块就会消失。
longCond:=真
shortCond:=假
如果不是短接和交叉(s20ema、s50ema)和(s20emas20ema
//当您的条目出现时,将绘制这些图,以便您可以验证它们在何处触发。
plotchar(买回,“买回”▲,location.belowbar,color.lime,size=size.tiny)
plotchar(卖出回撤,“卖出回撤”▼,location.overbar,color.fuchsia,size=size.tiny)
alertcondition(买入回撤,title='Long',me