我是Pine脚本的新手。一直在使用FX皮肤。但想转到交易视图。
要写警报,以指示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')
答案 0 :(得分:1)
最好学习当前版本的Pine v4,因此此代码使用v4(请参见第一行)。您的代码经过修改,因此可以跟踪两个不同的状态:longCond
和shortCond
,并且图表的背景反映了这些状态。处于状态longCond
时,可能会发生buy_pullback
。处于状态shortCond
时,可能会发生sell_pullback
。我在您的low
条件下将high
更改为sell_pullback
。代码中的注释说明了正在发生的事情。不确定这是否是您所需要的,但这可能会帮助您上路。
//@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')
您将在这里找到有用的信息来开始学习Pine:http://www.pinecoders.com/