【问题标题】:How to trigger crossover AND price above security in Pine Editor如何在 Pine Editor 中触发交叉和高于安全性的价格
【发布时间】:2021-11-08 20:06:49
【问题描述】:

我一直在尝试研究如何在没有运气的情况下在我的回测逻辑中从交叉和高于安全性的价格触发 LONG 和 EXIT,现在就我的回测 pine 编辑器代码寻求帮助。

我将包含我的代码的某些部分,以便您了解我要做什么。

// add trading pair outside chart data
btc_price = security("BINANCE:BTCUSDT", "D", close)

// compute the indicators ( main chart ETH/USDT ) 
smaInput = input(title="SMA", type=input.integer, defval=1)
indicator1 = sma(close,smaInput)

// compute the indicators BTC
btcsmaInput = input(title="SMABTC", type=input.integer, defval=1)
indicatorbtc = sma(btc_price,btcsmaInput)


// plot the indicators
plot(indicator1, title="Indicator1", color=color.red, linewidth=2)
plot(indicatorbtc, title="Indicator1", color=color.blue, linewidth=2)

我试图用伪代码实现的目标: 如果收盘价高于指标1(ETH/USDT) 且 BTC/USDT 价格高于指标btc,则做多 如果收盘价低于指标1(ETH/USDT) 或 BTC/USDT 收盘价低于指标btc,则退出

这是我需要帮助的代码,下面的代码不起作用,因为我在上面的伪代码中描述了它。

// Backtesting Logic
EnterLong =  crossover(close,indicator1) and crossover(btc_price, indicatorbtc)//
ExitLong = crossunder(close,indicator1) or crossunder(btc_price, indicatorbtc) //

请指教。

【问题讨论】:

    标签: pine-script algorithmic-trading trading back-testing


    【解决方案1】:

    crossover 和 crossunder 将是 true 仅适用于一根柱线,此时交叉操作变为 true。除非两个交叉同时发生,否则您的 AND 条件将失败。

    这是另一个想法,使用这些变量的实际值。所以,如果btc_price 大于indicatorbtc,你就知道这个交叉已经发生了。并且只触发一次你的入口函数,你可以使用crossover()和值比较一起使用。

    EnterLong =  (crossover(close,indicator1) or crossover(btc_price, indicatorbtc)) and ((close > indicator1) and (btc_price > indicatorbtc))
    

    因此,当其中一个交叉发生时,第一部分 (crossover(close,indicator1) or crossover(btc_price, indicatorbtc)) 只会是 true。然后您可以查看实际值以确定过去是否发生过其他交叉。那是((close > indicator1) and (btc_price > indicatorbtc)) 部分。

    【讨论】:

    • 非常感谢您抽出宝贵时间帮助我,Baris。这对我很有帮助
    • 很高兴我能提供帮助。祝您编码愉快,有问题随时回来。
    • 还有一个问题。我注意到当我使用 ((close
    • 它实际上应该与 and 运算符一起使用。你能问一个新问题吗?请在您认为它不起作用的地方添加屏幕截图。
    猜你喜欢
    • 2021-09-13
    • 1970-01-01
    • 2022-01-19
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-05
    • 2022-01-09
    相关资源
    最近更新 更多