策略。输入如果仅在下一个栏中满足条件

发布于 2025-02-12 23:50:17 字数 1336 浏览 1 评论 0原文

我正在制定策略,并且有以下问题。

  • 垂直红线是进入短

    的信号蜡烛
  • 水平虚线的信号蜡烛是所需的入口价格

  • 我不想在信号栏上输入,所以我让Process_orders_on_close = false

  • 我只想在下一个bar中输入贸易,如果价格输入停止价格在那里触发,不想等到价格才能集会5条然后击中我的条目

//@version=5
strategy("str demo", "str demo", overlay=true)

var float desired_entry_price = 0.0
var float entry_low = 0.0
var float entry_high = 0.0
var float c_entry_range = 0.0
var float position_avg_price = 0.0

shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))

if shortCondition and strategy.position_size == 0
    line.new(bar_index, close, bar_index, close + 1, xloc.bar_index, extend.both, color=color.new(color.red, 70)  ) //vertical line
 
if shortCondition and strategy.position_size == 0
    entry_low  := low
    entry_high := high
    c_entry_range := entry_high - entry_low
    desired_entry_price := entry_low - 10 * syminfo.mintick
    
    strategy.entry("es", strategy.short, qty = 10, stop = desired_entry_price )

position_avg_price := strategy.position_avg_price
s_sl1 = entry_high
s_tp1 = entry_low - (c_entry_range * 2.5)

plot(desired_entry_price, style=plot.style_circles, color=color.new(color.red, 0) )

if strategy.position_size < 0  
    strategy.exit("x1", "es", qty_percent = 100, limit = s_tp1, stop = s_sl1)

I work on a strategy and i have the following problem.

  • vertical red line is the signal candle to enter short

  • horizontal dotted line is the desired entry price

  • i do not want to enter on the signal bar, so i let process_orders_on_close = false

  • i want to enter in trade only in the next bar if price entry stop price is triggered there, do not want to wait for price to rally ex 5 bars then hit my entry

example on chart

//@version=5
strategy("str demo", "str demo", overlay=true)

var float desired_entry_price = 0.0
var float entry_low = 0.0
var float entry_high = 0.0
var float c_entry_range = 0.0
var float position_avg_price = 0.0

shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))

if shortCondition and strategy.position_size == 0
    line.new(bar_index, close, bar_index, close + 1, xloc.bar_index, extend.both, color=color.new(color.red, 70)  ) //vertical line
 
if shortCondition and strategy.position_size == 0
    entry_low  := low
    entry_high := high
    c_entry_range := entry_high - entry_low
    desired_entry_price := entry_low - 10 * syminfo.mintick
    
    strategy.entry("es", strategy.short, qty = 10, stop = desired_entry_price )

position_avg_price := strategy.position_avg_price
s_sl1 = entry_high
s_tp1 = entry_low - (c_entry_range * 2.5)

plot(desired_entry_price, style=plot.style_circles, color=color.new(color.red, 0) )

if strategy.position_size < 0  
    strategy.exit("x1", "es", qty_percent = 100, limit = s_tp1, stop = s_sl1)

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

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

发布评论

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

评论(1

七禾 2025-02-19 23:50:17

如果满足条件并且在下一个条上没有条目,则可以取消待定订单。
只需使用straging.cancel()straging.cancel_all()函数。将其添加到脚本的末尾:

if shortCondition[1] and strategy.position_size == 0 
    strategy.cancel_all()

You can cancel pending orders if the condition is met and there was no entry on the next bar.
Just use strategy.cancel() or strategy.cancel_all() function. Add this to the end of your script:

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