pine-script - 使用定义了限制和停止的 strategy.exit 进行回测不一致
问题描述
似乎无法弄清楚为什么回测没有严格遵守我的限制和停止值。大多数订单都在 3%,但我得到的订单在交易列表中以 3.38% 或 3.91% 的价格退出,这不是我需要的行为。我看到大约 15% 的时间差异不适合 3%
我认为它可能是 strategy.position_avg_price 但我不知道有任何其他方法可以获取从 strategy.entry 创建的订单的价格。
//@version=4
strategy("GS MACD Strategy v2",
shorttitle="GSMACDv2",
overlay=true,
pyramiding=0,
currency=currency.USD,
initial_capital=1000,
default_qty_type=strategy.percent_of_equity,
default_qty_value=90,
commission_type=strategy.commission.percent,
commission_value=0.3,
calc_on_every_tick=true,
backtest_fill_limits_assumption=1)
// MACD Params
fastLength = input(12)
slowlength = input(26)
MACDLength = input(7)
PercentVal = .03
SellPrice = strategy.position_avg_price * (1 + PercentVal)
StopLossPrice = strategy.position_avg_price * (1 - PercentVal)
// Calc MACD Lines
MACD = ema(close, fastLength) - ema(close, slowlength)
aMACD = ema(MACD, MACDLength)
delta = MACD - aMACD
enterLong = crossover(delta, 0)
if (enterLong)
strategy.entry("LE", strategy.long)
if (strategy.position_size > 0)
strategy.exit("LC", "LE", limit = SellPrice , stop = StopLossPrice)
解决方案
推荐阅读
- html - 输入类型=带有最小值和最大值的文本模式数字
- rxjs - 合并运算符的 Rxj 错误
- javascript - jQuery .then() 没有按预期工作
- json - 如何从文件 Json 或 Excel 中解析数据
- php - 如何在 CodeIgniter 的 db->get_where() 中使用“大于”和“小于”?
- java - 如何加密分割文件的每一部分
- android - 无法在 android studio 中解析方法 overridePendingTransition
- java - 小程序未在浏览器中显示
- google-cloud-platform - 预留静态私有 IP 和实例组的定价和配额
- android - 在android的片段中添加内容之前必须调用requestFeature()