如何正确制定策略? V5

发布于 2025-01-26 04:28:22 字数 1735 浏览 2 评论 0原文

作为初学者,我仍然感到困惑。对于我来说,太多的问题对我来说是迷宫,对不起,也许是直率的问题……

这是标题:

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_typedefault_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() or strategy.exit() function (above), it seems we
    can only specify quantity, independently from the default_qty_value variable (if I don't specify qty then it results an error message),
  • and there's not even such variables as default_qty_type or default_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

闻呓 2025-02-02 04:28:22

总的来说,回答“如何正确设置策略?” 我建议以下建议:

  1. 将您的策略​​设置保持在最低限度上。花哨的东西,但首先您的策略逻辑应该完全
  2. 检查您的触发条件是否有效。放置只有label.new(bar_index,关闭,“ works”)在那里,以确保可以在此处触发策略。
  3. 然后下订单。 Just stragity.entry('str1',strument.long)strategy.erter.order(...) s/l/p等。 如果一切都很好,应该完全工作,
  4. 您可以逐步完善它并添加所有额外的功能。

在“策略声明”中,您可以根据您的职位和投标作用来定义默认逻辑。 Dexplantion> //www.tradingview.com/pine-script-reference/v5/#fun_strategy“ rel =“ nofollow noreferrer”>参数列表
如果您将订单放在脚本中,您实际上不必再关心这些。

在您的具体示例中:stragity.entry()stragity.order.order()或多或少可以互换,具体取决于您想要实现的目标,例如strategy.exit() and and strategy.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:

  1. Keep your strategy settings like concerning initial_capital to a minimum. Fancy stuff but first your strategy logic should work at all
  2. Check if your trigger condition works. Place eg. just a label.new(bar_index, close, "works")line in there to make sure your strategy could be triggered there.
  3. Then place a simple order. Just strategy.entry('str1', strategy.long) or strategy.order(...) S/L/P etc. fancy stuff but first your strategy logic should work at all
  4. If everything is fine you can refine it step-by-step and add all the extra features.

In 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() and strategy.order() are more or less interchangeable depending what you want to achieve just like strategy.exit()and strategy.close() (great examples in the link that you can learn from). My favorite one is strategy.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 with strategy.order() instead.
strategy.close()does not have a when parameter. Your balance is strategy.equity that you can use to dynamically set the qty 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.

情深缘浅 2025-02-02 04:28:22

lmk如果这有助于IDK,为什么我以前从未遇到这个问题。.在图片中,我所做的只是用float代表它

Pick

LMK if this helps idk why I haven't encountered this problem before.. In the picture, all I did was typify it with float

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文