首页 > 解决方案 > 策略:在一天中的第一个柱/小时的低点买入并在一天结束时卖出 - 代码不起作用

问题描述

//@version=4
strategy("Ap", overlay=true, calc_on_every_tick=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, process_orders_on_close=false)

// Limit trading to 1 trade per day
strategy.risk.max_intraday_filled_orders(count=2)

嗨,我是 Pine 的新手,我的代码无法正常工作,希望能得到一些帮助。这应该在 SPY(常规交易时间)1 小时图表上运行。我想要它做的是以下内容:

  1. 如果触及当天第一根柱的低点,买入(限价或市价都无所谓)
  2. 如果触及当天第一根柱的高点,则卖出。
  3. 在一天结束时(16:00)卖出。

感谢任何帮助。谢谢

// Initial Balance High & Low 1
highTimeFrame = input("D", type=input.resolution)
sessSpec = input("0930-1600", type=input.session)

is_newbar(res, sess) =>
    t = time(res, sess)
    na(t[1]) and not na(t) or t[1] < t

newbar = is_newbar("1440", sessSpec)

var float s1 = na
var float s2 = na
if newbar
    s1 := low
    s2 := high

plot(s1, style=plot.style_circles, linewidth=2, color=color.red)
plot(s2, style=plot.style_circles, linewidth=2, color=color.lime)



// ------------------------ Entry & Exit -------------------------
TradeWindow = time(timeframe.period, "1030-1500") 
IBLBuy = (low < s1) or (low[1] < s1) or (low[2] < s1) or (low[3] < s1) or (low[4] < s1) or (low[5] < s1)

longCondition = IBLBuy 
if (longCondition)
    strategy.entry(id="Long", long=true, limit=s1, when=TradeWindow)

shortCondition = (close > s2) or (hour == 14 and minute == 30)
if (shortCondition)
    strategy.close(id="Long")

标签: pine-script

解决方案


推荐阅读