英文:
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_long
和strategy.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,"Margin Long")
marginShort = input.float(25,"Margin Short")
strategy("My strategy", overlay=true, margin_long=marginLong, margin_short=marginShort)
This way, you will be able to use it after in your code.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论