pine-script - 如何确保我的交易有 2 种不同的止损(松树脚本)?
问题描述
被困在这个问题上一段时间了。在我的策略脚本中,我允许同时打开 2 个仓位(在同一个方向)。然而,现在最终发生的是,当交易开始时,第一个头寸的止损变为第二个头寸的止损。这造成了相当多的不必要的损失。我想我需要存储第一个止损的价值(价值何时?),但我无法弄清楚。有人知道如何解决这个问题吗?谢谢!
shortEntry = MACDfilter == "Yes" ? ((shortCond and hist < 0) or (shortCond[1] and hist[1] > 0 and hist <0)) : shortCond
bgShort = shortEntry ? color.orange : na
bgcolor(bgShort)
SfixedATRSL = float(na)
SfixedATRTP = float(na)
SfixedATRSL := (longEntry and typeTPSL =="ATR - fixed") ? na : shortEntry ? close + (atr * atrStopMultiplier) : SfixedATRSL[1]
SfixedATRTP := (longEntry and typeTPSL =="ATR - fixed") ? na : shortEntry ? close - ((atr * atrStopMultiplier)* rr) : SfixedATRTP[1]
if (strategy.position_size < 0 and barstate.isconfirmed)
strategy.exit(id="Short TP/SL", limit=S_typeTP, stop=S_typeSL)
我尝试了一些有价值的事情,但没有得到我希望的结果..
SL_trade1 = strategy.opentrades == (1 or 2) ? na : valuewhen(strategy.opentrades == 0 and shortEntry,close + (atr * atrStopMultiplier),0)
SL_trade2 = strategy.opentrades == (0 or 1) ? na : valuewhen(strategy.opentrades == 1 and shortEntry,close + (atr * atrStopMultiplier),0)
解决方案
推荐阅读
- reactjs - 如何使用 TypeScript 实现 React Hook Form 智能表单组件
- android - 通知滑动时“onNotificationRemoved”不起作用
- spring - Spring Boot 2.5 中 server.error.path 的默认值是多少?
- azure-devops - Azure DevOps - 以积压优先级查询更改历史记录
- python - How to do regex operation with tensorflow string?
- api - 如何在币安套接字管理器 api 中获取符号信息?
- python - 有没有办法从图像列表中创建 numpy 数组?
- java - Flowable 使用 RxJava ReactiveX 执行任务和返回值
- php - Laravel PHPunit 设置数据在 dataprovider 中为空
- functional-programming - SICP Checking eval 是一个 thunk?