Showing posts with label in. Show all posts
Showing posts with label in. Show all posts

Sunday, 20 October 2024

Pine Scripters Network • Join Our PINE SCRIPT COMMUNITY!

hi traders in this video i'm excited to introduce you to the pine scriptures network the pine scriptures network is a new online forum i've set up and it's intended to be a community where pine scriptures such as yourself can communicate with each other share your scripts share your code and help each other with your own scripts and today i just want to introduce you to the website show you how to sign up and give you an idea of what to expect so if you go to pinescripters.net that will bring you to this page here and there's not a lot happening here yet because i'm the only user of this website but hopefully soon we'll have a bunch of active members here helping each other out with their scripts so the first thing you want to do is get rid of this cookies notification you want to come up here and click on register and here is the agreement registration agreement there's nothing hidden here this is just a disclaimer about trading and the just generic forum rules nothing too complicated i don't want your firstborn child or anything crazy like that you want to agree to these terms and then fill out this information with whatever relevant information you want to include so you need to input a username an email address password and down here this is optional this is your trading view profile you don't have to put this in if you don't want to and then finally this is the important part this is the registration code box so depending what code you put into this box will determine what group you added to when you sign up to the forum so at the moment there are three groups there's the pinescript mastery students group there's the pinescript mastery course graduates group and there is the pinescript mastery mentorship group so anyone can sign up to this website it's completely free to access but there are a handful of private forums that are only accessible by certain groups of people so anyone who signs up to the basics course or finds this website over google or from my youtube channel they can sign up for free and they get access to their own forum and this will be easier if i just show you what i'm talking about so everyone has access to these forums here you need to be registered in order to post in these forums but these forms are accessible by anyone same with these ones here and the feedback and support section but there are a handful of private forums so first there's the pine script scholars forum this is only for people who are enrolled in the pine script mastery course this is for you guys to talk among each other and you won't get any random trolls or anyone that's um that's not on your level of pine script expertise coming in to contribute to your conversations the next one is the pinescript masters forum now this forum is restricted only to people who have graduated the pinescript mastery course finished all the lessons in the course so this is for people who want to have a little bit more of a sophisticated conversation about pine script with each other and they know that the only other people who can comment on their discussions are people who are at the same level as them in their pine script education or even more educated and then finally there's another form here that you can't see unless you're signed in as a mentorship student but there's a pine script mentorship section as well so anyway let's go back to the register page and i'll explain what you do down here so because this is on youtube and it's open to everyone unless you're enrolled in the mastery course in which case you'll get an email with a code to sign up with then you can only sign up as a free user and you can just ignore this box here and don't put anything into it you just create a free account and you can communicate with other free users on the network if you want to access any of those restricted forms that i just mentioned you'll need to upgrade to the mastery course or graduate the mastery course if you want to talk to other mastery course graduates so if you have access to a code once you put it in here and you click submit you'll be automatically enrolled in the relevant group and once you confirm your email you can come in and access the form and start sharing your thoughts with the community now if you've already created an account on this forum and then you receive a new code so for example let's say you purchased a mastery course and you sign up as a mastery course student and then eventually you graduate the course and you complete all the lessons and you want to change your membership group type to the graduate group you need to come up here to your user control panel so click on your profile picture click on user control panel and come up to user groups and then in here you can type in the registration code that you receive and the codes here are exactly the same as they are on the other registration page other than that it just operates as a normal forum so there's a few guidelines and information here so i encourage you to read through this when you first sign up but there's nothing really fancy here it's just you know don't spam be kind to each other keep all topics relevant to pine script coding and don't advertise anything on the forum without asking me first so that i can verify that it's not something malicious or or low quality of course you are absolutely welcome to advertise your own scripts your own projects even your own websites but if you're going to advertise anything external to this platform other than a trading view script please let me know first so that i can just ok it and vet anything that goes through here because i don't want any scammy stuff happening or any spamming to occur i want to keep this as clean as possible and as useful as possible to everyone who signs up other than that there is also this forum here the show-and-tell slash request so you can share your scripts here with the community everyone has access to this forum and same with request scripts you can request scripts from other people in the community and so if you're a student say you're a pine script mastery core student and you want to test your skills i'd encourage you to come and check out if anyone requests a script in here maybe you can help them out and maybe you can test yourself and see what you're capable of there's also a forum for general trading discussions so i prefer if everyone can keep their trading related discussions that don't involve panscript in this forum and then there's a feedback and support section as well so i definitely want to hear your feedback if there's something you feel is missing from the site or something that's not working as you would like it to just let me know and this is supposed to be community effort and i really hope you guys will get involved and help me make this community as useful and engaging as possible this is for your benefit not for my benefit i created this for the pine scripting community so that when you guys have questions if you shoot them to me and i don't have time to answer them maybe you can throw them up in this form as well we can all benefit from the answers and maybe you guys can help each other solve each other's problems i plan to expand this in the future i'd like to have like some sort of store for people to sell their own scripts on here or just some sort of script library would be great so that you guys can get the most out of this but for now this is just a community for you to talk amongst each other help each other out and i hope you like it i hope you find it valuable that's it for this video i hope to see you over there if not that's fine there's no pressure to join this community this is just for fun and it's purely optional if you guys want to join up and help each other out so that's it for this video i'll see you in the next one take care guys [Music] you

