pine-script - Strategy.entry 数量(固定或百分比)
问题描述
我在交易视图中有这个策略:
strategy("NAME", "SHORT_NAME", overlay=true, default_qty_type=strategy.percent_of_equity, initial_capital=100, default_qty_value=20, precision=4, currency = currency.USD, pyramiding =5, commission_value = 0.075)
我尝试了不同的选项,但结果不同:
if (buy)
strategy.entry(id="BUY", long=true)
它可以工作,但会忽略 default_qty_value 并使用机器人中的所有大写配置。
if (buy)
strategy.entry(id="BUY", long=true, qty = 20)
不会在 Pine Script 中给出任何错误,但机器人(来自 Quadency)没有收到警报
if (buy)
strategy.entry("BUY", strategy.long, 10)
这就是 Quadency 教程中的写法。不起作用,Pine 脚本给出语法错误
我希望机器人下订单 20% 的 initial_capital,这样我就可以一次运行 5 个订单。
我应该如何编写 strategy.entry?
解决方案
这段代码
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adolgov
//@version=4
strategy("My Strategy", overlay=true, initial_capital=100, currency = currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=20)
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
推荐阅读
- c# - 统一的Inventorysystem得到Nullreference错误
- python - 将字典列表合并到一个列表中
- javascript - 如何将 html 上的 firebase 查询结果显示为列表?
- javascript - 错误 找不到绑定文件。VS 代码上的 JS/TS
- swagger - 如何在 OpenAPI / Swagger 中指定两个路径模板部分的示例
- javascript - 在 DOM 中添加新元素后,FabricJS 画布停止工作
- c# - 通过 Angular 11 应用程序和 .Net 4.7.2 Web API 正确使用 CAS 身份验证
- pointers - 是否可以从另一个进程中获取值?
- python - 如何仅在另一个 python 列表中的某个值之后附加到列表?
- apache-kafka - KStream 过滤器是否消耗每条消息?