Close Trade at end of day

script serves as an example how we can close trades at end of day.

can be session controlled or the time controlled.

the session should be adjusted to be earlier than the candle time.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Want to use this script on a chart?


After a lot of search, i finally got it from a fellow Indian trader. May you earn 10X this year.
+6 Svara
nice one sir
+4 Svara
When I tried this, its not working(not ending the the trade at the end of day), please guide if any changes required.
+3 Svara
ms30141 sudhakarreddyk
@sudhakarreddyk, I am not sure, but try changing your chart time resolution to 4-1 hour or even minute interval. It is not going to work with a day interval or lower time resolutions.
Thanks Brother for providing this :)
this code does't work in any time frame
daytraderph kankariyanitin
@kankariyanitin, you need to understand and tweek the code according to you need. for more you can refer below link of pine.
Thank you!
Great work. Works for me. Also, if we use minute time interval, then on line 95 and 98 we would write if ( hour(time) == 15 and minute(time) >= 59 )
Not working for me