Pine Script V4 Color Gradients (& my first SIX FIGURE winning trade on Cardano!🥳)

hi traders in today's video i'm going to
be showing you how to use a new feature
that
the tradingview team recently added to
pinescript
this week i was planning to release the
seventh video in my auto view series
where i show you how to expand
the strategy script that we wrote in the
previous lesson
and add a bunch of filters to that
script but this week we had a gigantic
market crash in the crypto markets and
so i've been
very very busy managing my own money and
actively trading this week
i actually had the most profitable day
of my entire career
yesterday trading this correction on
cadano i managed to buy
very very close to the bottom
at one dollar and four cents u.s which
resulted in me having my very first
six figure profitable trading day which
was pretty exciting to say the least
i managed to sell up here at 2.37
i sold roughly half of my holdings and i
bought back in at a dollar and four
cents which is the best trade i've ever
made in my entire life
and here is the proof that on the 16th
i actually did sell half of my kadano
position
at 2.37 cents up on this week here
just really quickly the reason why i did
that was because on a five minute time
frame
uh we began making lower
lows and lower highs and so i sold on
this retracement here
and i was fully prepared to buy back in
if i was wrong and price
broke out above this previous high but
price never
did break through that previous high and
in fact
we had one of the biggest market crashes
that i've seen in crypto
in a very long time but anyway i'm not
saying all this just to brag
i'm just pointing out that over the
years i have become very very confident
in my own trading techniques and
processes and i do plan to
create a trading course later this year
demonstrating and explaining how i
analyze charts
why i picked all of these key support
and resistance levels on my chart
why i sold up here and brought back down
here and in fact i sold some more of my
position
in here at around 1.80 on a lower time
frame and
i have already bought back in to my
position down at
a dollar seventy so in a matter of two
or three days i have significantly
increased my cardano holdings
using extremely simple trading
techniques and i'm really excited to
pass on the knowledge that i've learned
over the past four or five years of
trading
and so if you're interested in learning
how i trade keep an eye out for that
course which i'll start rolling out at
some point later in the year
hopefully if i get time it's actually
really hard to find the time to make all
of these videos when i'm actively
trading my own accounts and managing my
own investments
but anyway enough about that let's get
into today's video
next week i'll pick up where i left off
in the previous auto view video
but for today we're just going to cover
an extremely simple but interesting pine
script update
that the team made where we can now work
with color gradients
so overnight the pine script team added
a new functionality or feature
to pine scripts dealing with colors so
we now have more control over the colors
we use in our scripts
it's a small change but it's a nice
change for those of you who like to have
your scripts look more aesthetically
pleasing so this will just be a quick
video
explaining the new changes and how you
can use them in your scripts so they've
added a couple of new functions
2pin script the first one is this
color.rgb function
which takes four function parameters
which is your red color green color blue
color and transparency now those of you
who are familiar with other programming
languages and have used rgb coloring
before
we'll already be familiar to this sort
of method
for generating colors so the numbers are
between 0
and 255. 0 being
no green or no red or no blue and 255
being
bright red bright green bright blue so
this is a little bit different to
hexadecimal coloring
and perhaps a little more intuitive so
i'll leave a link to this article
beneath this video the pinescript team
have included a couple of examples of
how to use
this code but we'll jump over to the
pine editor in a moment and play around
with an example so that's the first
change that made is this new color.rgb
function
the second function that they've added
is this color.from gradient
function which allows you to change the
color of something on your chart
based on where the value falls between
two
numbers so in this particular example
the script is plotting the rsi and the
closer the rsi is to 70
the more red the rsi turns and the
closer it is to 30
the more green the rsi turns and this is
all achieved
using this new from gradient function so
you can see here they're passing the rsi
value
they're passing their lower limit and
their upper limit and the two colors
they want to
calculate the gradient between and the
closer the rsi value is to 30
the closer the color is to lime green
and the closer that value is to 70
the closer the color is to red and you
can see that this allows
you to achieve some pretty cool stuff on
your charts it can really make some of
these scripts look a lot more futuristic
and modern so let's jump over to the
pine editor and
break down this particular example i've
just added a few comments
to this script to better explain what's
going on here
so this script is just plotting an rsi
standard rsi
14 length period with the price source
being the closing price
the first thing that's happening here is
we're creating a custom function
that takes two parameters one is the
color we want to work with
and the other is the transparency we
want to work with
and so later on the script is filling
the background it might be a bit hard to
see because of how
faint or transparent the coloring is but
the background of this rsi
is changing color based on the color of
the rsi so we'll come back to this
custom function in a moment
let's go over how the rsi coloring works
first because this function depends on
the rsi color being a parameter so the
first thing we do is just get the rsi
here
the second thing we do is get the color
gradient of the rsi so that's the actual
color
of this line that is plotting onto the
chart we do this using the color.from
gradient function
which takes several parameters the first
one is the value
we want to reference the second
parameter
is our bottom value so the closer this
value gets to
our bottom value the closer the color
will be to our bottom color
and the closer this value is to our top
value
the closer the color will be to this top
color
so we wanted to we could change this to
anything we could change this to
blue and color.green for example
if i save the script the gradient will
change
so this is a really cool feature that
makes it extremely simple
to basically create like a heat map kind
of
effect so let me change these back for a
moment
and move on to this custom function here
so the next thing we do is we just draw
our upper and lower limit
we're using the new color color.rgb
function
just to demonstrate how this works so
this is your red
green blue value and as you can see this
upper
limit the overbought limit has a higher
red amount than
blue and green and that makes the color
more red and once we plot our upper and
lower limit
we then fill the background between
these two limits with this color
function here which is this custom
function and we're passing
the color gradient of the rsi so the
color of our rsi line
into that custom function along with a
transparency amount which in this case
is 90 so 90
transparency then this function is
getting the red
value from our rsi color then
it's getting the green value and the
blue value and then we are rebuilding
that color using the color.rgb function
we're passing in the red value the green
value the blue value and our
transparency
here which is again 90 so there are
obviously more efficient ways to do what
the script is doing this is purely just
demonstrating
how we can use these new functions in a
practical manner
in our scripts and it's actually pretty
cool for example one use case for this
might be
a heat map like i mentioned so i have a
arvol by time script here that i created
uh many months ago
and it has a heat map color scheme here
and i had to custom code the color
gradients here so the more volume that
was printed on
a bar the brighter the color is i could
actually
add this color gradient functionality to
this script
which would mean i don't have to hard
code
the color gradients so that's it for
today's example of this latest pine
script update
if you want more information i'll leave
a link to the blog article beneath this
video
i've got a few more examples over there
a few more code examples
but that'll do it for today thanks for
watching best of luck with your trading
and coding and i'll see you in the next
lesson
you

