This requires the use of the security() function, which in Pine Script is used like this:Figure 3.
Pine Script security functionThis function will need a symbol (including an exchange) like the following: “BINANCE:BTCUSDT”, so it will know where to pull the data from.
If you want to pull data from chart you’re looking at, just use tickerid.
Then it looks at the resolution, which is the timeframe, for the 15 minute chart this is “15”, for the 4 hour chart it’s “240” and for the daily chart it’s “D”.
If you want to pull data from the timeframe you’re looking at, you enter period.
The expression it needs is the data type, which I just discussed.
gaps and lookahead are more advanced parameters of this function, which are by default set to off and most of you are better off for it.
If you want to play around with these settings, you should check this link.
If I’m looking at a 15 minute Bitcoin chart and i want to see the daily data, I will need to code the following:Figure 4.
Different timeframe selection.
Result of different timeframe selectionThis worked perfectly, but it would still be nice to turn this into a more dynamic piece of code, so you can edit the values through a menu.
I would like a selection of resolutions and expressions to choose from.
Dynamic timeframe and data selectionThe results from this code above is exactly the same as in Figure 5, so let’s a bit to give it more functionality.
What if you don’t want to see all four plots?.You should be able to switch them off.
We do this by creating an option in the menu for each plot and altering the lines with plot function.
You do this by using a language operator.
Language operatorYou should read this as following: If ‘expr1' is, it will execute ‘expr2’.
If not, then it will execute ‘expr3’.
Without this making much sense in a grammatical way, it does show the opportunity for using this as a switch.
Let me show you how this looks in code, it makes more sense in my opinion.
Language operator codedYou can see that I added a showPlot variable for each line, which can be set to true or false.
Then, in the plot codes, I added the language operator which now reads a lot better: If showPlot is true, then show Data or else (false) do nothing (na).
In the menu it looks like this:Figure 9.
A dynamic data selection menuSo, now i can plot one line (by turning 3 of them off) with a lesser used data type of my selection, HLC3 in this instance, which stands for (high + low + close) / 3, on a daily timeframe.
HLC3 `data type on daily timeframeExotic data inputsExperimenting with data types makes your bot more versatile and sometimes it definitely makes more sense to use one instead of the other.
What would happen if you choose to use very different inputs to use in your calculations?.What about using OBV as the calculations for Bollinger Bands?Extra DimensionsIf playing with data types makes your bot more versatile, then playing with timeframes opens a door to new dimensions for your bot, by being able to give it instructions such as:Only buy/long when the daily close is above the SMA200 and the RSI is leaving oversold conditions on the 1 hour timeframeDo not sell/short when the 4 hour close is above the Ichimoku Tenkan-sen and 30 minute OBV is still risingDo not execute a buy/long or sell/short at all when the daily Bitcoin ATR (volatility) is below 4%.
These are just examples, but demonstrate the newfound abilities.
I hope this piece will help you in trying out a lot of combinations, i have no doubt there is winner in there, thanks for reading!You can follow me on Twitter, where you can also find the link to my bot which shares it’s calls for free on Telegram!.Im also on TradingView, where you can see and use my scripts.
.. More details