Volume [Educational]Hello All,
This is an educational work and it's developed to show how to write scripts that will work like built-in volume indicator.
We have new features in Pine Script™ Language, such chart.bg_color, chart.fg_color, chart.left_visible_bar_time, chart.right_visible_bar_time and many more. Many Thanks to Tradingview and Pine Team for such great additions!
You can find more information about these new functions here .
How the script works?
- At the first step it calculates how many visible bar on the chart by using chart.right_visible_bar_time and chart.left_visible_bar_time functions.
- Calculates the zero line for the volume
- Finds maximum volume on visible area and normalize all volume values
- Draws volume bars
- Shows volume info as indicator value. in this step it uses chart.fg_color and plotarrow() commands to show the values in optimum color.
In order to place the indicator at the bottom of the chart, Please set Bottom Margin = 0 as shown in the following screenshot:
You can change the volume bar colors optionally.
An Example screenshot with different volume bar colors:
Enjoy!
Builtin
Learning Built-in VarsI'm currently working on v5 of my Pine Script Programming Course.
As a part of it, I'm building a few tools/widgets to help students get the content easier.
Here is one of the tools. It's quite basic with it you can select a bar and see all the build-in variables for this bar (Except strategy variables)
I hope it will help you in learning Pine Script!
Disclaimer
Please remember that past performance may not be indicative of future results.
Due to various factors, including changing market conditions, the strategy may no longer perform as well as in historical backtesting.
This post and the script don’t provide any financial advice.
GMS: GW-VWAPAlright, as per usual with these, I end up adapting an existing indicator to what I want to accomplish. So this is based off the built in VWAP indicator. I added in the gummy worm to easily identify the trend, as well as the related bands to identify potential areas to either reverse position or to trim an existing one.
The middle part of the bands are the gummy worm version of VWAP. It is the VWAP using the high and another VWAP using the low. The black line is HL2 VWAP (technically 3 VWAPs).
The bands follow what I was mentioning above. So the outer most part of the bands are the high & low VWAP (with the same multiplier) and the inner bands are the HL2 VWAP.
Of course you can set whatever input source you want for these. The default is how I use it. If you want to get rid of the bar color just go to the indicator settings and un-select it at the bottom.
Source code is open so feel free to poke around.
Hope this helps,
Andre
Bollinger Band Color BarsThis is a simple addition to the built in Bollinger Bands script. All it does is replaces the traditional plotting of Bollinger Bands with color bars.
Combined Candlestick PatternsI combined all the build-in candlestick patterns scripts into one single script so anyone who does not have a Pro plan can display all the patterns in the same chart.
Leave a comment for any feedback!
[RESEARCH] Mean Absolute DeviationHello traders and developers!
I was wondering how built-in "dev" function in Pine is calculated so I made a little research.
I examined 7 samples:
0) "dev" function itself
1) "dev" according to its description: series - sma(series)
2) Mean Absolute Deviation
3) ratio of the absolute difference from 1) divided by period
4) ratio of the difference from 1) divided by period
5) Median Absolute Deviation
6) tricky for-loop to calculate Mean Absolute Deviation
The results of the null and sixth samples are identical.
So, TV built-in "dev" function represents Mean Absolute Deviation and it's description is incorrect.
Where it is used? For example: Commodity Channel Index. You can check its original formula and if you used simple standard deviation instead of MAD in your CCIs - well guys, you were wrong.
Good luck!
[RESEARCH] Rate of ChangeHello traders and developers!
I was wondering how built-in "roc" function in Pine is defined and calculated so I made a little research.
I examined 4 samples:
1) "roc" function itself
2) "roc" according to its description
3) price change ratio
4) price percent change ratio
The results of the first and fourth samples are identical.
So, TV built-in roc(source, length) = 100 * change(source, length) / source .
And it's description is incorrect.
If you didnt know it - now you know it.
Good luck!