Showing posts with label a. Show all posts
Showing posts with label a. Show all posts

Sunday, 20 October 2024

Pine Script [OUTDATED V4] Tutorial Lesson 8 Using The Security Function & Higher Timeframe Data

a traders welcome back to another pine script tutorial today's tutorial is going to focus on the security function in order to use higher time frame data so the example I'm going to use today is implementing a higher time frame EMA so what we're going to do is we're going to access the 50 day EMA on these intraday time frames so on this four hour chart when we're finished it will be plotting the 50 day EMA as opposed to the 50 standard EMA so let's get straight into this one it's going to be called less than 8 today because that's what we're up to the first thing we need to do is set the overlaid to true so that this will draw on to our charts the next thing we need to do is get some user input so the first input I'm going to get is the time frame what time frame do we want a reference so this is going to be called EMA time frame it's going to be a type of input dot resolution we're working with resolution here which is which means time time frame and the default value is going to be D for daily chart you could also set this to 1440 which is 1440 minutes 1440 minutes is one day otherwise just use D for short the next input is going to be the EMA length so MA length and a type of integer integer and the default value is going to be 50 typos everywhere today all right the next input is going to be whether or not to color this EMA now this will make more sense later but what basically what this is going to do is if price action is above the EMA the EMA will be colored green and if price action is below the EMA to be colored red this is just something I like to do with my indicators the ones that use emas so red obviously means I'm looking for short trades and green means I'm looking for long trades and so I'll show you how to do that in this tutorial today as well so this will be called color EMA and it'll be a type of input bool boolean and the default value is gonna be true last but not least is going to be our smoothing function now I'll explain this one later when we actually have the EMA plotting to the chart but this is going to also be a boolean input so input title equals smooth type whoops type is input bull and this one is going to be set to true as well I'll save that and we'll move on to the next bit of code which is going to be get actually getting the EMA value itself so I'll call this calculate EMA and we'll begin here by establishing an EI EMA variable so this EMA variable is going to be set to the inbuilt EMA function if you hover your mouse over this it'll tell you what you need to input in order to get a return value and this EMA function takes a source and a length source is high low close that sort of thing length is obviously the period length of the EMA so we want to calculate this EMA based on the closing price and it's going to be a length of Len of our variable we created here so a default of 50 the next thing we need to do is get the higher time frame EMA so we're going to basically plug this liner code into the security function in order to use this to calculate this EMA value based on the daily closing price or whatever time frame you set in your resolution input so we're going to get to email use here and this is gonna be a little bit complicated to explain but I'll do my best basically when you're calculating a higher time something like a higher time frame EMA you've got to remember that if I go down to a one-hour chart for example there's 24 one-hour bars in a day 24 one-hour bars make up one daily bar and so there's gaps between the star of this 24-hour period and the beginning of the next four-hour period there's gonna be gaps in price data on that higher time frame and so what we're going to do in order to compensate that is we're gonna have to EMI values one is going to compensate for that value and the other is not so basically one is going to be a smooth higher time frame EMA value and one is going to be a stepped higher time frame EMA value so this will make a lot more sense when this is drawing to the chart so let's just write the code first and then I'll come back to explaining what's happening so the first EMA value are going to get is the smooth EMA value and we're going to assign this one this variable to the security function and now I'll explain what goes into this one if you hover your mouse over the function name it will tell you what inputs it takes and it outputs whatever it needs to floating-point numbers like price price data integers boolean's color which I believe is candlestick color today we're going to be working with the float because we're going to be calculating an EMA value which is a float because it has decimal point numbers just like price action does because it is a an average of price action values the first input this thing takes this function takes is what's symbol do you want to calculate this data on so you can actually use this to reference other symbols so you could reference and we're on Ozzy CAD here Australian dollar versus Canadian dollar but you could reference the euro dollar or or a stock commodity whatever you feel like so I'm not going to go into detail about that in this tutorial this is just introducing you to the security function but in future tutorials I'll show you how to reference other markets today is market we're just going to reference the current symbol so we need to write in here sim info which is short for symbol info press control space and you get a list of of variables you can you can grab from this basically this this collection of instrument data and so out of this list we want ticket ID and this will give us the Australian cat AUD C ad and I believe it will also get it from the same brokerage so so whatever broker you're on it will get the price action data for the symbol you're on from the same broker which is important obviously because different brokers have different price data and so you want this to be consistent with the symbol you're referencing on your charts so trading view takes care of that all for you just by this little happy little line of code here to reference Bob Ross but the next variable we need to input here is the resolution what time frame are we referencing and we can just reference our time frame important from up here so just type in res sorry I could have taken lots of breaks between writing this out because my neighbors are redoing their lawn and there's someone out there shoveling a whole lot of gravel I don't envy them today that's a harder job than writing code that's for damn sure so the next input variable we need to get we need to plug in to this security function is it's called expression here you can see expression is a third input basically this is any expression any line of code and so we're going to be plugging in this here into into this expression slot or whatever and what this is saying is on the current symbol ticker ID or Z CAD on the current time frame or that are on the reference time frame the daily time frame it's saying tradingview please get us the EMA variable from this information so this will be the daily clothes on the daily chart and we'll be calculating a 50 period EMA with that information but we're not quite done yet we also need to plug in the gaps variable and the look-ahead variable and I'll explain what those do next so the first one is gaps and we're gonna write in here bar merge dot and press control space and that will show us the available variables for bar merch basically if you put bar merge caps on what that will do is remember I said that there's 24 one-hour bars in a day well this will merge the gaps between the start of the day and the start of the next day and basically what that will give us is a an average of the average we're going into EMA inception here and we're calculating a average of the EMA the exponential moving average and merging the gaps between price action so again that'll make more sense when you can see it on the chart so for this one we're just going to write gaps on so we're turning bar merge on emerging the gaps of any price action gaps on the higher time frame we're turning that feature on the next input is an interesting one as well this is the look ahead so if I type bar merge dot control space we have look ahead on or look ahead off basically what look ahead is is that in historical data when you're referencing a higher time frame pine Script obviously has access to the days closing price the current days closing price so right now the day daily chart hasn't closed on this time frame so if you were to turn this to look ahead on it would be referencing the current days closing price and that's how you would run into what's called repainting issues I'll get into that in another lesson because it's a little bit advanced for this stage of this this course but basically in layman's terms what that means is that if you set this to look ahead on throughout historical price action the script will be able to look into the future to see what the day's closing price was before the day would have closed in live action so first of all there's all sorts of reasons why you would want the script to be able to cheat and look ahead but I'm not gonna go into them today I'm just gonna say that for the most part for most scripts that you create it's probably safest to just turn look-ahead off so this script is going to merge any price action gaps between any missing price action gaps and it's going to not look ahead and basically when you turn this off what that means is that instead of on historical data instead of referencing the days closing price and cheating seeing looking ahead to see what the day's closing price was it will simply reference the previous day's closing price instead which in this case for the purposes we're using this higher time for an EMA for is exactly what we want so we'll leave that off and the next step in this tutorial lesson is to create the EMA steped version and then I'll will plot these to the chart and it'll make a lot more sense what these to do so again we're going to reference the security function we're going to do all the same here we're going to reference the same symbol that we're currently on the same higher time frame setting the same EMA expression the only difference on this line of code is that we're going to set Bar merge gaps off and the BOM merge look-ahead is also going to be off so literally the only difference between these two lines of code is that this one has gaps off and now we can plot these two variables to our chart so let's do that here now we don't want to draw both of these EMAS at the same time which is why I have this smooth setting here so whether this is turned on or off we'll determine which one of these EMA is we draw it to the chart so this is going to be a little bit of a messy line of code but I'll explain it as we go first thing we're going to use is what's called a conditional operator if you're not sure what this is just go back and go through my previous lessons where I explain in detail how this works but this is like an if if or else statement so we're going to say if smoothing is on if this smooth bullying is set to true in the settings menu then we want to draw the EMA smooth otherwise if this is set to false we want to draw the EMA step value then comma for that the next function setting for this this plot function is going to be the color what color are we going to draw this EMA at and that's where this color variable boolean comes into play or you want to say if we're coloring this EMA then we want it to be green if the current closing price on this time frame is above our higher time frame I'm gonna use EMA step for this and I'm not gonna explain why but that'll make more sense if you if you go over this lesson a couple times and you and you really think about what these two lines of code do but anyway here we're going to stack two conditional operators on top of each other so we're gonna say if the color variable is turned on this boolean is set to true and the if the closing price is above the higher time frame EMA then we want to set the color to green otherwise if color is set to true and the closing price is not above the EMA higher time frame EMA then we want to set the color to red and then we'll draw another semicolon here otherwise we're just going to paint it black as the rolling stones would say I'll just go over this one more time because the nodes would be confusing to look at but what it's saying is if the color variable is set to true if the user has set this boolean to true this check box is ticked and the closing price is currently above the higher time frame EMA then we want to set the EMA color to green otherwise if it's the closing prices below the EMA or equal to it then we want to set it to red and if this color variable input variable is not set to true meaning the check box is not ticked then we're just going to paint it a solid black color and that's it for this section now we're just going to set the line width to two so that it's just a little bit thicker I feel that that works better on EMAS especially a higher time frame EMA and we're going to title this plot function so that our users can go into the settings menu and change these colors if they want to so I'm going to say EMA in brackets hiya time frame and that's it for this script basically we can hit save and add to chart hopefully there's no errors doesn't look like it add to chart and there we have it it's now plotting to the chart but because we're so zoomed in on this one hour time frame we can't see it so zoom out a little bit let's go up to the 4-hour chart and here we have the higher time frame EMA 50-day EMA being drawn to our 4-hour chart but we do have smoothing turned on so if we come up to here and we turn smooth off now we have our stepped 50-day EMA and so I'll just quickly explain this stepped EMA again now that we can see it on our chart and that'll be the end of this lesson so we go down the one-hour chart zoom out a bit if I count the amount of bars between each step you'll see that it adds up to 24 so during this whole day of price action the EMA was one solid value and this was the previous day's 50 EMA value based on the closing price and this is exactly what we want if you're going to use this information to trade off this is what you want on your chart and now this script isn't quite perfect if I am if you look up here you can see that it's it is actually repainting it's still repainting even though we set look ahead to off I'm not going to go over how to fix that in this in this lesson because it's it's quite a detailed process and the lessons already long enough but this is the gist of what you would need to do in order to achieve working with higher time frame data using the security function in future lessons we'll do other things like drawing the higher time frame high or low but that sort of thing but this is a great introduction to the security function and what all the variables do and so yeah this if we turn this to smooth if we turn the smooth function on you can see that it's merging the gaps and so we're not getting that stepped effect but but this is an inaccurate 50-day EMA reading looks a lot better looks cleaner on your chart and it could be useful for things like just performing general technical analysis on your charts but if you wanted to use these levels to trade off it would be much better to have this depth version on so that during this day you are referencing the previous previous days 50 EMA value instead of the current days 50 EMA value which really we won't know until the end of the trading session and that and the current daily chart closes so yeah that's it for this lesson I hope that made sense if not leave a question in the comment section and I'll get back to you as soon as I can if you found this lesson helpful please subscribe to the channel that there's a lot of motivation to continue making these videos and I'm glad to be able to help you guys learn this new skill and just before I leave I just wanted to let you guys know that there is a lot that goes into creating complex and practical useful Pyne script scripts and indicators and so I'm considering creating a very in-depth advanced plan script course for you guys going into detail maybe going over how I create my own indicators my own complex indicators such as my ultimate pull back indicator which I actually used to trade the live markets forex markets and this is painting pull back signals to the charts so you can see it's it sends me an alert telling me when to go long or short tells me my stop-loss my target placement and you can see it's had a couple of winning trades here I'm considering teaching you guys exactly how I made this sort of indicator the catch is this information is quite valuable it took me a long time many many many hours of work to get something like this working and I don't really feel comfortable giving away all of my secrets for free so I'm considering creating a premium pine script course where I'll go into much more detail about how to practically apply all of this information and I'll make it affordable when it is finished and by the end of it you will be able to create your own strategy scripts your own indicators and tools to aid in your own trading and so over the next few maybe months I'm going to be working on that and building that and making that as great as I possibly can and I'll let you guys know when it's ready and for those of you who really want to take this to the next level that'll be a great resource for you guys to really enhance your edge and in that course I may even include a mentorship option where you can get one-on-one access with me and ask me questions and I'll help you to create your own scripts because right now I'm getting a lot of questions from traders and coders and I just I really don't have the time to help everyone and so I'd love to offer a service where I can help you guys but obviously with the amount of time I spend on my own trading and content creation I just don't have the time to do that for everyone so I'll have to find a way to prioritize that and maybe the core students can get that priority and so if you're interested in that I'll leave a link in the video description to sign up to my PI inscript mailing list and anyone who signs up before the course is released I'll send out an email to you when it is released and I'll give you a significant discount on the opening price for supporting me and for pursuing success and being proactive about your trading because I respect that and I will reward that where I can so we'll speak to you guys in the next lesson good luck with your trading best of luck with your coding keep at it I know this stuff can be confusing and it takes time to learn but it's extremely extremely valuable information to master and once you do you will be able to take your trading to the next level completely and possibly even automate your strategies that'll be another thing I'll cover in the paid course how to use third-party api's to automate strategy scripts so take it easy everybody I've enjoyed this time with you I hope you did too and I'll see you in the next lesson good bye [Music]