Multi-Timeframe Trend Analysis in Pine Script

in today's video we are going to be
dressing another question from someone
in the Mastery course and this someone
wanted to know how to adapt the regime
filter to work on multiple time frames
so if you're not aware of what a regime
filter is it's covered in great detail
in Andreas clanow's fantastic book
stocks on the Move highly recommend that
book if you haven't read it already it's
one of my favorite trading books same
with Unholy Grails by Nick Raj he uses a
market regime filter in his trading
systems as well this approach is best
suited to stocks although it does seem
to show promise in crypto and certain
other markets if you're creative with
how you apply it but the general concept
is that the market needs to be trading
above a higher time frame moving average
before you start taking trades on a
lower time frame so in this case we're
on spy we're on the S P 500 market index
we're on the one hour time frame and
this moving average here is a higher
time frame EMA right now it's set to
four hours but we could set it all the
way up to one week and now you can see
that it's turning green when price is
trading above this moving average and
turns red when it is not the whole
concept here originally is for long only
stock market strategies to only trade
when the wind is behind our back so when
the market is trending upwards on those
higher time frames and this script you
see down here
is the regime filter script adapted to
show three different time frames so
we've got the 240 minute time frame or
the um four hour chart we have the daily
time frame and the weekly and if I hover
over these labels on the end we can see
the actual EMA value there so what is
more effective than using one market
regime filter not necessarily three but
if one indicator is good then several
must be even better now I'm joking a
little bit there because a lot of
Traders do like to throw on a lot of
indicators on their charts and it's not
helpful but in this particular case this
Market regime Builder could be useful
especially on Lower time frames so if we
go down to like the 15 minute chart here
and you would adjust these higher time
frame moving averages you could really
make a simple rules-based objective
method for determining your directional
bias for day trading you know sometimes
it's difficult to know which way to
trade a market when you're using just
discretion but with an indicator like
this it's pretty pretty clear where the
momentum is and which direction you
should be trading in and as a little
bonus at the end of this lesson I've
implemented this new Pine logging
feature we open up the pine logs will
actually tell us how often the market
trades above all of these higher time
frame moving averages so if we go to the
one hour chart again you can see we have
a 54 chance that a bar will trade on
this time frame this one hour time frame
we have a 54 chance that the regime
filters will all be green what that
tells us is that the market likes to
Trend upwards at least on this one hour
time frame and at least since 2009 until
today which is a decent sample size by
the way we have 20 000 one hour bars
that we're analyzing here to get these
numbers so yeah interesting script here
let's break down the source code uh the
source code is not particularly complex
and hopefully you guys find it
interesting so let's open up the source
code here and break down everything so
I've already written out the code
obviously to save time the first thing
we're doing is getting our user inputs
so we have three time frames here we
have a moving average length which is 20
by default now this isn't trading advice
but obviously depending on the time
frame you're trading these numbers will
matter a lot so on a lower time frame
you would want these higher time frame
moving averages to be a lot closer to
your trading time frame so if you're
trading a five minute chart you might
want the 30 minute hourly and and four
hour time frames for example you want
the regime filter to be more sensitive
to short-term momentum if you're trading
a short-term time frame and if you're
trading a higher time frame like the
four hour or daily you might want this
to be the daily one week in one month or
something like that same with the moving
average length the lower the time frame
typically the lower you probably want
this number to be the higher the time
frame you might want to extend it to 50
100 or even 200 not 1200 that's probably
a bit too much the next input is our
market so this is the market we're
referencing to get all of these EMA
values you could get rid of this input
and simply pass in the Sim info dot
ticker ID into all of these security
function calls and then you would just
retrieve all of the market information
for the market that you've loaded onto
your chart but the whole point of this
regime filter in its original conception
is to trade it on things like individual
stocks if I go to S P 500 here
and we jump on to what looks interesting
Netflix now we are plotting the s p 500s
regime filters over the Netflix stock
chart and so what this will tell us is
when the broader Market is moving
upwards
um you can see that the regime filter
Now does not match the price action I
have on my chart because this
information down here is referencing the
S P 500 while all of this including this
higher time frame moving average is
referencing Netflix's price action and
how you would typically use this regime
filter is to only trade these members of
the regime filter universe so in this
case members of the S P 500 when the S P
500 is trending upwards if you were to
use this on crypto you'd probably want
to reference Bitcoin on altcoins and if
you're using it on something like Forex
maybe you want to reference the dollar
Index when you're trading dollar
denominated pairs like euro dollar
dollar Yen Etc but anyway let's go back
to the S P 500 for now and finish
breaking down the source code so before
we get any of this information we're
creating a custom security function that
does not repaint so I've gone over
repainting many times in the course and
on my YouTube channel so go back and
check those videos out if you are still
uncomfortable with repainting but
basically including this code here these
little historical operator checks this
check is checking the real time price
information the real-time bar if the
real-time bar is currently a real-time
bar not a historical bar we reference
that bar otherwise if it is a historical
bar we reference the previous bar now
don't ask me why this expression
eliminates repainting it's just
Blackmagic that the training view
developers have decided to implement on
this particular function and it works so
that's all I know and so when you're
using the security function make sure to
include this code expression if you do
not want your script to act differently
on real-time price movements compared to
historical price movements that's a big
problem with uh strategy scripts in
particular if your script does not
perform the same on historical data as
it does in real time then you're
obviously getting dodgy back testing
results which can lead to the
development of systems that aren't
profitable but look profitable on paper
anyway you don't need to have this
security function this Custom Security
function I just implemented this into
the script because it makes these lines
of code a lot easier to read otherwise
we would have six of these really long
lines of code on these six variables and
so to make the code more readable I've
just implemented this this custom
function which by the way is easy to
just copy and paste into your own
scripts and then you have your own
non-repainting security function anyway
moving on we get our EMA values for the
higher time frame so to do that we just
get the current time frames EMA this is
what is called an expression a code
expression and the security function
requires us to pass in an expression
that's why this is called exp short for
expression and that's what these three
are and these three are so for our
higher time frame EMAs we are passing in
the EMA expression and this will
retrieve this value from this market and
this time frame so EMA value one will be
our first time frames EMA value
ema2 will be the second and so on and
same with our price values we're getting
our first time frames closing price
second closing price and third closing
price and then to validate our regime
filters for each time frame we simply
check if each time frame's closing price
is above its moving average and that's
it that's all we need for a market
regime filter now if we just wanted to
have one color down here we could just
simply add in a new bull variable here
called regime filter equals regime
filter 1 and 2 and 3 Etc passing those
but for today's lesson the student who
asked this question wanted to see all
three separately so that's what we are
doing here which obviously complicates
the script a little bit not a lot
there's a bunch of code here that looks
scary if you're new to paint script but
it's all just copy and pasted blocks of
code so I'll just go over one of them
and explain what's going on here I
simply wrote this code out once copied
it and pasted it three times and change
the variables so that they don't
conflict with each other so for the
first regime filter I create two H lines
which are horizontal lines that's these
black dotted lines on my chart here and
once we have two H lines if we assign
them to a variable we can then use the
fill function to fill between these two
H lines and we can specify the color
that we want to fill between those two
lines so to get the color of our region
filter to make it either green or red we
simply check is regime filter 1 true in
other words is the closing price of our
first time frame above its moving
average if so we want to fill the two H
lines as green otherwise we want to fill
it as red and then just to make it a
little bit clearer what each ribbon here
represents I've added in some labels
these labels here tell us which time
frame each ribbon represents that just
makes it a lot easier to understand
what's happening just at a glance
without having to remember which ribbon
is which time frame so to do this I
create a persistent label VAR means it
does not reset on every new bar on our
chart and in fact because we delete the
label on each previous historical bar
you don't need these persistent variable
labels so I'll get rid of them for now
just to make the code a little bit
easier to read let's save that this
should change nothing there we go so
we're creating a label
it's set to n a and then we check if we
are on the last bar loaded onto our
chart then delete the previous bars
label and draw a new label on the
current bar the reason we need to do
this is because if we were to run this
script on a real-time price chart and we
had a few bars print these labels would
start to shift to the left and be drawn
over the top or underneath these ribbon
colors which obviously is not what we
want we want these to stay on the far
right so we delete old labels and create
new labels
the new label
just has our time frame as its text so
240 is this time frame it has a tool tip
so if we hover our Mouse over it will
tell us what the EMA value for that time
frame is it has a transparent background
color white text and the label style is
to the left which just means that it the
label looks like this
however I've set the background color of
the label to transparent so we don't
actually see that but the text
is to the right of the current bar and
that's it that's the script
um I've simply copy and pasted this
three times I've changed the price value
that we're drawing each label so this
label is drawn at 0.5 which is here this
label is drawn at 1.5 which is here and
this label is drawn at 2.5 which is here
and the H lines simply draw between 0
and 1 1 and 2 2 and 3 and that gives us
these even
um this even scale for this particular
indicator and that's it for this script
uh just as a little bit of a bonus outro
or conclusion here is
some code using the new Pine script logs
functionality so what we're doing here
is we're counting how many bars past all
three regime filters so if all three
regime filters are true then total bars
past is incremented by one we add up how
many bars had all of these filters met
if we are on the very first bar in our
chart we use the log dot info function
to plot a bit of text here that just
says our analysis starts here so we can
see at a glance what the very first bar
that our script ran on so that was back
in January of 2009 and then we check if
this is the last bar on our chart we
calculate the percentage of bars on this
time frame where all of our filters were
met so in this case that's four 54 of
the time so we have an obvious bullish
bias on this one hour time frame from
2009 all the way till today so that
tells me that if I was to be day trading
the S P 500 100 on the one hour time
frame I should probably favor long
trades over short trades objectively the
market likes to Trend upwards or the
momentum likes to be to the upside at
least with the settings we've inputted
into this current script and then we log
how many bars passed out of how many
bars have drawn on our chart so bar
index on the last bar will simply be the
number of total bars on our chart and we
add in the percent here so that we get
all of that information we had 11
173 bars out of 20 000 bars that passed
all three filters and then I also drew a
table here table Z or Z I don't know why
I put a z on the end it's just it can't
be called table because that's a
reserved keyword so we can call this
whatever you want but basically this
table has one column with three rows so
one column three rows it's set in the
middle Center and we set each row to
each time frame so so that we can see
which time frame which ribbon applies to
which time frame even when we go back on
historical data now the table isn't 100
accurate if you extend this too much it
uh gets out of whack but you get the
idea at least At a Glance we can tell
the top one is the weekly middle one is
daily bottom one is four hour anyway I
hope you found this lesson interesting
it's a pretty cool little application of
the security function and higher time
frame information I'll leave this video
here thanks for watching good luck with
your trading and I'll speak with you in
the next lesson take care

