Marvin White
Marvin White

Reputation: 11

Pine Script strategy to trigger once per day?

Need help coding Pine Script v5 strategy to trigger once per day?
Would like to use "bar_index == 0", but do not know how to establish when the bar index re-starts at the beginning of the trading day. Please help!

Upvotes: 1

Views: 2037

Answers (3)

N. Josh
N. Josh

Reputation: 33

Simple, use function

strategy.risk.max_intraday_filled_orders(count=2)

count 2 means, one for Entry order and second for Exit order

Upvotes: 0

Marzo Buffon
Marzo Buffon

Reputation: 39

I'm sure there is a better way, but this worked for me:

var traded_today = false

//use whatever hours:days for first candle of time series chart
//using 15min here, but can be done using an input()
first_candle = time(timeframe.period, "9:30-9:15:23456"

if (first_candle)
    traded_today := false
    
condition = your_condition and not traded_today

if (condition)
    traded_today := true 

Upvotes: 0

Dave
Dave

Reputation: 865

Solution: https://www.tradingview.com/pine-script-reference/v5/#fun_timeframe{dot}change

The below tests if it's a new day

if timeframe.change("D")
    ...

Upvotes: 0

Related Questions