馃攳
Tulip Indicators - A library to calculate technical indicators like RSI,MACD etc. - YouTube
Channel: unknown
[1]
Today we鈥檙e going to talk about tulip indicators.
[3]
It is a library that allows you to calculate
technical indicators like RSI, MACD,(EMA OR
[9]
BOLLINGER BANDS) and all that and the good
thing about this (wrapper) is that you don鈥檛
[14]
have to know about the underlying math behind
each of these indicators, so it offers you
[18]
(wrappers) or in-built functions that you
can leverage to automatically calculate values
[23]
for a particular indicator.
[24]
let鈥檚 get started.
[27]
Before we begin, here are some prerequisites.
[29]
you need to have NodeJS installed on your
machine and you should also have a basic understanding
[34]
of javascript programming.
[36]
this picture illustrates what the library
does, so you would pass in the candlestick
[40]
data on one end and you would receive the
corresponding indicator value on the other
[45]
end.
[46]
so this library serves like a black box obfuscating
the underlying math and giving us functions
[53]
to automatically calculate the indicator values.
[57]
This is the node package URL for this library
and this is the command to install this package
[62]
in your project, so just copy that and goto
your project and hit right click to paste
[66]
the command and hit enter.
[68]
It will take a couple of minutes to install.
[72]
that's it, installation is done.
[73]
Enter cls to clear screen.
[75]
This is the GitHub link for this library.
[77]
You can find the documentation for all the
commands over here.
[81]
Now that we've installed the package, let's
get started with demo.I鈥檓 going to create
[85]
a new file called demo.js.
[88]
I'm going to import the library first.
[91]
I鈥檓 also going to create a reference for
console log so that I can reuse the command
[100]
every time.
[106]
1st in order to see the version of the library,
you can log tulind.version.
[114]
(if you run it), you can see the version is
0.8.4.
[126]
Now in order to see the list of indicators
supported by this library, we can say log
[130]
tulind.indicators.
[135]
let me comment the previous statement and
let鈥檚 run it again.
[141]
You can see that we get a list of we get an
array with the list of indicators supported
[146]
by this library.
[147]
you can see volume weighted moving average
and Williams accumulation.
[150]
so you can support quite a bit of indicators.
[154]
inorder to see the documentation for a particular
indicator to see you know what parameters
[162]
are needed and how to use the function you
can say log tulind.indicators.
[169]
So let's take RSI in this case.
[172]
So, if i hit RSI and if i run it, you can
see that you can see the required documentation
[179]
for this particular indicator.
[180]
you can see that it has 1 input 1 output and
here we get the data type for each for the
[186]
input and the output.
[188]
without any further ado let's get started
with RSI indicator.
[191]
So I鈥檓 going to create a new file.
[192]
I鈥檓 just going to clone this for now.
[197]
Ok.
[201]
Now in order to calculate indicators I need
candlestick data.
[205]
so to do that i'm going to use this API that
returns the last thousand candles of BTCUSDT
[213]
on the one minute time frame.
[214]
so i鈥檓 going to use this data to perform
the analysis.
[216]
so, i鈥檒l just copy this.
[218]
i鈥檓 going to create a new file called data.JS
and module.exports.data is equal to these
[228]
values and save it.
[232]
now let鈥檚 import.
[233]
let鈥檚 (comment) this out.
[235]
now let鈥檚 import the data over here and
if you look at the documentation, we need
[243]
to pass the closing price low, high, and open
price in the form of an array in the chronological
[249]
order from the oldest to the newest.
[251]
so it should be in ascending order and it
should be in ascending chronological order.
[255]
so, let's extract this information from the
data that we just copied and if you look at
[262]
the documentation for the candlestick data,
you can see that this is how the data is organised.
[268]
so in order to get the closing price, you
can say require data.data.map d[].
[277]
so the fourth element is the closing price,
we鈥檒l say d[4] and let鈥檚 duplicate these.
[289]
We need open, high, low, and close.
[296]
so, open price is 1, high is 2, low is 3,
and close is 4.
[305]
that鈥檚 it.
[307]
So, we now have an array of all the price
points of all candlesticks.
[316]
Now in order to calculate the RSI value for
this candlestick Series all you have to do
[320]
is say tulind.indicators.rsi.indicator and
this takes in three parameters.
[329]
first one is the input and I'm going to use
the closing price to calculate the RSI. so
[334]
I pass the close array and then I'm going
to specify the length of the RSI. if you look
[339]
at the documentation, we can see we have to
specify the period.
[342]
so i'm going to put the length as 14 and then
we are going to pass another function which
[346]
is an asynchronous function that gets called,
once the candlestick are processed.
[350]
so, it has two parameters: error and result.
[353]
so, if there is any error, we鈥檙e just going
to return that and if there is no error we鈥檙e
[361]
just going to log the response.
[364]
let鈥檚 run it.
[369]
you can see that we got the RSI values for
the given candlesticks series and this is
[375]
also sorted in chronological order and to
get the latest one, we have to look at the
[381]
last item in these arrays.
[382]
so, we get slice (- 1)[0].
[384]
so, this returns the last element which is
the current which is the RSI value for the
[390]
current candle.
[391]
so, if i run it again, you can see that the
RSI value for the current candle is 55.92.
[397]
so, it is as simple as that.
[400]
so, you pause the candlestick series and you
specify the parameters and we get the response
[405]
back in the form of the result in the form
of this function.
[409]
now, let us look at this simple moving average.
[413]
so, i鈥檓 just going to clone this.
[415]
call it SMA and everything is going to be
the same.
[421]
first let me just comment this out and let鈥檚
look at the documentation for SMA indicators.
[426]
So, i鈥檒l just copy this and paste it here.
[431]
we call it SMA and let鈥檚 run this node SMA.
you can see that I can pass the closing price
[440]
open price whatever series i want and it only
has one parameter which is the period which
[445]
is the length of the moving average and we
get the response back in the form of an array
[449]
which is the moving average.
[450]
So..so, let鈥檚 do that.
[452]
I'll comment this out And i'll uncomment on
this.
[456]
Instead of RSI we get SMA and close let鈥檚
get SMA 200 ok and ya everything remains the
[465]
same.
[466]
so if I just run it.
[472]
so this is the simple moving average, the
last simple moving average and if you want
[475]
the if you want the entire series, then you
just have to, instead of looking at the last
[483]
element just look at the entire value, entire
array, sorry oh sorry.
[492]
just close this hha..yup. so, we get the entire
series with moving average so if you have
[503]
any if you have a requirement to plot these
values on some charts, you can use the series
[509]
as it is.
[510]
Ok so,That's how you calculate a simple moving
average.
[513]
Now, We can do something similar for exponential
moving average as well.
[517]
So i鈥檒l just clone it and I'll call EMA
and I think the parameters are going to be
[523]
the same.
[524]
so i鈥檒l just pass EMA instead of SMA and
let鈥檚 get 21 period moving average.
[527]
so i'll just pass 21 and if i just run this
command, you can see we got the moving - exponential
[534]
moving average instead of simple moving average
for the given series.
[538]
so,it is as simple as that now let's take
a slightly Complex scenario where we have
[543]
two results instead of one result.
[545]
so let鈥檚 just look at MACd moving averages,
convergence, divergence.
[554]
so let me comment this out and let鈥檚 look
at the parameters for MACd first.
[561]
If I log it, you can see, we only have one
input which is the series open, close or whatever
[569]
it is and then we have three parameters which
is a short period, long period, and the signal
[574]
period and then we get the result back in
3 arrays.
[579]
So, the first one is the MACd, the second
one is the MACd_signal, and third one is the
[584]
MACd_histogram.
[585]
So let me open a tradingview and show you
exactly what these values are.
[588]
all right.
[589]
I have added MACd indicator over this chart
and you can see that the MACd plot has 3 price
[594]
points: the blue line, the orange line, and
also the histogram.
[599]
So these are the three results that this function
Returns so that we can plot the values for
[605]
each individual one of them and you have to
pass the short period.
[609]
These are the three parameters.
[610]
You just double click on this.
[611]
you get to see all the parameters.
[612]
you can see the fast length, slow length and
source is close.
[616]
Source, we are anyways passing as the input
parameter, so that鈥檚 why it's not listed
[619]
here and then we have the signals smoothening
(smoothing), which is a signal period.
[624]
so let's try to calculate that.
[627]
So, I'll just comment this out and i鈥檒l
uncomment this.
[632]
So, instead of EMA, we would have MACd and
the closing price and three lengths, so, i'll
[639]
just take this same length-12 26 & 9.
[642]
Let's copy that 12 26 & 9.
[644]
I guess, these are the default values and
in the response we have three arrays.
[650]
so if I look at the response.length if I lock
response.length, you should see a value of
[656]
3.
[657]
let's see that.
[658]
You can see the value of 3.
[660]
It returns 3 arrays.
[661]
So, if i just log the entire response, you
can see it returns values in the form of 3
[669]
arrays.
[670]
It鈥檚 not really visible on the command prompt,
so i鈥檒l try to run it on in debug mode to
[676]
show you exactly the values look like.
[678]
So i鈥檒l just add an additional log statement,
so that I can put a breakpoint here.
[683]
All right.
[686]
So, i鈥檒l just keep it here and run it.
[692]
Ok if i Look at the response, you can see
there are this array has three different arrays
[696]
inside it.
[697]
so, the first one is the MACd, and the second
one is the (fast) the Slow length, the fast
[703]
length and the third one is the histogram
length.
[705]
So, you know now that you have these values
at your disposal you can perform any kind
[710]
of analysis that you want.
[712]
you can use for plotting charts or for performing
some kind of you know background analysis.
[717]
So, it鈥檚 as simple as that and finally let鈥檚
just look at one last indicator which is parabolic
[725]
Sar. so, i鈥檒l just duplicate this one and
i鈥檒l call it as psar.
[732]
Let me comment this out and let鈥檚 look at
the documentation for Psar which is parabolic
[739]
sar. node. ok, you can see parabolic sar has
two Inputs, which is the high series and low
[748]
series and then it takes into parameters two
options.
[753]
One is accelerating factor step and acceleration
factor maximum.
[757]
So, on tradingview chart let me remove all
the indicators and let's add psar(psar) parabolic
[767]
sar. ya and let's look at the parameters options
for it.
[777]
So you have the start increment and max value.
[779]
so we'll just put 0.02 to 0.2 and run this
.
[789]
Indicators psar and here we pass.
[792]
What do we pass?
[793]
high and low.
[795]
so high and low.
[797]
Note that we already have the high low and
open and close series extracted at the beginning.
[802]
So, we鈥檒l just pass the high and low arrays
and then we have to pass 2 additional parameters
[808]
here which is 0.002 and 0.02 and 0.2 and then
we get the response in the form of ya response
[816]
is just, output is just 1 array.
[819]
So, if i log response.length we should only
see one value.
[824]
let's see that.
[825]
Node psar. you can see the value is just one
and just comment this out and If you want
[832]
to look at the last value 80 size -1 in the
last element of the array let's log it again
[836]
value is the last value for the last value
so just look at response(0).slice (-1).
[840]
I鈥檓 just picking up the last element of
the array.
[842]
So, ill just comment this out and let鈥檚
log it again.
[850]
Yup so this is the value.
[851]
This is the last parabolic psar value for
the last candle.
[855]
So, that's it.
[856]
I wanted to cover simple indicators like a
RSI and moving averages and I also wanted
[861]
to cover Complex indicators like MACd and
Psar which requires multiple inputs multiple
[866]
outputs.
[868]
so that you get a gist of how to you use the
library as a whole and I also created separate
[873]
files so that when you download the code from
GitHub which i鈥檓 going to leave the link
[877]
in the description box.
[879]
it's easier for you to look at the code and
implement this in your project.
[883]
so I hope you found this useful and just leave
your thoughts and suggestions in the comments
[887]
section.
[888]
I鈥檒l talk to you guys very soon.
Most Recent Videos:
You can go back to the homepage right here: Homepage