MERGING Stochastic & RSI • Pine Script [OUTDATED V4] Tutorial

hi traders in this lesson I'm going to
show you how to draw the RSI indicator
over the top of a stochastic indicator
by creating our own our a science to
cast ik code so let's get into it start
a blank script here gonna remove this
script going to call this PS MC
stochastic and RSI I'm gonna save these
scripts add it to my chart and we're
good to go so the first thing I want to
do here as always is get my user input
user input and we needed several inputs
here in order to draw a fast stochastic
we need the K input we need the D input
we need an overbought level and we need
an oversold level so I'm going to use
the input function for all of these and
this first input function is going to
get our K length so I'm going to title
this input function K length I'm gonna
give it a type of input integer and a
default value of 14 which is the
standard default for a stochastic
indicator next up we need to get our d
input which is going to be a moving
average of the k variable so here I'm
going to give it a title of d.length a
type of input integer and a default
value of 3 so these are the default
parameters for your standard stochastic
indicator we have a key length of 14 and
a moving average a simple moving average
of the K length of a 3 period moving
average and when we calculate the actual
stochastic this will make sense later on
in the script so next up we need our
overbought and oversold levels so I'm
going to title this over board threshold
and I'm gonna give it a type of input
float and a default value of 80 so you
could set this to integer if you wanted
to but I find that it's better to set it
to a float because then your user can
come up into the settings menu and
change the overbought level or oversold
level
more minutely so you could change this
to 80 point one for example it just
gives you a little bit more control a
little bit more flexibility with your
scripts parameters so I'm just gonna
copy this line of code here and change
this to say oversold and change the
default value for the oversold to 20 so
by default we're using our overbought
and oversold levels as 80 and 20 but you
could change these to whatever you
wanted to nineteen point nine for
example something like that but we'll
leave it as 1820 for now and let's move
on to calculate our stochastic so in
order to do that the stochastic
indicator is similar to the RSI
indicator in that it's an oscillator
that oscillates between a value of 0 and
100 now there's a mathematical formula
for this indicator that's quite simple
you no need to know this and need to
understand what this is or how it works
in order to use it but I like to have a
thorough understanding of all the
indicators that I use and so I will
write out the formula for this
stochastic and it goes a little
something like this 100 times the closed
minus the lowest low over the past 14
candles divided by the highest high over
the past 14 candles minus the lowest low
over the past 14 candles or of course
this 14 could be whatever we set out
k.length to so let's write this out in
prime code so we need to create a new
variable called K and we're gonna set
this to 100 times we need to open a pair
of parentheses here I'm gonna get the
closing price minus the lowest low over
our K input length so by default 14 then
close that parenthesis you don't need to
have these parentheses here in closing
this entire statement this would work
just as well but I like to just for
visuals sake I like to wrap any equation
in parenthesis so I just know for sure
what arithmetic operators are being
executed within these parentheses but
anyway now we need to divide whatever
this result is by
the highest high / out key input length
- the lowest low / our key input length
and I'm just gonna wrap this entire
calculation in a set of parentheses just
so that we know for certain that this
value here whatever this turns out to be
is going to be multiplied by a hundred
here so there's our stochastic formula
that will give us our fast stochastic
next up we need to calculate our D
variable which is simply a simple moving
average SMA this will use the inbuilt
simple moving average function we need
to pass it our K input and our length
which is d input so now we're
calculating a simple moving average of K
based on a three period length and our
user can change this to whatever they
want by changing the D length input
parameter in the settings menu so that's
it we have now calculated how stochastic
I'm gonna get rid of this formula here
just to tidy the script up a little bit
and all that's left now is to draw data
to chart so for this I'm going to plot
out K variable I'm going to give it a
color of color purple I'm gonna give it
a title of K so that we can adjust this
in the settings menu if you want to next
I'm going to plot the D variable here is
D value and it's gonna have a color of
color orange and a title of D then we
need to pluck our over board an oversold
levels so OB level will give it a color
of color dot red and a title of
overbought and I might set the line
width here to two as well just so it's a
little bit thicker and it stands out a
little more on our indicator box and
then finally I'm just gonna copy this
entire line of code paste it down here
change this to oversold level change the
color to green and change our title to
oversold so now we're drawing our
stochastic and if I save these scripts
and we minimize this pine editor there
we go just like magic
we are drawing our stochastic indicator
onto our chart and everything appears to
be working perfectly
so just before I move on I should point
out that you can achieve this
calculation using an inbuilt function in
pine script so I've written this formula
out manually because I thought you guys
might find it interesting how to achieve
this so that if you ever run across an
indicator out there in the wide world of
the internet that pine script doesn't
provide an inbuilt function for you can
just write out the formula yourself but
if we wanted to we could have just used
the inbuilt stochastic function so this
function here takes four input variables
it takes a source a high a low and a
length so we could write in here close
high low and just we could put 14 in
here for a default stochastic length or
just copy our K input into that and now
if I saved these scripts I'll be getting
exactly the same thing drawing onto our
chart but for the purposes of this
demonstration we're just going to leave
this custom formula in just because it
makes this lesson a little bit more
interesting so now if you were to try to
detect setups
whenever the RSI goes overboard or
oversold we'll try to identify
divergences such as this divergence here
you can compare whatever price is doing
to your K variable or your D variable so
if you wanted to detect the market being
oversold you could see if the closing
price is below K or D and then if this
condition is met then you can do a bunch
of other calculations and we're not
going to go into that in this lesson
because this lesson is just about
drawing the stochastic and the RSI which
we'll get to next onto your chart and
I've already shown you how to detect
candlestick patterns and work with
conditions so if you want to make this
more complicated you can go ahead and do
that in your own time but next up before
we finish this lesson let's draw our RSI
on as well so here I'm going to create a
new input variable called RSI length and
we're gonna give it an input title of
our side length a type of input integer
and a default value of 14 so by default
we're gonna calculate the same arrow
sign length as out K and on here I'm
just gonna add and RSI and we're going
to calculate our
using the inbuilt RSI indicator function
which takes two input parameters and
that is a source price so in this case
we're just going to calculate it on the
closing price and we're gonna give it a
length of RSI lengths so by default this
will be a 14 period RSI and now if we
come down here we'll plot the RSI onto
our chart I'll give it a color of color
black and I'll give it a line width too
as well so that it stands down a little
more and we'll give it a title of RSI so
now if I save the scripts we'll be
getting our our side drawn over the top
of our stochastic so that we have it and
just before I finish this lesson I'm
just gonna change the color of this RSI
to red or green based on whether it's
overbought or oversold just so we have
some visual cues of what's going on with
that so here I'm gonna change this to
say is our RSI level greater than our
overbought level question mark then if
this is true then set the color to color
red otherwise is the RSI less than our
oversold level question mark if so and
set the colored color green and if
neither of those conditions are true
then we set the color to black and I
should probably change these to less
than or equal to and greater than or
equal to so if the RSI hits our
overbought or oversold level the color
of the RSI will change color and if I
come to the settings menu change the RSI
length to let's say seven and I save
those settings here we go you can see
that when the RSI goes over bought we
get a red RSI drawing and when it goes
beneath the oversold level it turns
green and there we have it we're done so
that's it for this lesson I hope you
found that helpful if you did and you
want to learn more about Pine scripts
head over to pine skip mastery com here
you'll find my advanced pine script
courses and my basics course which is
free so if you want to learn more about
pine script head over here and you'll
find out a little bit more about me and
a little bit more about pine scripts I
hope you found this lesson interesting
and helpful I'll see you in the next one
[Music]

