pine-script - 策略:在一天中的第一个柱/小时的低点买入并在一天结束时卖出 - 代码不起作用
问题描述
//@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 小时图表上运行。我想要它做的是以下内容:
- 如果触及当天第一根柱的低点,买入(限价或市价都无所谓)
- 如果触及当天第一根柱的高点,则卖出。
- 在一天结束时(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")
解决方案
推荐阅读
- java - Version issue in custom jar
- kubernetes - k8s - ReplicaSet matchLabel 选择器的意义
- c++ - Large binary read in windows 10 is faster when run as admin
- python - 在 Python 中安装 -D /dev/null path_file 功能
- r - R:根据前一行合并连续行
- http - 如何停止http重定向到https
- mysql - Cosmos DB:更快的搜索选项
- twitter - 如何自动化在社交媒体(MS Teams、Slack、Twitter、Whats App、LinkedIn 等)上共享的链接预览?
- javascript - 如何在反应中清除传单地图,以便绘制新数据?
- c - 计算和打印n个数的gcd和lcm的ac程序