Pine Script [OUTDATED V4] Tutorial Lesson 1 Introduction Hello World!

a little hey guys this is Matt and
welcome to my trading view pine script
guide for beginners in this video series
I'm gonna cover topics regarding pine
script which is a trading view
programming language it's a very basic
programming language but it can allow
you to achieve some pretty powerful
stuff I've been using the scripting
language for a couple of years now I use
it to create trading tools that assist
in my trading process now pine script
doesn't allow you to automate your trade
execution or trade management unlike a
language like MQL but what it does allow
you to do is automate a significant part
of your trading process such as analysis
stop-loss sizes trailing stops setup
detection all kinds of things and so
basically the way I treat pine script is
I use it to be my second pair of eyes on
the market for the most part I either
use it to create scripts that send me
alerts so I can stay on top of the
market I use it to create tools to help
in my back testing process that's a big
one and overall I've just found that if
you can master the basics of pine script
you can dramatically increase your edge
over the markets we live in a world
where technological prowess and
understanding technology and and
computers and programming languages is a
very valuable skill to have now when I
first started learning how to code I was
probably 16 or 17 I used to make
computer games I'm embarrassed to admit
this but I used to make runescape
private server right up until the
creator of that game try to sue me and
shut down everything I was working on
but I had a lot of fun with that and
I've always had a passion for computer
programming
I started out learning Java which is an
intermediate programming language and I
got quite good at it but over the years
I've lost that skill because I haven't
practiced it enough but thankfully I've
moved over to Pine script now which
is very similar to a lot of programming
languages that are out there but it's
also very lightweight it's very simple
very easy to pick up very easy to learn
you don't need to be an expert in
programming to learn this stuff and I'm
excited to show you what's possible with
Pyne script in this guide so without any
further ado let's get into this stuff
I'm going to assume you have zero
experience with programming or and
specifically Pyne scripts so if you're a
little bit ahead of the beginner stages
you might want to skip this video and go
into more advanced topics but if you're
new to this stuff this is going to be
really important to learn so first of
all you want to take this mouth of yours
come all the way down here and click on
the pine editor this will open the pine
script editor and this is where the
magic happens now this is the default
script everyone will get this when you
open this for the first time and I'm
gonna run you through each line of code
here and just tell you what it does so
that you have a basic understanding of
what you're looking at so this first
line here is just a bit of legal jargon
it associates the Mozilla public license
with any code you create and basically
that's just like an open-source license
I'll go into detail about your options
later down the track in terms of keeping
your scripts private and protecting your
source code if that's something you you
want to do but for the most part if
you're anything like me you'll want to
release most of the things you create to
the public and so this this license here
will just protect you from nefarious
actors on the Internet that's just a
standard tradingview precaution and here
you'll get a little copyright symbol and
then your training view username these
these two lines here are what is
referred to as comments you see these
two forward slashes at the start of this
line what that is saying is it's telling
pine script it's telling the interpreter
or the compiler which is a fancy word
for a computer translator so all of this
English language code needs to be
translated into a language that the
computer understands that's all done for
you that's the magic of being a program
in the modern day is you don't have to
know what's going on behind the scenes
in order to code many years ago you had
to write in what's called assembly code
and it was an absolute nut you had to be
a NASA level intelligence in order to
achieve anything meaningful with that
language but today
even a monkey can create if I can create
some of the scripts I've created with
this then you'll be amazed of what
you'll be able to achieve because I'm
hardly a rocket scientist I come from a
music background I was a musician before
I became a traitor and I was a dabbler
in programming languages but now I have
a pretty firm grasp on this stuff and if
I can learn it you guys can too so I
hope that's encouraging to you but
anyway these two lines here it's telling
the computer interpreter to ignore these
lines these aren't relevant to the
script this is for human eyes only you
can use these comments to say whatever
you want for the most part it's used to
either explain what your code does or to
leave notes for yourself or you can
comment out certain lines of code that
you don't want to delete because they
might be valuable later down the line
but maybe you're dealing with some bugs
and you want to isolate what's going on
you can just comment out a couple of
lines of code and using this in there
and the script will you just ignore
those lines but for the most part you'll
be using comments to leave yourself
notes or leave notes for others so you
could say something like the script is
for teaching beginners how to use pie in
script simple as that the interpreter
the compiler will ignore this line but
you know exactly what it means and
that's very valuable when you start
creating extremely complex scripts I
have a bunch of scripts that I've
written in the past that I have no idea
what they do anymore because I didn't
comment them heavily enough so this is
something this is a good habit to get
into in the beginning this third line
here even though it starts with two
forward slashes it's technically not a
meaningless comment it's not it's not a
comment that's ignored by the compiler
but it's also not a part of my own
script code what this does is it tells
the compiler what version of Pyne script
to target so the best example I can give
is is the English language we have Old
English from many centuries ago which
you know Shakespearean type English
which isn't appropriate for today's day
and age and if you were to talk that way
you wouldn't make friends very easily
and so that's an old version of English
of the English language and today's
version is for 2.0 English 2.0 and it is
colloquial it's easy to understand
there's a lot of slang that sort of
thing
and so you could think of Old English as
version one and if you were to speak in
that language hardly anyone would
understand you but there's times where
that's appropriate because maybe you're
studying Old English or you're trying to
write something in that context
but for the most part you'd want to use
the latest version obviously and it's
the same at pine Script so pine script
has version one two three and now it has
version for each variation of these pine
script versions have different features
different syntax different syntax is
another word for grammar basically its
programming jargon for grammar so commas
brackets that this is syntax in here you
know you've got the two quotes and you
got brackets that's referred to as
programming syntax if you change this to
version 3 there'll be certain features
of pine script that you wouldn't have
access to anymore so for the most part
you can just leave this line you'll want
you'll unless you're working on an old
script that's the purpose of this is to
allow for backwards compatibility with
previous pine script versions for the
most part you're gonna want to leave
this as it is because you're going to
want to work with the latest version of
pine script obviously if you want access
to all the latest features and bells and
whistles then you're gonna want to leave
this as version 4 now moving on this is
where things get a little more
interesting a little more complex so
this first line here dictates what type
of script this is going to be now
there's two types of scripts that you
can create in pine script one is an
indicator like any other indicator you
would have seen like RSI MACD moving
averages that all falls under indicator
the other script option is a strategy
script now a strategy script is used for
back-testing strategies over historical
data automatically I'll show you a quick
example of one of the strategies scripts
I've created so here you can see that
the script places market trades so you
can see it went long here at the close
of this candle and exited for a profit
at the profit target and now adding up
all of these over about 208 trades over
the past year or two of data it had a
53% win race so 53% of these trades hit
target before they hit their stop-loss
so this is quite advanced we'll go over
this stuff much later in the course but
I'm just showing you what this strategy
script is for for the most part we're
going to be working with standard
indicators so to write a standard
indicator script you need to name this
study now this line here is sort of like
a letterhead you know on a letter you
would have something at the top of the
page explaining what the letter is for
or who it's intended for that's what
this does for the pine script compiler
it tells a pine script compiler that
this script or writing is an indicator
script not a strategy script and so the
two scripts get access to entirely
different features we don't want to be
working with any of the mock trade
features so we're just gonna leave this
as it is for the next few videos and you
can name this whatever you want I'm
gonna call this beginner script just for
an example describing this next line
will be easier basically add to chart
you'll see that now this this blind plot
is telling the script to draw the
closing price to my screen and it's that
simple
from three lines of code you can delete
these if you wanted to and this will
still work and there you go three lines
of code and we're already drawing the
beginnings of an indicator I'll show you
one more thing before I wrap this up and
then we can move on to the next video
where I'll go into much more detail
about the code part of this if you just
simply add this line of code in here oh
this is saying set the variable called
overlay to true and true this is called
a boolean it's a funny word you'll get
used to it but it's called a boolean in
programming and that's just another
fancy word just like how lawyers have
their own jargon as you would know the
financial industry has its own jargon to
make things overly complex so that only
other financial experts can understand
it programming is exactly the same
there's a bunch of jargon terms that
only other programmers will understand
and boolean is one of them all it means
is that yes or no 1 or 0 it's pretty
simple so this little line here is
saying set the inbuilt
variable overlay to 1 / yes / on /
now if I remove this from my chart save
it and then click Add to chart now we'll
draw the line it's a bit hard to see but
you can see it draws the line on to the
actual chart instead of to its own box
now this is obviously really useful for
drawing moving averages or like some of
my scripts this script is an overlay
script and it draws directly to the
chart you can see it draws a moving
average in a bunch of signals and
stoploss placements targets I'm gonna
show you guys exactly how to build
something like this and this is the
beginnings of that and so that's it this
lesson I hope you found it interesting I
hope you found it useful and strap in
because we're gonna get into much more
complicated stuff than this in the
videos to come alright thanks for
watching everyone thanks for listening
good luck with your trading good luck
with your coding and I'll speak to you
in the next video
[Music]
[Applause]
[Music]
you
[Music]

