如何将两种多交易策略组合成单一策略?

时间:2021-01-17 04:09:39

标签: pine-script algorithmic-trading trading

我有两个指标 -

第一个指标 - 1 小时时间范围的随机指标 第二个指标 - MACD 1 分钟时间框架

我想将这两个指标的买入/卖出信号组合成一个单一的策略,如下所示:

  1. 如果 1 小时随机指标给出买入信号,则将我们的交易偏向或方向视为买入。 现在因为随机指标在 1 小时的时间范围内运行,所以它会给出更少的信号。 由于我们的 MACD 在 1 分钟的时间范围内运行,因此它会给出多个买入/卖出信号。 现在从随机指标我们得到了买入的方向,所以我只想使用买入交易 1 分钟时间范围内的 MACD。 Ex - 1 H 时间框架给了我们买入信号,这是我们的偏见。现在使用 MACD 我们 获得大约 30 个买入/卖出信号。但由于偏差已经设置,所以我们将只采用 MACD 的买入信号,所以 这减少了信号的数量,因此它会小于 30。

  2. 这将与第一个条件相同,但在相反的方向,我们的偏见将是卖出,我们将采取 使用 MACD 在 1 分钟的时间范围内卖出交易。

随机策略:-

strategy("Stochastic Slow Strategy", overlay=true)
length = input(14, minval=1)
OverBought = input(80)
OverSold = input(20)
smoothK = 3
smoothD = 3
k = sma(stoch(close, high, low, length), smoothK)
d = sma(k, smoothD)
co = crossover(k,d)
cu = crossunder(k,d)
if (not na(k) and not na(d))
if (co and k < OverSold)
    strategy.entry("StochLE", strategy.long, comment="StochLE")
if (cu and k > OverBought)
    strategy.entry("StochSE", strategy.short, comment="StochSE")

MACD 策略:-

strategy("MACD Strategy", overlay=true)
fastLength = input(12)
slowlength = input(26)
MACDLength = input(9)
MACD = ema(close, fastLength) - ema(close, slowlength)
aMACD = ema(MACD, MACDLength)
delta = MACD - aMACD
if (crossover(delta, 0))
    strategy.entry("MacdLE", strategy.long, comment="MacdLE")
if (crossunder(delta, 0))
    strategy.entry("MacdSE", strategy.short, comment="MacdSE")

所以我想将这两种策略合二为一。

我的尝试似乎不正确:-

strategy("Stochastic MACD", overlay = true,initial_capital = 1000000,currency=currency.USD,default_qty_type=strategy.percent_of_equity,default_qty_value=100)
length = input(14, minval=1)
OverBought = input(80)
OverSold = input(20)
smoothK = 3
smoothD = 3
k = sma(stoch(close, high, low, length), smoothK)
d = sma(k, smoothD)
co = crossover(k,d)
cu = crossunder(k,d)

fastLength = input(12)
slowlength = input(26) 
MACDLength = input(9)
MACD = ema(close, fastLength) - ema(close, slowlength)
aMACD = ema(MACD, MACDLength)
delta = MACD - aMACD

if (not na(k) and not na(d))

    if (co and k < OverSold)
        if (crossover(delta, 0))
            strategy.entry("MacdLE", strategy.long, comment="MacdLE")
        if (crossunder(delta, 0))
            strategy.entry("MacdSE", strategy.short, comment="MacdSE")
if (cu and k > OverBought)
        if (crossover(delta, 0))
             strategy.entry("MacdLE", strategy.long, comment="MacdLE")
        if (crossunder(delta, 0))
             strategy.entry("MacdSE", strategy.short, comment="MacdSE")

0 个答案:

没有答案