neeraj kumar
neeraj kumar

Reputation: 13

Exit position Pine Script

How can I exit or close a position on a specific time of exchange in Pine Script. Example I have long position and want to close it on or before 1500 hrs as per Indian Time Zone. Please help?

Upvotes: 1

Views: 194

Answers (1)

vitruvius
vitruvius

Reputation: 21342

You can use the time() function for that.

Here is an example where it marks candles between 1200 and 1500. It shouldn't be difficult to adapt according to your needs.

//@version=5
indicator("My Script", overlay=true)

timeAllowed = input.session("1200-1500", "Allowed hours")

// Check to see if we are in allowed hours using session info on all 7 days of the week.
timeIsAllowed = time(timeframe.period, timeAllowed + ":1234567")

plotchar(timeIsAllowed, size=size.small)

enter image description here

Upvotes: 1

Related Questions