【问题标题】:How limit the number of strategy entries (Consequence entries) to a specific condition?如何将策略条目(结果条目)的数量限制为特定条件?
【发布时间】:2021-07-25 22:45:23
【问题描述】:

我试图在初始订单之后限制额外的条目,直到满足关闭条件(所以在初始订单填写和 TP/SL 达到后,在关闭条件发生之前不允许其他条目,只有这样才能再次允许新条目) Pyramidingstrategy.risk.max_intraday_filled_orders() 没有解决我的问题, 下面是我的代码

strategy(title='EMA Cross', overlay=true)


tp_inp          = input(defval = 2.0, title='Take Profit %', type=input.float)/100
sl_inp          = input(defval = 2.0, title='Stop Loss %'  , type=input.float)/100
tp_inp_val = (1 + tp_inp)
sl_inp_val = (1 - sl_inp)
price = na(strategy.position_avg_price) ? close : strategy.position_avg_price
take_level = price * tp_inp_val
stop_level = price * sl_inp_val
useTake_level   = tp_inp         <= 1 and tp_inp != 0 ? take_level : na
useStop_level   = sl_inp         <= 1 and sl_inp != 0 ? stop_level : na
plot(strategy.position_size > 0 ? useTake_level : na, color=color.green, style=plot.style_linebr, linewidth=2) // plot TP
plot(strategy.position_size > 0 ? useStop_level : na, color=color.red  , style=plot.style_linebr, linewidth=2) // plot SL

ema20  = ema(close, 20)
ema100 = ema(close, 100)

plot(ema20 , color = color.orange)
plot(ema100, color = color.blue  )

entry_allowed = true
if ema100 > ema20
    entry_allowed := true

if ema20>ema100
    strategy.entry("Buy", strategy.long, when = ema20>ema100)
    entry_allowed := false
strategy.close("Buy", when = ema100 > ema20 )
strategy.exit("Exit Buy",  limit = useTake_level, stop=useStop_level) ```

【问题讨论】:

    标签: pine-script algorithmic-trading


    【解决方案1】:

    试试这个:

    var entry_allowed = true
    
    if (ema20>ema100) and entry_allowed
        strategy.entry("Buy", strategy.long)
        entry_allowed := false
        
    if (ema100 > ema20) 
        strategy.close("Buy")
        entry_allowed := true
    
    strategy.exit("Exit Buy",  limit = useTake_level, stop=useStop_level)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-29
      • 2018-02-10
      • 2011-11-06
      • 2012-08-20
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2021-01-06
      相关资源
      最近更新 更多