How To Use EMA FILTERS • Pine Script [OUTDATED V4] Tutorial

hi traders in this video i'm going to
show you how to create
an ema confluence filter for your
scripts
so basically what that means is here i
have two emas plotting onto my chart
we have a 50 ema here
and 100 ema below it and for this
particular script it doesn't matter what
entry reasons
you detect in your script you can be
detecting any candlestick pattern that
you like
but for today's example i'm keeping it
very simple and the entry reason we're
detecting is just simple engulfing
candles they don't have to be swing lows
they just need to engulf the previous
candle and
what this script is doing is first of
all
price must be above this 50 ema before a
valid
signal will be detected but the
50 ema must also be above the 100 ema
before a valid signal is detected and so
in today's
video i'm going to show you how i
created this script so first of all
let's remove the script
reset the chart and create a new blank
script so here i am with a blank script
let's get started first thing i'm going
to
do is always is get user input and for
today's video we're just going to get
two
uh inputs two ema length inputs so here
we have two inputs ema length one
ema length two of type integer and we're
just going to set it to 50 and 100 by
default
and the next thing we're going to do is
get the actual ema's
so we need ema1 is set to ema close
with the length of ema length 1 this
input here
and then we'll just copy this paste it
down here and change these to
two so there's our emas now we can draw
them to make sure that they're working
properly
so the first one i'm going to plot as
ema1
and i'm going to change the color based
on where the price is above or below it
so we're going to say
is the close above ema 1 if so set the
color to color.green
otherwise set it to color.red and we're
going to give it a line width of two
let's thicken it up a little bit now
copy this line of code paste it in there
change this to ema2 and we'll just get
rid of this because
it'll be confusing to have both ema's
changing color we'll
just set this second ema to color.blue
and we'll just thicken it up a little
bit change the line width to three
save the script we shouldn't have two
emas drawing there perfect
and so now in order to get the filter
and detect whether these ema's are above
or below
each other we need to detect some entry
reasons
so here i'm going to say detect entry
reasons and again this could be any
entry reason you want
i'm just using engulfing candles today
because they're an easy example
so i'm going to create two variables
here long entry and short
entry long entry is going to be set to
whether the
current candle close is greater than or
equal to the previous candles
open and did the previous candle
close as a bearish candle
or a doji was a previous candles closing
price less than or equal to the previous
candles opening price
and then it's just the opposite for a
bearish engulfing candle
so there's our long entries and short
entries now we can plot these
to the chart so create a new section of
code
here call this plot entry signals
and we'll just use plot shape for this
not plute
shape plot shape uh long entry
i like to do it this way if you don't do
it this way
i'll show you what happens in a second
but what we're doing we're saying
if we have a long entry then set plot
shape to 1 which means it will plot
a shape otherwise plot n a and we'll
give it a style of shape dot
pro up for a bullish candle and the
color will be color.green
and the location will be location dot
below
bar so just really quickly let me save
the script make sure that's working
there we go so now the reason why
i like to do it this way
because we could just get rid of this
code here and this will still compile if
i save the script
you can see it's doing exactly the same
thing the difference is
up here so when we have a signal
you can see that this plots 1.0000
or however many decimals are on your
price chart but now if i go to
any candle that does not have a signal
we're also getting 0.000
this is obviously a long number and if
you've got a lot of plots
in your script these numbers can add up
quickly
if you have six digits plotting for
every single shape on your chart
whenever there's a no signal
it'll just really clutter up your chart
so i like
to add this little bit of code in here
so what we're saying is we're saying
if we have a long entry detected then
set this plot shape to 1 which means
true it'll just draw the
shape otherwise plot n a so now if i
save the script
you'll see that when we hover over any
candle that does not have a signal
we're just plotting n a it's much
shorter than a six digit number
so that's why i do that here let's move
on
copy this line of code paste it in here
get rid of blow bar because by default
this plot shape plots above the bar and
for
bearish signals that's just fine
so we're going to plot shape for every
short entry
and the color of color.red now if i say
the script we'll be getting
bearish engulfing candles plotting to
our chart as well
but we're not taking into account our
ema filters yet
so for that let's add a new section up
here
called get filters we're going to have a
long filter
and a short filter now our long filter
is going to be there's a couple of ways
we can do this first of all
we could just check if the emas are in
confluence so we could just say here
is ema1 greater than ema2
or is ema1 less than ema2 for a short
filter
then if we add this boolean into our
entry reason detection down here so
short
filter and long filter combined with our
long entry and short entry conditions
now if i save the script we'll only be
getting long
bullish engulfing candles plotting if
this 50 ema
is above the 100 ema
and vice versa for shorts we'll only be
plotting
bearish signals if the 100 ema is above
the 50
ema so that's the first part of an ema
compliments filter
and this works just pretty pretty good
works pretty fine actually
uh but if you want to take it one step
further you can also detect
if price action is below this 50 ema
for shorts or above for longs so if we
wanted to we could add into this long
filter
is the current close greater than ema 1
and is the ema 1 above
our ema2 and vice versa for short so we
could say
is the price of the current candle below
ama1
and is ema1 below ema2
so when i save the script here this
entry pattern here is going to go away
as is this one here and this one up here
so now if i save the script so there we
have it so now we're only plotting
signals
if the 50 ema is below the 100 ema and
price action is below the 50 ema
and the opposite for long trades so
that's one way to apply
an ema filter uh but before i end this
lesson i thought it might be interesting
to show you guys how you can
disable your ema 2 in your script in
case
you have a script that has this
functionality in it
but you want to allow both options for
your users so you want to allow
the user to disable ema2 and only use
the ema1 as your filter the easiest way
to do that is to just set ema
2 to 0 ema2length to 0
and detect that in your script so i'll
show you what i mean right now
so down here we can change our filter to
say
is the closing price above our ema 1
and is ema1 above ema2 or
is ema length two equal to zero
and copy that down into there and so now
our filter
will return true if price is above the
ema
and our emas are in confluence or we've
disabled
ema2 by setting its length to zero now
the problem is if i say the script will
get an error
whenever i come up and set this to zero
because
you cannot have if i click on that it'll
tell me the error
we cannot have a length of 0 passed to
the ema function
must be above 0. so what we need to do
here
is say ema length 2
equal to 0 question mark then set it to
1
otherwise set it to ema length 2. so
what we're saying here is we're saying
for our second ema
if the user has set ema length 2 to 0
then we just want to get an ema with a
length of 1
otherwise we do want to use our ema
length 2 parameter
because it's set to something other than
0.
so now if i say the script that will
work just fine
if we come up here and we set email
length 2 to 0
we'll be getting any signal that closes
above or below this 50 ema but you can
see we're also plotting
our second ema with a length of one so
if we come down to where we plot our
emas
and we check here if our ema length two
is set to zero
so ema length two equals zero question
mark
then we want to draw n a
otherwise we actually do wanna draw our
ema
two so now let's save the script
minimize that come up to the settings
menu and set ema length two to zero
our second ema goes away and it is now
no longer being considered
in our filter check uh if you didn't
understand anything in this video just
rewatch it it'll make sense i'm
sure but basically what we're doing here
is we now have two emas
if our first ema is
above our second ema and price action
is above our first ema
then the script will be looking for long
trades
otherwise if our first ema is below
our second ema and price action is below
the first dma then the script will look
for
short trades and if you want to you can
come into the settings menu here
set ema length two to zero hit ok
and now this script is only using the
first ema as the filter this is a
very simple filter very simple method
but it works very well but finally
one last thing that i have found useful
in my own scripts
is to detect how many candles
are above or below the ema preceding the
setup
so for example in this case you can see
we have
two candles that closed above the ema
immediately preceding
our setup what happens if you want to
invalidate the setup
based on this condition as well i'll
show you how to do that really quickly
so here we come up here and above our
filters
let's add in ema breach check
and what we're going to do here is we're
going to create two new variables we're
going to say
bars above ema and bars below
ema and this is going to be set to 0
by default then we're going to use two
for loops here we're going to say 4
i equals 0 2 and
let's create a new input variable up
here i will say
e may look back and this is just going
to be another input
with a title of ema lookback a type of
integer and a default value of
three so we're going to look back three
bars and count
how many bars are above or below the ema
and incorporate that into our filter
so here i can change this through to ema
look back
and now we can check if the close
of our current iteration we can just put
i in here
which is this guy here so if the current
adoration of our loop
our for loop looking back if the closing
price of that candle
is above the ema one then we want to set
bars above ema to bars
above ema plus one and we can also check
in the same for loop we can also count
how many bars close below the eme
so here we'll say if the closing price
of the current
iteration of this loop so you know we're
looking back
one two three candles if the current
candle
is below the ema or the previous candle
or the one before that then that will
increment our bars below
variable by one so this is how we
count candles beyond the
ema so now if i save the script should
compile without any errors
there we go now all that's left to do is
add these checks
into our filters so i'm going to create
one more user input here it's going to
be called max bars beyond ema
it's going to have a title of max bars
beyond ema
it's going to be of type input.integer
and have a default value of one so we're
only allowed one bar
to close beyond the ema over the past
three candles by default for a signal to
be considered
valid so now if i come down to our long
filter and short filter
we can add on the end here and bars
for a long trade where checking bars
below ema
is less than or equal to max bars beyond
ema and the opposite for short trades
we're checking
and bars above ema is less than or equal
to max bars
beyond ema so now if i save the script
we come up to the settings menu and we
turn off our second ema that will bring
back this example here
and look at that we are now invalidating
this setup here because we have had more
than one candle
close above this 50 ema over the past
three bars
so now if i come up to the settings menu
here if we change this max bars
beyond ema variable to 2
let me click ok this setup will come
back
because it's now considered valid
because we can have a max of two candles
closing above the ema for short trades
and obviously for long trades
it is the opposite so back here if i set
this back to
one ah sorry if i set this to zero
that will invalidate this setup here
because we've had one candle close below
the ema
so this is a great way to avoid taking
signals
around the ema when price is
consolidating
around it so typically speaking when
the ema is tested as support or
resistance
and price responds from it it's often
likely that we only have a maximum of
one candle closed
below it if we have more than one candle
close below it preceding a setup
then that usually means that the ema is
being ignored
so that i found in my personal trading
that the optimal setting for this filter
is one bar
beyond the ema over the past three bars
preceding
our setup so if we zoom out a little bit
look for some examples so you notice
we're working off closing prices here
not wix because any wix test in the ema
is a good sign that's a bullish sign
that this ema is acting
as support and pushing price up but
if price hovers around the ema
for a little bit too long such as in
here
we do not want to be going short on any
short signals
if price is consolidating around the ema
because that means we're either entering
a period of consolidation
or price wants to reverse so i hope you
found this lesson interesting i'm going
to leave it there
i don't want it to get too long we
covered a lot of subjects here we've
covered how to create a single
ema filter we've covered how to
create two ema filters in confluence
with each other we've covered how to
create a filter with an ema breach look
back
so we're searching back three bars
counting how many bars close beyond the
ema
so above the ema for short trades below
the ema for long trades
and if we have too many bars closing
beyond the ema
then we're adding that filter in our
script as well
and there's just a few ideas for you to
play around with in your own scripts
to add some ema filters to potentially
optimize your strategy scripts
or your setup detection indicators if
you have any questions
shoot them to me otherwise i will see
you in the next lesson good luck with
your trading good luck with your coding
speak to you soon have a great day
if you found this video helpful and you
want to learn more about pinescript head
over to panscriptmastery.com
i have an advanced course there with 70
plus lessons
covering pinescript from the basics all
the way up to more advanced topics such
as strategy scripts
and complex indicators and if you don't
want to pay for anything that's fine
i've got a free course there as well
that goes into great detail about the
core fundamental
concepts you need to know in order to
use pine script effectively
so i'd love to see you there go and
check that out if you're interested in
that otherwise hang around
hit that subscribe button and i'll be
back with more free content
really soon thanks for watching i'll see
you next time
you

PineConnector TradingView Automation MetaTrader 4 Setup Guide

what's up Traders I'm Kevin Hart and in today's video I'm going to be showing you how to install Pine connecto...