pine-script - 为什么当蜡烛颜色改变时这个脚本(pinescript)没有退出?
问题描述
我想在蜡烛收盘红色时退出做多,当蜡烛收盘绿色时退出做空。
如果达到一定的利润百分比,也想退出。
下面的代码是打开 LONG 并关闭...类似于 SHORT。
longExitPrice = strategy.position_avg_price * (1+longProfitPerc)
shortExitPrice = strategy.position_avg_price / (1+shortProfitPerc)
closedGreen = barstate.isconfirmed and (close > open)
closedRed = barstate.isconfirmed and (close < open)
if (inDateRange)
if(enterLONG and strategy.position_size == 0 )
strategy.entry(id="LONG" , long=true , when=highABO)
if (enterSHORT and strategy.position_size == 0 )
strategy.entry(id="SHORT" , long=false , when=lowABO)
positions = strategy.position_size
if (strategy.position_size > 0 )
strategy.exit("Exit/TP","LONG" , limit = longExitPrice)
if(closedRed)
strategy.exit("Stop Loss/TP","SHORT")
if (strategy.position_size < 0 and close > open)
strategy.exit("Stop Loss/TP","SHORT" , limit = shortExitPrice)
if(closedGreen)
strategy.exit("Stop Loss/TP","SHORT" )
解决方案
不要在strategy.exit()
没有参数的情况下使用。改为使用strategy.close()
。
if(closedRed)
strategy.close("Short")
推荐阅读
- mapbox - 如何将带有旋转的图标图像添加到静态 MapBox 图像?
- javascript - jquery on(click) 每次点击,信息取自第一个元素
- html - 我的 h1 元素的文本比元素的实际高度短。我可以删除空白空间吗?
- node.js - 改进 mongoose find() 查询执行时间
- python - 字符串列上的雾索引
- python - libvlc - http 流错误:本地流 1 错误:取消 (0x8)
- node.js - NodeJS 上的 FortiClient
- flutter - 在颤振运行期间收到多条错误消息(与 gradle 相关)
- java - 在编写junit测试用例时在Spring Webflux中自动装配ApplicationContext
- java - XMLBeans 无法加载 SchemaTypeSystem。无法加载名为 schemaorg_apache_xmlbeans.system 的类