【问题标题】:How to enter a trade in an opposite direction after stoploss is triggered?如何在触发止损后反方向进场交易?
【发布时间】:2022-12-12 01:34:52
【问题描述】:

假设您进入多头头寸但价格下跌并触发止损,而不是仅仅关闭多头交易我希望脚本打开空头交易。我怎么做?我试过自己做,但我太笨了,所以这就是我想出的。

strategy.exit("Exit short", from_entry="short", stop=low * stoplossforSell)

接着

if strategy.position_entry_name=="Exit short"
     strategy.entry("long from short",strategy.long)

【问题讨论】:

    标签: pine-script pinescript-v5


    【解决方案1】:

    您需要在您的止损价位下一个空头限价单。

    下面是一个简单的示例,每当价格收盘高于 SMA 线时,它就会进入多头头寸。然后它以 5% 的价格放置止损退出订单。它还以相同的价格下了一个空头限价订单。

    //@version=5
    strategy("My script", overlay=true)
    
    sma_val = ta.sma(close, 20)
    long_cond = ta.crossover(close, sma_val)
    
    if (long_cond)
        strategy.entry("Long", strategy.long)
    
    long_sl_price = strategy.position_avg_price * (1 - 0.005)
    
    if (strategy.position_size > 0)
        strategy.exit("LE", "Long", stop=long_sl_price)
        strategy.entry("Short", strategy.short, stop=long_sl_price)
    
    plot(sma_val, color=color.blue)
    plot(long_sl_price, color=color.red)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-28
      • 2015-07-15
      • 1970-01-01
      • 1970-01-01
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多