首页 > 解决方案 > 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?

标签: pine-scripttradingview-api

解决方案


这段代码

// 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)

给出下一个结果: 在此处输入图像描述


推荐阅读