【问题标题】:I need help on this backtesting pinescript我需要关于这个回测 pinescript 的帮助
【发布时间】:2022-07-20 15:22:11
【问题描述】:

以下是我写的 pinescript。

我是 pinescript 的新手,想就我一直在研究的 pinescript 寻求帮助。基本上,问题出在“EntryCondition”中,其中“bullishEC”和“MA 条件”不能同时起作用。但是,如果我删除 BullishEC 条件或 MA 条件,它们会单独工作。请告知,任何输入/帮助将不胜感激!

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © thrilledBook49599

//@version=5
strategy('RSI2 Strategy', overlay=true)

// Get price of SPX500USD,1H,CLOSE
spx500usd_price = request.security('spx500usd', '60', close)

// Creating EMA Indicator
spx500usd_ema10 = ta.ema(spx500usd_price, 10)
spx500usd_ema200 = ta.ema(spx500usd_price, 200)

//Create an RSI Indicator
r = ta.rsi(close, 2)

//Create Engulfing Candle
BullishEC = open[1] > close[1] and close > open and close >= open[1] and close[1] >= open and close - open > open[1] - close[1]
BearishEC = close[1] > open[1] and open > close and open >= close[1] and open[1] >= close and open - close > close[1] - open[1]

//Create Entry Conditions Variable
longCondition = (close > spx500usd_ema200 and close < spx500usd_ema10) and r<10 and BullishEC
closelongCondition = r > 90
shortCondition = (close > spx500usd_ema200 and close < spx500usd_ema10) and r<10 and BullishEC
closeshortCondition = r < 10

strategy.entry('long', strategy.long, when=longCondition)
strategy.close('long', when=closelongCondition)

strategy.entry('short', strategy.short, when=shortCondition)
strategy.close('short', when=closeshortCondition)

plot(spx500usd_ema10)
plot(spx500usd_ema200)
plotshape(BearishEC, title='Bearish Engulfing', color= color.red, style=shape.arrowdown, text='Bearish\nEngulfing')
plotshape(BullishEC, title='Bullish Engulfing', location=location.belowbar, color=color.green, style=shape.arrowup, text='Bullish\nEngulfling')

【问题讨论】:

    标签: pine-script pinescript-v5


    【解决方案1】:

    我可以告诉你两个原因。

    #1

    TradingView 不支持对冲交易回测。这意味着你不能同时做 LONG 和 SHORT。

    #2

    strategy.entry 允许您输入单个条目,除非您设置了pyramiding 选项。

    请改用strategy.order。它允许您下多个订单。

    我也建议你检查一下你有多少职位。 因为它将继续无限订购。

    strategy.opentrades 为您提供职位编号。

    示例)

        if strategy.opentrades < 5
           strategy.order(conditions)
    

    有用吗??祝你好运!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 2014-03-11
      • 1970-01-01
      • 2014-09-25
      • 1970-01-01
      • 2021-12-13
      相关资源
      最近更新 更多