Pine Script 5 – 从strategy()函数中获取数据

huangapple go评论62阅读模式
英文:

Pine Script 5 - Access data from strategy()

问题

我正在尝试从strategy()函数中访问数据,并将其保存在一个变量中,以便在脚本中用于绘图或表格数据。我不知道这是否可能?

strategy("My strategy", overlay=true, margin_long=25, margin_short=25)

leverageLong = 100 / margin_long
leverageShort = 100 / strategy.margin_short

我尝试了margin_longstrategy.margin_short两种方式。有没有一种方法可以访问这些数据?

英文:

I'm trying to access data from the strategy() function to save this in a variable so I can use this in the script for plotting and or table data. I don't know if this is possible?

//@version=5
strategy("My strategy", overlay=true, margin_long=25, margin_short=25)

leverageLong = 100 / margin_long
leverageShort = 100 / strategy.margin_short

I tried both margin_long & strategy.margin_short. Is there a way of accessing this data?

答案1

得分: 0

在Pinescript中,margin_long和margin_short是一个固定百分比。你可以在"strategy"语句中声明后获取它们。如果你想将它们存储在一个变量中,并且可以在图表的参数面板中进行更改,你可以这样做:

marginLong = input.float(25,"Margin Long")
marginShort = input.float(25,"Margin Short")
strategy("My strategy", overlay=true, margin_long=marginLong, margin_short=marginShort)

这样,你就可以在代码中后续使用它们了。

英文:

In pinescript, the margin_long and margin_short is a fixed percentage.<br>
You can' retrieve it once declare in the 'strategy' statement.<br>
If you want it in a variable, that you will be able to change in the parameter panel on your charte, you can do this :

marginLong = input.float(25,&quot;Margin Long&quot;)
marginShort = input.float(25,&quot;Margin Short&quot;)
strategy(&quot;My strategy&quot;, overlay=true, margin_long=marginLong, margin_short=marginShort)

This way, you will be able to use it after in your code.

huangapple
  • 本文由 发表于 2023年1月8日 22:07:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75048397.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定