Pine Script debug PRINT LOGS are finally here!

Pine script finally has a console that
we can print stuff to I mean this is
this is a dream come true for me I've
been coding in pinescript since uh 2017
and I have dreamed of this day for years
I mean it's such a basic feature of any
programming language that is so
invaluable for debugging your scripts
and figuring out why it's not doing what
you wanted to do which is let's be
honest more often than we'd like and
oftentimes depending on the complexity
of your script it can be quite difficult
to figure out what the heck is going on
under the hood and what you have
overlooked in your code this new feature
helps us figure that out so let's go
over some of the uh the words here so we
now have a new log function I love the
Simplicity of this it's very easy this
will be a short lesson or video because
it's not rocket science this new feature
thank goodness it's really easy to use
if you've been following following the
channel for a while you'll know that I
recorded a video a few weeks ago or
months ago you're now demonstrating a
script by he who must not be named a
prominent Pines scripter who created a
table that did this functionality it
printed logs onto our chart the catch
was there was a table on our chart and
you can't copy text out of a table on a
training view chart and so you could
display the text but you couldn't do
much with it you definitely couldn't
search through the logs which you can
now so this new feature is incredibly
useful so we now have three new
functions log dot error log.info and log
dot warning and they have a screenshot
here the gray text is a log.info the
yellow text is a log dot warning and red
text would be a log dot error there is
no difference between these three other
than the color coding in your Pine logs
now importantly Pine logs work
everywhere they work on historical bars
they work in real time and they work in
replay mode and they can be called from
any type of script so indicators
strategies live libraries and from
anywhere in the script including local
blocks loops and from inside
request.security and similar functions
so let's copy the example code here jump
into the pine editor and I'll break down
what's happening so here is the example
script that they provide in the blog and
what we're doing here is we're just
demonstrating all three different log
types so the first log.warning function
caller here is plotting every 100th bar
index into the logs and first of all I
should probably show you how to open the
pine log console it's pretty simple all
we do is click on this little elliptical
hamburger whatever they call this thing
in the corner here and come down to Pine
logs now I need to add this to my chart
I believe before it will do anything so
let's save this script and add it to my
chart and I'll hide this script here
we'll get to what this is in a moment
just hide these two scripts and open the
pane editor come up to here and then
Pine logs and that's fantastic
thanks Elon Musk my starlink apparently
has a poor internet connection one of
the beautiful things about living in
Australia in Queensland at least is that
we have terrible internet here but
anyway first of all problems right let's
break down what's happening here so we
have every 100th bar index is being
plotted onto my Pine logs here in yellow
because it's a warning log then we have
real-time bar processing here so if I go
to a different Market that's live and we
go to let's go to a one minute bar now
you can see that these varip variables
allow us to manipulate variables on a
real-time bar so if we zoom in here
every time this bar moves or the volume
changes we're going to get a new log
print here this is obviously really
useful for seeing what your script is
doing it's like having a magnifier on
your own code and so now a new bar is
about to start which should get a new
log here now this was an error log so
it's in red
so when a new bar started we error
logged to the console and there we have
it then if the bar is not new and it's
not a historical bar that means it's a
real-time bar and our info log is
plotting uh price information now this
particular script uses a few different
methods for formatting our logs so this
is an expression we can pass in to the
log functions server hold down control
and click on this you can see that we
have the option to just pass in some
text or we have the option to pass in a
format string followed by several
different arguments or parameters so
this is telling the log function how to
format this number same with this here
so we have 0 is our first parameter one
is our second parameter or argument and
two is our third and then we pass in one
two three numbers
but you don't need to do this if you
don't want to you could just pass in
something like this
uh plus str.to string bar index that
will do exactly the same thing but if
you are comfortable with slightly more
advanced text formatting options you
have these options here for quickly and
easily plotting lots of number
information into the log functions the
final thing to note is that this
functionality is only available in
scripts that you have the source code to
and that you have added to your own
chart so if you get a script from the
script library and you try to check the
pine logs they won't be there you need
to have added the script code to your
chart yourself and have access to the
script code in order for this to work at
least for now that's what it says on the
log blog post now next week I have
another lesson planned that is going to
show how to create a multi-time frame
Market regime filter and this script is
also using the new panscript log
function another way to get to the log
console by the way is to hover over your
script click on this and click Pine logs
and here you can see I've done some test
printing here I'm printing when the very
first bar on my chart started so this is
January of 2009 and I am printing how
many bars on this time frame past all
three regime filters so I'll explain all
of that in next week's video make sure
to hit the Subscribe button if you
haven't already the script is telling us
that on this time frame the market has
bullish momentum on 54 of 20 000 bars in
our charts so out of 20 000 bars all the
way back to 2009 this Market the S P 500
has a 54 chance to be trading above its
one week 20 EMA as one day 20 EMA and
it's 4 hour 20 EMA so in other words it
has an objective bullish bias which is
useful to know and obviously you could
display this information in other ways
using pinescript features but it's
really cool to just be able to quickly
print this sort of information to the
log console and just see it and we can
also copy and paste this out of the
console which we couldn't do before so
really powerful stuff we can also search
so
you can type in keywords and it will
search the logs you can filter the logs
you can set a start date to display the
logs I believe there's a 10 000 log
limit so it's useful to be able to
filter your logs so that you can see a
certain time period see what your script
was doing during certain market
conditions you can disable logging here
and you can also search using rejects or
regular expression if you know how to
use that search formatting function but
anyway I think that's all there is to
cover about this new feature we'll
obviously be using this a lot going
forward in certain scripts so we'll come
back to this in future videos but for
now that's how we use this new awesome
simple feature to debug Alpine scripts
I'll leave a link in the video
description and the pin comment below to
the two-part video series I did on
debugging Pine script code including for
loops and functions that sort of thing
obviously if you watch those older
videos just replace whatever I'm using
in there's all videos with this new log
feature these new log functions because
this is much easier than the options we
had in the past it's a lot more
efficient and a lot more powerful
actually before I go I should mention
that there was just a new blog post
released yesterday announcing yet
another new feature to Pine script which
is Maps now maps are very similar to
arrays except that you use a key instead
of an index to reference the members of
this map so I'll explain this in future
videos we'll I'll probably do a video
just on this when I get time
um it's not something I personally use
very often in my scripts but there are
reasons why you might want to use this
for example in this example code here
they put various colors into a map and
you can reference these Colors by their
names instead of um array index number
so it just makes it a little bit more
intuitive to work with certain types of
data or data for you Americans out there
but anyway we'll come back to this in a
Future video just thought I'd mention
this since it just came out hot off the
press so with that said thank you for
watching good luck with your debugging
and your coding and your trading and
I'll speak with you in the next lesson
take care have a great weekend and I'll
speak with you soon

