TradingView Pine脚本多重转换策略

问题描述 投票:0回答:2

我拼命地寻求在交易视图中编写策略的帮助,在该视图中,我试图创建3种不同移动平均线(尤其是9 ema,21 ema和33简单移动平均线)的交叉买卖信号。我想做的是,当9个ema超过21个ema时,存在一个较长的条件,而当21个ema超过33个简单移动平均线时,也具有相同的长条件。我希望这对多头和空头都适用-将9和21用作“小信号”,而将21和33用作“大信号”,我想不通...这是我最近的有以下内容,它将无法正常工作:/请帮助,我将为您的下6件装venmo / cash应用程序!

//@version=3
//study(title="MA Crossover Strategy", overlay = true)
strategy("EMA Crossover Strategy", overlay=true)
src = input(close, title="Source")

price = security(tickerid, period, src)
ema1 = input(9, title="1st EMA Length")
type1 = input("EMA", "1st EMA Type", options=["SMA", "EMA"])

ema2 = input(21, title="2nd EMA Length")
type2 = input("EMA", "2nd EMA Type", options=["SMA", "EMA"])

sma3 = input(33, title="1st MA Length")
type3 = input("SMA", "2nd SMA type", options=["SMA", "EMA"])

price1 = if (type1 == "EMA")
ema(price, ema1)
else
sma(price, ema1)

price2 = if (type2 == "EMA")
sma(price, ema2)
else
ema(price, ema2)

price3 = if (type3 == "SMA")
sma(price, sma3)
else
ema(price, sma3)

//plot(series=price, style=line,  title="Price", color=black, linewidth=1, transp=0)
plot(series=price1, style=line,  title="1st EMA", color=blue, linewidth=2, transp=0)
plot(series=price2, style=line, title="2nd EMA", color=yellow, linewidth=2, transp=0)
plot(series=price3, style=line, title="1st MA", color=orange, linewidth=2, transp=0)

longCondition = crossover(price1, price2) and crossover(price2, price3)
if (longCondition)
strategy.entry("Long", strategy.long)

shortCondition = crossunder(price1, price2) and crossover(price2, price3)
if (shortCondition)
strategy.entry("Short", strategy.short)

信号不会显示,但是如果您删除两个条件的最后一个“和交叉”部分,它将仅适用于9 ema和21 ema,但我想合并21 ema和33简单的叉号

algorithmic-trading trading pine-script crossover
2个回答
0
投票

请下次复制带有空格/制表符的代码,因此不需要重新格式化。另外,请勿将[tradingiew-api]标记用于与Pine有关的问题,如标记说明中所述。


© www.soinside.com 2019 - 2024. All rights reserved.