TradingView
LonesomeTheBlue
2 de Nov de 2020 09:24

Start the Script on Last Nth Bar [Experimental] 

International Business Machines CorporationNYSE

Descrição

Hello Pine Scripters,

Sometimes we need to run some processes in the scripts on last N bar but currently we don't know bar_index value of realtime bar or number of remaining bars before we reached it. So most of us use "start date" as input and run some processes after "start date".

This experimental script finds last Nth bar approximately. As you can see in the script we (should) use GMT, otherwise as I see the result might not be accurate (we don't know timezone used on the chart)

The idea is to find/use similar bar in the past (using timenow as reference) and then calculate aproximate the time of last Nth bar. the results may not be accurate all the time, also we can not know local holidays etc.

At the moment the script works on 1minute or higher time frames (it won't work on less 1min timeframes)

In the future if the Pine Team add something like "bar_index_realtime" then we will not need such things. by the way many thanks to Pine Team, they are doing great job.

You can use this script in your scripts as you want, no need to ask permission. If you can improve it let me know ;)


Enjoy!

Notas de Lançamento

Comentários
Pratik_4Clover
Wow, that should reduce some unnecessary computing power usage. Thanks!
LonesomeTheBlue
@Pratik_4Clover, yes absolutely ;)
kurtsmock
This is fantastic. I have some work arounds for this problem as well. We have to ask ourselves. Does it really need to be this hard? Answer so far. Yes. No way around it. haha. Great work though. I love reading your code.
Deadca7
I'm not sure what to do with this script. Do I just paste it at the beginning of my scripts? thank you
JoshuaMcGowan
really enjoy the ideas you put out. lots of value here. cheers bru
kvramana12
Great job sir
I always admire your hard work
LonesomeTheBlue
@kvramana12, thank you. I know this will be helpful for many scripters as there is no other solution at the moment.
anilhavuc
Super, super. Tebrikler...
andresdrb
Great script but I found it breaks on some scenarios. It doesn't really work if the historic data available for the symbol is less than the prd parameter
mccshuka
@andresdrb, yea that's a problem:(
Mais