Pinescript订单输入,停止损失并获利

发布于 2025-01-26 17:00:19 字数 460 浏览 3 评论 0原文

我只是要掌握Pinescript,更具体地编写了放置订单/交易的策略,但是有一个快速的问题。

我想创建一个基本的模板策略,该策略将进入交易,设置其停止损失并获利,这一切都开始。我对使用任何指标不感兴趣来设置这些值中的任何一个,所以我只想简单地设置:

  • 输入价格 = 当前价格 + 10pips
  • 停止损失 = entry_price -20pips
  • 获利 = entry_price + 60pips

我感谢这不是与我交易的有用策略我只是在使用此练习来更好地理解Pinescript,并且一旦我有一个可以执行上述脚本,我打算以此为基础,因此这将是一个巨大的帮助!

谢谢大家

I am just getting to grips with PineScript and more specifically writing strategies to place orders/trades however, have a quick question.

I want to create a basic template strategy that will enter a trade, set its stop loss and take profit, and that's all to begin with. I am not interested in using any indicators to set any of these values as yet, so I just wish to simply set:

  • Entry price = current price + 10pips
  • Stop loss = entry_price - 20pips
  • Take profit = entry_price + 60pips

I appreciate this isn't a useful strategy to trade with, I am just using this exercise to better understand PineScript and once I have a script that can execute the above I plan to then build on that, so this will be a huge help!

Thanks all

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

红焚 2025-02-02 17:00:19

您可以使用以下内容来获取PIP尺寸:

pip_size = syminfo.mintick * (syminfo.type == "forex" ? 10 : 1)

并使用它来获取入口价格:

entry_price = strategy.opentrades.entry_price(strategy.opentrades - 1)

然后:

tp = entry_price + (60 * pip_size)
sl = entry_price - (20 * pip_size)

然后退出职位:

if (strategy.position_size > 0)
    strategy.exit("exit", "long", stop=sl, limit=tp)

You can use the following to get the pip size:

pip_size = syminfo.mintick * (syminfo.type == "forex" ? 10 : 1)

And use this to get the entry price:

entry_price = strategy.opentrades.entry_price(strategy.opentrades - 1)

Then:

tp = entry_price + (60 * pip_size)
sl = entry_price - (20 * pip_size)

Then to exit a position:

if (strategy.position_size > 0)
    strategy.exit("exit", "long", stop=sl, limit=tp)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文