You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pine Script中strategy.long与strategy.short含义及示例代码作用是什么?

Pine Script中strategy.long与strategy.short的含义及作用

基础含义

  • strategy.long是Pine Script策略模块的内置常量,代表多头入场方向,底层固定取值为1,无需开发者手动定义赋值。
  • strategy.short是对应的方向常量,代表空头入场方向,底层固定取值为-1。

示例代码中的作用

你给出的代码片段如下:

strategy.entry("LONG", strategy.long, when = "some_condition")
strategy.close("LONG", when = "some_condition")

strategy.entry("SHORT", strategy.short, when = "some_condition")
strategy.close("SHORT", when = "some_condition")

两个常量的核心作用都是给strategy.entry开仓函数指定交易方向:

  1. 第一行传入strategy.long,指定当some_condition条件触发时,执行多头开仓操作,这笔订单的唯一标识为LONG。
  2. 第三行传入strategy.short,指定当对应条件触发时,执行空头开仓操作,这笔订单的唯一标识为SHORT。
  3. 后续的strategy.close函数通过匹配订单ID即可定向平掉对应仓位,不需要再传入方向参数。

使用内置方向常量而非直接写1/-1的好处是代码可读性更强,也能避免手动填值出错的问题。

内容的提问来源于stack exchange,提问作者Abhinav Manthri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 04:45:07