如何正确制定策略? V5
作为初学者,我仍然感到困惑。对于我来说,太多的问题对我来说是迷宫,对不起,也许是直率的问题……
这是标题:
strategy(title="Testing Strategy Testing", initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 1, pyramiding = 20, currency = 'USD', overlay=true)
这是策略输入代码部分(可能是长期型):
if ShortItPlease and in_date_range and enable_short_strategy == true
strategy.entry("ShortItPlease", strategy.short, qty=1, when=ShortItPlease, alert_message="Open Short Position")
strategy.exit( "ShortItPlease", qty=1, from_entry="Short", loss=short_stoploss_percentage, profit=short_takeprofit_percentage, alert_message="Your Short SL/TP Limit As Been Triggered.")
strategy.close("ShortItPlease", when=when_specified, alert_message="Close Short Position")
因此,如您所见,<代码> default_qty_type = straging.percent_of_eqequity 在标题中指定,default_qty_value = 1
,但
- 在
stragent.entry.entry()
或策略中.exit()
函数(上图),似乎我们 只能独立于default_qty_value
变量独立于 ventity (如果我不指定qty
),则不会导致错误消息 - )即使是
default_qty_type
或default_qty_value
,也可以重复使用。例如,这些不是在计算中使用的变量。
如何做什么,使这些参数影响策略的行为? 也许我应该在条目函数中使用以下变量,正确调整了?目标是:基于百分比,基于 order ofer qty 的set pt/sl 按帐户余额百分比。
long_stoploss_price = strategy.position_avg_price * (1 - long_stoploss_value/100)
long_takeprofit_price = strategy.position_avg_price * (1 + long_takeprofit_value/100)
short_stoploss_price = strategy.position_avg_price * (1 + short_stoploss_value/100)
short_takeprofit_price = strategy.position_avg_price * (1 - short_takeprofit_value/100)
Being a beginner, I'm still confused; too many questions, to many options, it's a labyrinth for me yet, sorry for perhaps blunt questions…
Here's the header:
strategy(title="Testing Strategy Testing", initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 1, pyramiding = 20, currency = 'USD', overlay=true)
And here's the strategy entry code part (it could be a long-type one):
if ShortItPlease and in_date_range and enable_short_strategy == true
strategy.entry("ShortItPlease", strategy.short, qty=1, when=ShortItPlease, alert_message="Open Short Position")
strategy.exit( "ShortItPlease", qty=1, from_entry="Short", loss=short_stoploss_percentage, profit=short_takeprofit_percentage, alert_message="Your Short SL/TP Limit As Been Triggered.")
strategy.close("ShortItPlease", when=when_specified, alert_message="Close Short Position")
So as you may see, default_qty_type = strategy.percent_of_equity
is specified in the header, so is the default_qty_value = 1
but
- in the
strategy.entry()
orstrategy.exit()
function (above), it seems we
can only specifyquantity
, independently from thedefault_qty_value
variable (if I don't specifyqty
then it results an error message), - and there's not even such variables as
default_qty_type
ordefault_qty_value
, to re-use. These are not variables to be used in calculations, for example.
What to do different, to make these parameters affect the strategy's behavior?
Perhaps I should use the following variables in the entry functions, adjusted properly? Goal is: set PT/SL based on percentage, order qty based on account balance percentage.
long_stoploss_price = strategy.position_avg_price * (1 - long_stoploss_value/100)
long_takeprofit_price = strategy.position_avg_price * (1 + long_takeprofit_value/100)
short_stoploss_price = strategy.position_avg_price * (1 + short_stoploss_value/100)
short_takeprofit_price = strategy.position_avg_price * (1 - short_takeprofit_value/100)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
总的来说,回答“如何正确设置策略?” 我建议以下建议:
label.new(bar_index,关闭,“ works”)
在那里,以确保可以在此处触发策略。stragity.entry('str1',strument.long)
或strategy.erter.order(...)
s/l/p等。 如果一切都很好,应该完全工作,在“策略声明”中,您可以根据您的职位和投标作用来定义默认逻辑。 Dexplantion> //www.tradingview.com/pine-script-reference/v5/#fun_strategy“ rel =“ nofollow noreferrer”>参数列表
如果您将订单放在脚本中,您实际上不必再关心这些。
在您的具体示例中:
stragity.entry()
和stragity.order.order()
是或多或少可以互换,具体取决于您想要实现的目标,例如strategy.exit()
and andstrategy.close.close()
(很棒的示例在您可以从中学习的链接中)。我最喜欢的是straging.order()
。stragity.entry()
在相反的方向上将关闭所有其他位置。 (所有长位置都将关闭,而“ QTY”的简短位置取而代之。)如果这是一个问题,则必须使用strategy.order.order.order()
而不是。策略。 close()
没有参数时。您的余额是stragity.equity
,您可以用来动态设置每个顺序上的QTY
参数。您不能以百分比定义SL。像描述这就是您重回正轨并处理策略所需的全部。
In general to answer "How to set up a Strategy properly?" I'd suggest the following:
label.new(bar_index, close, "works")
line in there to make sure your strategy could be triggered there.strategy.entry('str1', strategy.long)
orstrategy.order(...)
S/L/P etc. fancy stuff but first your strategy logic should work at allIn the strategy declaration you can define the default logic by that your positions and bids should work. Explanation Parameter list
If you place your orders in your script you actually don't have to take care about these anymore.
To your specific example:
strategy.entry()
andstrategy.order()
are more or less interchangeable depending what you want to achieve just likestrategy.exit()
andstrategy.close()
(great examples in the link that you can learn from). My favorite one isstrategy.order()
.strategy.entry()
in the opposite direction will close all other positions. (All long positions are going to be closed and "qty" short positions opened instead.) If that's a problem you have to go withstrategy.order()
instead.strategy.close()
does not have a when parameter. Your balance isstrategy.equity
that you can use to dynamically set theqty
parameter on each order. You cannot define your SL in percentage. Like the description says, it has to be either in price or tick.That's all you need to get back on track and work with your strategy.
lmk如果这有助于IDK,为什么我以前从未遇到这个问题。.在图片中,我所做的只是用float代表它
LMK if this helps idk why I haven't encountered this problem before.. In the picture, all I did was typify it with float