[英]Strategy.entry if condition is satisfied only in the next bar
我正在制定一个策略,但我遇到了以下问题。
垂直的红线是做空的信号蜡烛
水平虚线是期望的入场价
我不想在信号栏上输入,所以我让 process_orders_on_close = false
如果在那里触发价格进入止损价格,我只想在下一个柱中进入交易,不想等待价格反弹前 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)
如果满足条件并且下一个柱上没有条目,您可以取消挂单。 只需使用strategy.cancel()
或strategy.cancel_all()
函数。 将此添加到脚本的末尾:
if shortCondition[1] and strategy.position_size == 0
strategy.cancel_all()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.