Pinescript TradingView 回测策略不产生任何数据

时间:2021-04-04 19:50:49

标签: pine-script

策略总结:

  1. 使用 15' 时间框架触发特定股票的空头头寸。
  2. 交易触发价格是盘前最后 15 根蜡烛线的低点减去 10 美分。
  3. 交易只能在新交易日(美国东部时间 0930-0945)的前 15 分钟内触发。
  4. 一旦触发空头头寸,我想在价格向下移动时退出交易 触发价格或价格上涨 0.80 美元(利润目标)0.40 美元(止损 - 损失)来自触发价格。

下面是我写的代码,它目前不产生任何数据。 我是 Pinescript 的新手,任何帮助正确格式化和工作的帮助将不胜感激!


//@version=4

strategy("Closing Range Breakdown")

//I want the lowest price from this time period.
lastPremarketCandle = time(timeframe.period, "0915-0930:23456")

//I only want a trade to trigger short during the first 15 minutes of the trading day.
firstFifteenMinutes = time(timeframe.period, "0930-0945:23456")

//grabbing the low price of the last 15 minute candle of the premarket.
lowestValue = lastPremarketCandle ? low : na

//I want to be triggered into the trade 10 cents below the low of the lastPremarketCandle once the market is open.
tradeTriggerPrice = lowestValue - 0.10

//Here I'm creating a stop loss as well as a profit target.
profitTarget = tradeTriggerPrice - 0.80
stopLoss = tradeTriggerPrice + 0.40

//I want my backtest to cover this period of time.
var start = timestamp(2016, 1, 1, 0, 0)
var end = timestamp(2021, 3, 31, 0, 0)

//checking conditions to make sure we are backtesting the right time frame and incorporating the right price levels
if (time >= start and time <= end and firstFifteenMinutes)
    strategy.entry("short", strategy.short, 1250, when = tradeTriggerPrice)

//closing out the position if we hit the stop loss or the take profit target
strategy.close("closePosition", when = stopLoss or profitTarget)

0 个答案:

没有答案