kaleboraciy

How to detect last bar of day

1175 visningar
45
Simple way how to detect last bar of day and close all positions

UPD: day end can be different for yours because stocks market use another timezone
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?

Kommentarer

cool stuff mate, thanks!
Svara
I needed something a little different, but this snippet pointed me into the right direction, thanks!

What I was looking for was to detect the candle previous to the last.
last_bar = timenow - time_close < 1000 * 60 * 60 * 24
Svara
kaleboraciy yalla-yalla-habibi
Svara
UPD: if you use strategy.close so it closes on open of new day

del = time_close - time_close
last_bar = timestamp(year, month, dayofmonth + 1, 0, 0, 0) == time_close + del
strategy.close(id, when = last_bar)

this code closes on open last bar
Svara
Hem Aktie-screener Forex-screener Krypto-screener Ekonomisk kalender Om Diagramfunktioner Priser Tipsa en vän Ordningsregler Hjälpcenter Webbsidor och mäklarlösningar Widgets Diagramlösningar Lightweight Charting Library Blogg och nyheter Twitter