Morning vs. Afternoon Ranges A Game-Changing Trading Revelation

I recently saw a clip on Instagram
posted by SMB capital a very very simple
but often misunderstood trading
opportunity if the range after
12:00 is greater than the range before
12:00 so 9:30 to noon noon to 4:00 if
the range in the afternoon is greater
than the range in the morning there is a
very very low likelihood of continuation
in the direction of the trend a very low
likelihood of that it can happen and
when it happens it happens with intense
magnitude but there's a very low
likelihood of that happening based on
the back testing we've done first of all
I was skeptical about this concept in
this particular example this sample size
is pitifully small and so I thought you
know what I'm going to write a script
I'm going to run it through pinescript
on a bunch of stocks and we'll see if
this hypothesis is true now I just went
over 100 stocks with thousands of range
expansion samples overall out of 100
stocks we had 12 stocks have a 50% or
higher chance of continuation in the
trend after range expansion in the
afternoon so I think it's safe to say
that this hypothesis is true ideally I'd
like to do the full 500 would be a great
sample size but 100 stocks 12 of them
had a chance of 50% or higher and two of
them were right on 50% which is
obviously neutral so maybe we shouldn't
even include those two so in that case
we only had 10 stocks with a greater
than 50% chance of continuing in the
trend after range expansion in the
afternoon so in other words when a stock
trades more distance in the afternoon
than it did in the morning there is a
statistically significant chance that it
will not continue in that Trend the next
day it will not close higher than its
previous day's High that's useful
information to know I'm sure you will
all agree now this is obviously an
oversimplification of this analysis but
if you want to get your hands on the
source code of the script and do more
research yourself or watch a video of me
breaking down the code of that script
check out the pin comment below take
care and good luck with your
Trading

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...