如何将策略变成不重新粉刷的标签

发布于 2025-01-23 07:35:12 字数 572 浏览 1 评论 0原文

我有一个策略,该策略一次只能在每个方向上进行一次交易,但是我想将其变成带有图形标签标签的指标。当我的购买或出售参数连续击中不止一次时,我尝试使用变量增加的每种方法都无法关闭标签,直到相反的信号出现。多次我希望它发出一个信号,然后关闭直到满足相对的交易参数。因此,一个购买信号,然后是一个卖出信号,中间没有无关的信号。我该如何实现?

//Strategy Trade Signal Bull
if bull
    strategy.entry('Bull', strategy.long, comment='Bull')
    strategy.close('Bull', when=bear, comment='Bear')

//Strategy Trade Signal Bear
if bear
    strategy.entry('Bear', strategy.short, comment='Bear')
    strategy.close('Bear', when=bull, comment='Bull')

I have a strategy built that only takes one trade in each direction at a time, but I'd like to turn it into just an indicator with labels using plotshape. Every method I have tried to use a variable increase when my buy or sell parameter hits more than once in a row, doesn't work to turn the labels off until the opposite signal comes in. So basically it is repainting a buy or sell signal multiple times when I want it to give one signal and then shut off until the opposite trade parameters are met. So one buy signal, then one sell signal, no irrelevant signals in the middle. How can I achieve this?

//Strategy Trade Signal Bull
if bull
    strategy.entry('Bull', strategy.long, comment='Bull')
    strategy.close('Bull', when=bear, comment='Bear')

//Strategy Trade Signal Bear
if bear
    strategy.entry('Bear', strategy.short, comment='Bear')
    strategy.close('Bear', when=bull, comment='Bull')

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

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

发布评论

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

评论(1

给我一枪 2025-01-30 07:35:12

您需要一个变量才能查看是否已经很长。

这应该给你一个想法:

var is_long = false

is_buy = barstate.isconfirmed and not is_long and bull  // Buy only if we are not already in a long position
is_sell = barstate.isconfirmed and is_long and bear  // Sell only if we are in a long position
is_long := is_buy ? true : is_sell ? false : is_long

You need a variable to see if you are already long.

This should give you an idea:

var is_long = false

is_buy = barstate.isconfirmed and not is_long and bull  // Buy only if we are not already in a long position
is_sell = barstate.isconfirmed and is_long and bear  // Sell only if we are in a long position
is_long := is_buy ? true : is_sell ? false : is_long
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文