Welcome to the BEST forum for traders

Did you know we're sharing tons of exclusive content here?
Our community is growing quickly. Take a look around and say "Hello".

  • Forums
  • Pinescript
  • Pine Script V5, How can i DELAY 5 seconds for my LONG & SHORT Entry?

Pine Script V5, How can i DELAY 5 seconds for my LONG & SHORT Entry?

Mar 8, 2022 - 12:49 PM

Viewed 6682 times

https://best-trading-indicator.com/community/bti/forums/4180/topics/56002 COPY
  • I want to delay 5 seconds for my LONG & SHORT entries.

    for example, if the longCondition is true at 12:00:00, I want to execute LONG entry at 12:00:05

    the same for Short entry: if the shortCondition is true at 12:00:00, I want to execute SHORT entry at 12:00:05

    Can anyone help me, please?

    ****** Code ******
    //@version=5
    strategy('My Strategy', overlay=true)

    // Indicators
    shortSMA = ta.sma(close, 10)
    longSMA = ta.sma(close, 30)
    rsi = ta.rsi(close, 14)

    // Conditions
    longCondition = ta.crossover(shortSMA, longSMA) and (rsi > 50)
    shortCondition = ta.crossunder(shortSMA, longSMA) and (rsi < 50)

    /// LONG
    strategy.entry(long, strategy.long, when=longCondition, comment=Entry Long) //## How can i delay 5 seconds for this entry ???
    strategy.close(long, when=shortCondition, comment = Exit Long)

    /// SHORT
    strategy.entry(short, strategy.short, when = shortCondition, comment=Entry Short) //## How can i delay 5 seconds for this entry ???
    strategy.close(short, when=longCondition, comment=Exit Short)

    0
  • Dave Dave (@davedave):
    Example here: https://www.tradingview.com/script/Tqq1lFCS-The-strategy-example-Close-position-by-timeout/ :)

    Thanks Bro~

    0
CONTENTS