pine-script - 就图而言,买入和卖出信号相差一根蜡烛
问题描述
我试图根据以下策略生成的信号绘制图表。但我从脚本中观察到信号生成点与 Candle 不同。如果有人知道这件事,请帮助我。作为参考,我附在下面的快照
//@version=4
strategy("My Strategy", overlay=true)
orderType = 0
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
orderType := 1
shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
orderType := -1
plot(orderType,"OrderType",color.black)
解决方案
//@version=4
strategy("My Strategy", overlay=true, process_orders_on_close=true)
orderType = 0
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
orderType := 1
shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
orderType := -1
plot(orderType,"OrderType",color.black)
推荐阅读
- java - 递归期间出现错误“线程“主”java.lang.StackOverflowError 中的异常”
- html - 用悬停将圆形照片分成四部分
- c# - SharePoint 2013 CSOM 请求超时
- python - pandas sqrt 和 root 不起作用并产生 NaN
- pagination - HUGO 如何在条款页面中使用分页?
- python - Python 的 cv2 凸缺陷距离太大?
- python - Python datetime 模块和获取当前时间
- aws-cdk - 如何在 CDK 管道中运行数据库迁移
- javascript - 按出现次数升序对元素数组进行排序
- javascript - 如何为具有不同类名的元素重复 Javascript 表达式