【问题标题】:Stochastic pine script stratygy随机松脚本策略
【发布时间】:2021-10-31 03:08:15
【问题描述】:

大家好,希望你们一切顺利,

我正在尝试编写一个策略,当 k 处于超买区域并越过 d 时做多,反之则做空

但是我是新手,如果交叉发生在超买区域,我现在不知道如何写多头。

谢谢大家,

【问题讨论】:

标签: pine-script stochastic


【解决方案1】:

我编写了以下代码,以获得当 k 处于超买区域并越过 d 时做多的策略结果,反之则做空。 在代码注释中添加了更多详细信息。

//@version=5
strategy("Stochastic Strategy", overlay=true)
//Stochastic Inputs
length = input.int(14, minval=1)
OverBought = input(80)
OverSold = input(20)
smoothK = 3
smoothD = 3
k = ta.sma(ta.stoch(close, high, low, length), smoothK)
d = ta.sma(k, smoothD)
//Rule to define crossover /crossunder
co = ta.crossover(k,d)
cu = ta.crossunder(k,d)

if (not na(k) and not na(d))
    //code to define if k is in overbought zone and k crossover d and enter a long trade
    if (co and k < OverSold)
        strategy.entry("StochLE", strategy.long, comment="StochLE")
    //code to define if k is in oversold zone and k crossunder d and enters a short trade
    if (cu and k > OverBought)
        strategy.entry("StochSE", strategy.short, comment="StochSE")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-24
    • 1970-01-01
    • 2022-08-05
    • 2012-09-25
    • 2020-05-01
    • 2011-08-09
    • 2012-09-26
    相关资源
    最近更新 更多