'Pinescript trade pause xx hours after wins

I want to apply a function to pause the strategy for xx hours or bars after win trade, how to do that? because my strategy is trending so there is always a period of trash time after big moves which I want to avoid, for example, pause for 24 hours after a win(correct trend) trade. thank you.



Solution 1:[1]

You might find this example suiting:

https://www.pinecoders.com/faq_and_code/#how-can-i-implement-a-time-delay-between-orders

Or this example:

Reopen closed trade after X seconds

//@version=5
strategy("strategy.closedtrades.exit_time Example 2")

// Strategy calls to emulate a single long trade at the first bar.
if bar_index == 0
    strategy.entry("Long", strategy.long)

reopenPositionAfter(timeSec) =>
    if strategy.closedtrades > 0
        if time - strategy.closedtrades.exit_time(strategy.closedtrades - 1) >= timeSec * 1000
            strategy.entry("Long", strategy.long)

// Reopen last closed position after 120 sec.                
reopenPositionAfter(120)

if ta.change(strategy.opentrades)
    strategy.exit("Long", stop = low * 0.9, profit = high * 2.5)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Starr Lucky