TradingView
melihtuna
2020年3月30日午後10時41分

Backward Number of Bars 

Binance Coin / TetherUSBinance

詳細

This indicator was written in order to apply bar limit in strategies and it was published as open code so that everyone can use it. When backtesting with stock market api data, we determine how many bars should be, not from which date the data will be drawn. For example, we can draw 1000 bar data from stock exchange and perform the backtest on this data. You can plan your strategy by checking the number of bars you test with the window () == 1 parameter here while checking through Tradingview to check that the test we performed gives correct results.



コメント
PineCoders
CT-Signals
Can anyone explain/correct why this won't work on a 1 minute chart? I'm need a script that will change the background (whether the "background" is the background function, histogram etc.) for the most recent 5 bars on a 1 minute chart. I'm having a heck of a time figuring out how to script it!! 'any help would be MUCH appreciated!! this script works on the H1 and D1, but not on the smaller time frames for some reason....
amethyst1478
@CT-Signals,
Try x = timeframe.multiplier * (timeframe.isdaily? _MILLISECONDS_IN_DAY : timeframe.isweekly? _MILLISECONDS_IN_WEEK : timeframe.ismonthly? _MILLISECONDS_IN_MONTH : _MILLISECONDS_IN_MINUTE)

timeframe.multiplier should encompass the whole thing because it could refer to, e.g. "5" days or "60" minutes
amethyst1478
backTestFromDate is in UNIX time. timestamp generates UNIX time. So why go through the whole exercise of generating all of the timestamp elements?

I think this whole script could be minified to something like:

BacktestBarCount = input(50)
MsPerBar = timeframe.multiplier * (timeframe.isminutes? 60*1000 : timeframe.isdaily? 24*60*60*1000 : timeframe.isweekly? 7*24*60*60*1000 : timeframe.ismonthly? 30*24*60*60*1000 : 1000)
StartTime = timenow - (BacktestBarCount * MsPerBar)
window() => time >= StartTime? 1:0
plot(window(), color=color.blue)
mrdanielkuo
@amethyst1478 I've tried your script but in some reason it still only works for daily chart, not on 1 minute or 5 minute chart. Can you help? Thank you
@CT-Signals Does it work for you?
kurtsmock
1,000 thank yous! This was breaking my brain. had like 12 ideas and I couldn't get any of them to work as good as this. lol. You win my friend! thanks for sharing!
CryptoKick
Hi @melihtuna - this is the method I've used in the past as well. The problem I run into is that it only works for instruments that trade 24/7. I've been racking my brain trying to come up with a method to accomplish the same thing for things like traditional equities (with or without extended sessions) and have gotten SO close a few times, but nothing perfected yet. Do you have any ideas? I'd be happy to share the "dead-ends" I've already attempted.
LucF
Very ingenious! Congrats.
melihtuna
@LucF, thx :)
詳細