hey friends welcome back to another plane script coding lesson my name is matthew from zen and the art of trading and today i'm gonna be showing you how to use the ATR indicator in your scripts so in the previous lesson i showed you how to use the RSI indicator to create overbought and oversold signals in this lesson I'm going to show you how to use the ATR indicator to create a trailing stop so we're just going to draw onto the chart our trailing long position stop and a short position stop I'm going to do it this way because it's just a lot more simple to demonstrate the logistics behind using this indicator in your scripts but in future lessons I'll come back to this lesson 6 script this RSI script and I'll show you how to plot your stop-loss and target placement so say you wanted to go along here after the RSI went oversold then we got a bullish engulfing candle so you want to have a 180 our stop loss and a 180 our target then you can actually plot these values directly to your chart using pine script but today's lesson we're not going to cover that I'm just going to keep it simple we're gonna delete the script I'm gonna start a new blank script and I'm going to call it lesson you guessed it seven keeping it really simple for you guys here alright so the first thing we need to do is set our overlay to true now overly to true if you if you set this to false then if I save this and add it to my chart it'll draws an oscillator box so now we're plotting the price we have a line chart that is separate to our main chart so that's useful when you're creating oscillator indicators basically like the RSI stochastics when you're working with those sorts of those styles of indicators but today's script we're going to be drawing directly to the chart so that I can visually represent the information I'm going to show you so if I click Save there delete this script and add this back to my chart we now have the closing price plotted directly to the chart so let's get straight into this one so first thing we're going to do is we're going to get inputs from the user because it's always useful to be able to adjust these values on the fly the first thing we're gonna want to get is the ATR length by default this is usually 40 a 14 period ATR so we'll leave that as the default setting but it's also great even creating scripts especially to release to the public it's always considered good etiquette to include as many options as you can for customizing the scripts so I'm gonna get in get you guys into that habit early on and so we're gonna call this 180 our length and we're going to have a type of input integer it's gonna be a whole number we're gonna have a default value of 14 and a min value of 1 might as well this isn't necessary but the ATR length can't be calculated beyond a 0 or negative value so might as well get into a good habit of using this min Val function as well or feature the second input we're going to use is a boolean and we're gonna call this one use structure so I'll explain what this does later first of all let's just code it in so we're gonna say use structure I like to put question marks on the end of my boolean inputs just out of habit you don't have to do that the default value is going to be true in this case this is going to be used for detecting swing lows and swing highs to trial stop-loss the alternative method is to just have a 180 R or whatever multiplier you want of the a TR from the closing price so that'll make more sense later I'll explain that later on so we're gonna have two more inputs the next one is look back this is for the structure look back so title is how far to look back for high-lows and we're gonna make this a integer as well because it's gonna be a whole number and we're gonna set a default value of 7 so we're gonna look back seven bars for swing high and swing lows the min value be 1 as well on this input and then we're going to create one more variable called the ATR stop multiplier and I'll also explain what this does later this will make more sense later I just like to get these inputs out of the way early so we're gonna say ATR times question mark and this one is going to be an input dot float it's gonna be a floating point variable and if I just quickly add the ATR indicator on to my chart you'll see why that is see if I hover my candle my cursor mouse cursor over any of these bars the it'll show you down here in the left-hand corner of this indicator this oscillator box it will show the ATR value and that's obviously a floating-point number it's not a whole number it's got a decimal point zero point zero zero zero one six is one point six pips I'm on the 1-minute chart here if you're wondering why the ATR is so low I just figured that the one-minute chart would be the best time frame to demonstrate this technique on but this script will obviously work on all time frames so for this one we're going to have a default value of one point zero so we're going to have a default value of a one ATR stop multiplier so whatever the ATR indicator is giving us that will be our stop loss so say above this swing high will have a one ATR stop above this swing high we don't need to set a minimum value for this but might as well while we're here and I'll set it to zero point one if you're going lower than a zero point one ATR multiplier then you might as well not use this at all so that's all of our inputs we're going to be using today so now the next step is to calculate the data that we're going to be plotting to the chart so we'll call this comment calculate data just for our own reference and the first thing we need to do is get the current ATR value so we're going to call this variable ATR just keep it simple I like my scripts to be as simple as possible we'll call it ATR and we'll use the ATR function to get the current ATR value with our specified ATR length so this by default is 14 that's the that's what this see 14 RMA is giving us a default AGI reading and so we'll this line of code here so these values will be identical and I'll show you that right now actually if we click the save and we look up here that at the top left of the chart you can see that those numbers are identical so we're plotting a 0.2 for now fit ATR it's the same on both indicators so that's good let's move on to now calculate our stop losses so our long trailing stop is going to be plotted below price and that's for long position so if we were to have gone long here then it will plot where our trailing stop should be which will be 180 our below the most recent swing low so let's type that in long stop is set to and then this is going to get a little bit complicated here but it's not that crazy it's just gonna be a bit confusing to read so I'll explain it as I go but we're going to use the conditional operator again and this just saves space in our code and we can put all of this if-then statement into one line of code so we're going to say use structure question mark if we're using structure if we've ticked YES on this you structure input then we want to calculate the stop loss based on the lowest low over our look-back period otherwise if we're not using structure then we just want to use the closing price so this line of code here now does two things if we have this ticked as true use structure is true then we're going to search back seven candles that's the default value of our look-back variable we're gonna look back seven bars and we're going to find the lowest low in those seven bars so in this case that would be this low in here and then we will calculate the stop loss as one eighty are below this swing low so the way we do that is we're gonna - because our stop loss is below price we're gonna - this lowest low or this closing price by the ATR value which is here but we're not just going to do that because otherwise we can only use a standard 180 our trailing stop what if your user wants to have a two ATR or three ATO or half ATR trailing stop well the way that you achieve that is by timesing this value this calculation by our ATR stop multiplier so if I type that in there we now have our trailing long stop so if I just quickly I'll just demonstrate what this looks like so we'll type in plot our long stop the color is going to be color dark green it's going we're going to use a little bit of style here we're gonna say style equals plot style underscore line break line be are the short for line break then we're going to call it we're gonna title it long trailing stop we're going to set the transparency to zero we don't want any transparency on this if I hit save here you can see we are now plotting our trailing stop and it's plotting 180 are below the lowest candle or the lowest low of the past seven candles so say you wanted to use a standard trend following technique and you wanted to trail your stop-loss below the low of the pullback preceding the breakout the most recent breakup so in this case it would look like this we have a swing high here a couple of candles pullback then we break in close above the swing high on this candle here if you were to hold your mouse cursor over this candle look back seven bars the ATR indicator over this candle here this trailing stop will be plotting the lowest low below these seven bars so on this one-minute chart you might want to make these look-back period a little bit shorter than seven bars because you can see here that that's that would put you on this bar here which is lower than the swing low of the pullback but let's just say we hover our mouse over this here this will give us the trailing stop value so say you went long down here on this bullish engulfing candle and you had a 180 ah stop below this entry which would put you around here somewhere and say that when this breakout happened you wanted to trail your stop-loss up a little bit you would move your stop-loss you'd hover your mouse over here look for the value which up in the top left here is zero point six zero three eight eight so you would help bring your your stop-loss up to this green line here and so that's how this indicator would work in practical terms but that's not important for the demonstration so let's just continue onwards now and we'll draw the short trailing stop so the short stop is going to be set to use structure question mark are we using structure if we are we want to use the highest high over the pier over the look-back period as our reference price otherwise we won't just want to use the close and because this is a trailing stop that is above price action we've won the plus we want to add to this value so we're going to add the current ATR times our ATR stop multiplier so by default this is set to one so this is just one ATR but as you can see if you want to change that to say - ATR that will widen your stop-loss or a zero point five ATR which is why we set this to a float not a whole number we can set it even tighter it's up to you that's a matter of preference so now we've got that we can now plot I'm just going to copy this line of code I'm going to plot our shortstop and the shortstop's going to be colored red everything else can stay the same we'll change this to say short trailing stop click Save and it will now plot our short trailing stop above price so if you had word to have gone short up here on this little double top up here maybe you had a 180 our stop above the high then as price went into your favor you were just simply every time we had a breaking close below a swing low so we had a break and close below the swing low here you'd hover your mouse over that candle and then whatever value you get up here is where you would put your stop loss and so that's a practical way of using this particular indicator this script and so I'll do one last thing before we finish this lesson and that's we're going to keep plotting this ATR indicator but we don't want to actually plot the value if I scroll this right down right down you'll see that it's actually plotting our ATR to the chart we don't want that because it's gonna on some instruments that may draw over price action and we don't we don't want that so what we can do is use the transparency function so what we'll do here is I'll set the color you can set the color to whatever you want I'll leave it as blue in this case I will also title it so that our users of our script can adjust this color and transparency as they wish and we'll set the transparency in this case to a hundred we wanted a hundred percent transparent here we have zero percent transparent because we want it to be drawn to the chart clearly here we don't want to drawn at all if I type that in hit save and now if I scroll right down you'll see that it's not plotting to the chart anymore and so that's the end of this demonstration we now have a trailing stop 180 our indicator so I can you can see if I hover my mouse on any of these candles the blue line up here that's plotting to the top left is the same as the actual ATR indicator in the bottom left down there so we can now remove this and we now have our trailing stop indicator and if account to the settings first of all you can adjust our values here see that we've titled our plot our drawings so that we can actually change the color of these so if you wanted a blue trailing stop and an orange a blue long trailing stop and an orange short trailing stop you can change that in here and of course if you wanted to adjust the ATR multiplier in come up here and have a one and a half eighty our multiplier that'll widen your stop-loss or if you want to change the look-back period of the ATR the ATR length you can change that in here to say calculate the ATR based on the past seven candles instead of the past 14 or you can adjust this so you might want to make this even less of a look-back so maybe three candle look back and now it will detect the highest high and highest low of the past three bars to draw our trailing stop above or below and there we have it I hope that all made sense if not feel free to leave any questions in the comment section I'll get back to you as soon as I can and the reason why I'm making this lesson is less than seven is because the future scripts that I go into are going to use the ATR indicator probably quite a lot so it's important we get this out of the way early and this is the simplest method I can think of to demonstrate how to actually use the ATR indicator on your charts so that brings me to the end of this lesson I hope you enjoyed it please leave any feedback in the comment section any suggestions of topics you'd like me to cover anything I missed or didn't make clear enough shoot me a question I'll get back to you as soon as I can I've been getting a lot of positive feedback from these lessons and it's really encouraging I'm really glad that you guys have finding value out of these lessons and I'm glad I'm helping you guys advance your own trading career this stuff has really dramatically improved my own trading and I'm just super grateful to have these tools at my disposal and I'm really excited to pass them on to you as always if you have any questions head over to Zen in the art of trading comm there's a link in the description I have heaps of lessons over there written lessons and a whole library of free indicators free scripts that I've created myself I've created dozens and dozens and dozens of scripts some of them premium you have to pay for them because they took me quite a long time to create like my my ultimate pull back indicator for example if I throw that on the chart this will just give you an example of what you can achieve when you master this skill so you can see here this indicator is plotting signals to the chart pullback signals so if I turn off lesson seven it's plotting my stop-loss one eighty are above the swing high and my target one eighty are below the entry point and it's using the EMA has changed color based on price action all of this stuff you I'll teach you guys how to do yourself but if you want to skip ahead head over to my website and check out some of my free indicators the source code for my free indicators is readily available so you can go there and use them as reference material if you want to that's it for today see you next time guys take it easy trade green and good luck with your coding [Music] you
Sunday, 20 October 2024
Pine Script V4 A Breakout Strategy
what's up my friends and fellow traders
welcome back to another partnership
video i've got a good one for you today
i'm sorry it's been a couple of weeks
since i posted a video
i've been extremely busy lately working
on my own trading but today's lesson is
going to address a question i got from a
student of my pantry mastery course so
here's the question here from dj and dj
wants to know how to create a script
that first draws the previous days low
and high onto his chart
and then he wanted to do something like
entering a trade i'm guessing in the
back tester system he didn't say that
explicitly here but i'm assuming he
means enter a trade in the back tester
system
with a buy stop order three pips above
the previous day's high a stop loss five
pips below his entry and his take profit
ten pips from his entry so two to one
risk reward
and using a buy stop order above the
previous day's high and i'm assuming
also below the previous day's low and so
that is exactly what i'm going to show
you how to do today so here we are with
a blank strategy script i'm going to do
things a little bit differently today
instead of writing out each line of code
as i go to save time and be a little
more efficient and concise i'm just
going to copy and paste blocks of code
over into the editor and explain what
that code does as we go so as you know
if you've watched any of my previous
lessons the first thing i like to do in
my scripts is get my user input so i'm
going to paste in my user input for this
script here one other thing or one new
habit i've gotten into with my scripts
is just lining up all of these equal
signs so this particular script only has
three user inputs entry pips stop pips
and target pips they're all pretty
self-explanatory entry pips is
the distance from the daily high and low
that we want to set our buy or sell stop
order
stop pips is our stop-loss distance in
pips from our entry target pips is our
profit target our take profit uh
distance in pips from our entry they're
all using the data type float floating
point numbers so they are decimal
numbers meaning we could have 3.1 pips
as our
entry pips if we wanted to and then
finally i'm using the new tooltip
feature of pinescript was not that new
but it was added a couple of months ago
and now we can explain what each setting
does so that when we hover over this
little i information icon
this little tool tip pops up that
explains what that setting does these
settings are very self-explanatory so
let's just move on to the next block of
code which is getting the daily high and
low
so i'm going to copy this code over here
to get these values we use the security
function
when you need to reference either
another market or another time frame we
do that using the security function
the security function takes a bunch of
input parameters i've left
our gaps and look ahead as the default
settings if you want to learn more about
this function just hold down control and
click on it
and there'll be a description that pops
up here and a few examples
but basically all we're doing today is
we're referencing sim info or symbol
info dot ticker id
and that will get the current market
that we have loaded onto our chart
in this case that would be euro new
zealand dollar
from the oanda
price source or data feed so ticker id
would be replaced with a string
that looks like this oanda
colon euro new zealand dollar
if we just put in ticker then it would
just look like that but we don't want
that we want to actually get the price
data from the
exact same market that we've loaded onto
our charts here
then we reference a resolution or time
frame in this case we're referencing the
daily chart you could also put 1440 here
for 14 40 minutes which is a daily
resolution as well but to keep it simple
i just left mine as d next up we need to
reference an expression now this
expression could be anything it could be
an indicator value so for example we
could get the daily ema 50 ema
or the daily rsi value in this case
we're just referencing the high price so
we're getting the high and the low from
the daily time frame on the current
market that we have loaded onto our
chart
pretty simple now we get to the more
complicated part of the script which is
calculating our entry price stop loss
price and take profit price so we'll
copy these in one at a time
the first thing we do is we determine
our buy
and sell point that should say and sell
point uh and it's going to be above
below
the high slash low
so our buy point is going to be the
daily high
plus
our entry pip setting so
3.0 by default
multiplied by 10
because
pinescript deals in points not pips and
so we need to multiply anything dealing
with pips by 10 in order to convert that
into points
and then we need to multiply
our
points
by this symbol info or siminfo dot
minimum tick value and this is just the
last decimal place on our price chart so
it would be 0.00001
obviously depending which market you're
on this value will be different and
that's why we need to do this
but moving on we then do the same thing
for our cell point now one thing i
didn't do here is replace the default
three pips with our user setting so this
is how it should look
that multiplied by 10 multiplied by our
minimum tick
so our buy point is our entry pips above
the daily high previous daily high our
sell point is our entry pips
below the previous day's low
the next thing we need to do is
determine our stop loss and our take
profit so to do that we subtract our
stop pips multiplied by 10 to turn it
into points multiplied by our minimum
tick value and then we subtract this
number from our buy point and then we
add that number to our sell point so for
longs our stop obviously goes below
our entry and for shorts it goes above
so we need to add in the case of our
short stop loss
next up we get our take profit price to
calculate that we do exactly the same
thing as our stop loss except in the
opposite direction and using our target
pips instead of our stock pips so we add
to our buy point our target pips
converted into the correct amount of
points for this market so that's it for
our trade entry data
the next thing we need to do is detect
when a new day begins
and when we detect that new day
beginning we place our stop orders our
buy stop order and our sell stop order
at our buy and sell point now this code
here is a little bit more complicated so
let me just paste in the first part of
it
and go over what's happening here let's
save the script make sure there's no
errors and we're all good
so
next up we check if a new day has
started and we're flat meaning we have
no positions open no trades open then we
want to place a buy stop and a sell stop
above and below the previous days high
and low before we can do that we need to
detect
when a new day begins the easiest way
i've found to do that is to use the
change function inbuilt change function
and then pass it in this time function
that references a resolution or time
frame so this new day variable will be
set to true
if
a change is detected in the daily time
frame and a change will only be detected
on the daily time frame if a new daily
bar
begins
and then i have a bunch of var variables
these are persistent variables that are
stored across our chart so they're not
recalculated on every new bar like these
ones are these variables will stay as
0.0 until we overwrite them
with a different value
and that's what we do next so first we
check if we have a new day
then we want to check if
our strategy dot position
size is equal to zero that means we do
not have any trades open
then if these two conditions are met we
have a new day starting and we have no
trades open then we want to enter our
buy stop and sell stop orders because
obviously if we have a position open
that means we took a trade yesterday
that has not yet hit its stop loss or
take profit and we don't want to enter
any new trades because this
particular strategy is not
a pyramiding strategy it's just a one in
one out very simple
approach to trading daily breakouts so
let's start with our long orders first
let me copy in our long code
so the first thing we do is we save our
long stop loss price
by overriding this var variable with the
current stop loss long and then we save
our take profit price
then we use the strategy.entry function
to place our buy stop order and the way
this works is we need to give it an id
to reference so that we can close this
trade later if our stop or target is hit
then we need to tell panscript which
direction we're trading in so we set
long to strategy.long or you could also
write true here but just to make it more
readable i like to leave it as
strategy.long then to place a by stop
order we use the stop parameter and then
this parameter takes a price
and so we pass in our buy point which we
calculated up here our buy and sell
point which is by default three pips
above the daily high and three pips
below the daily low and then i use
a couple of new parameters that we
haven't covered before in any video that
i've ever done and that is the oca or
one cancels all parameter
so oca name is the name of our one
cancels all group and then the oca type
tells pinescript what we want to do with
this group so this is completely
optional you don't need to add this you
could cut this out if you want to
but i included this just because it was
a good
opportunity to demonstrate this
functionality basically what i'm doing
here or what i plan to do is
when we set up our shorts as well
and it might be easy to show you this
visually so let me copy over my short
entry code which is exactly the same as
our long entry but obviously for the
short side so we're saving our shortstop
and our short target and then we're
using the strategy.entry function to
enter a short cell stop at our cell
point but you can see here that these
both have oca name set to x you could
set this to anything any string just so
long as they're the same string
and the type is set to the same type so
this is a one cancels all order meaning
that if we get filled on a long trade
then our short
entry sell stop will be cancelled in
other words we're only taking one trade
per day so if we get filled on a long
breakout and then that trade either hits
its profit target or reverses and stops
us out and then we
clear or break through the previous
day's low
rather than enter a new short trade
nothing will happen
and again this is optional you could
remove this i haven't noticed it affect
the profitability much at all in my
preliminary testing uh probably because
it's not a common occurrence that the
previous day's high gets taken out and
then the previous day's low gets taken
out it does happen but not that
frequently so this is just for example
purposes just to demonstrate how you can
use the one cancels all in your strategy
scripts so the next thing we need to do
is tell pinescript when to exit these
trades so i'm going to paste in that
code now
so here we are exiting our trade if our
stop loss or our take profit is hit to
do that we use the strategy.exit
function
we give it its own unique id and then we
need to tell it which
order which entry we want to exit so
from underscore entry needs to
correspond to one of our open orders in
this case
we have our strategy.entry with an id of
long
and a strategy.exit with a from entry id
of long so this will exit
this
trade but it will only exit this trade
if our take profit is hit by price
action or our stop loss is hit by price
action
so limit is for your take profit limit
order
stop is for your stop loss order and
then we do the same thing for our short
trades we exit from our short trade only
if our short take profit is hit or our
short stop loss is hit so that's pretty
much it the strategy is written um the
only thing left to do is visually plot
this information to the chart
so that's what i do next i'm just going
to copy this entire block of code in
down here
and i'll explain what we're doing so
it's all pretty self-explanatory we're
just plotting all of the relevant data
for this strategy script so we're
plotting the daily high we're plotting
the daily low we're plotting our buy
price or our long buy stop price
and then we're plotting our stop loss
and our take profit for our long trades
and then the same for our short trades
we're plotting our sell stop price
our short stop loss price
and our
short take profit price and then we're
setting the color of each plot
our daily high and low has a line width
of two so it's just a little bit thicker
stands out a little more and then i've
titled all of these plots so that we can
adjust them in the settings menu under
the style tab so let's save the script
make sure it compiles without any errors
and there we go
open up the strategy tester you can see
that
because we're on a euro yen
and i did set the default quantity value
to quite a high number uh this is off
the scales
i need to come up here and drop our
position size just a little bit
to get more reasonable results here and
we're pretty much done with our script
let's just go over a couple of trades to
see what it's actually doing
here's
a trade here
so when a new day begins
as it did on this bar right here
we start plotting the previous day's
high
and we place a buy stop order three pips
above that high on this purple line so
if i measure that out that should be
three pips
it's exactly three pips you can see that
the strategy tester entered long here
and then exited our long trade at our
profit target which is 10 pips
from our entry and our stop loss down
here was 5 pips so we've got a 2 1 risk
reward profile 5 pip stop loss 10 pip
take profit
and this was a example of a winning
trade now one thing to be aware of is
i'm not 100 sure how the tester system
knows that this trade did not um come up
and fill us on this order and then
decline to hit our stop loss and then
rally to hit our take profit so for
example let's just draw
this
information onto the chart
and then we'll drop down to a 15 minute
time frame
and see exactly what happened here so
let's draw a line there drop down to the
15 minute chart
and have a look at what actually
happened on that day
yeah and just as i thought
this trade did not play out how the
strategy tester thinks it did let me
change the color of these lines
this is our entry this is our take
profit and this is our stop loss
so you can see the price action rallied
here
filled us on our order and then on that
same bar retraced all the way down and
then hit our stop loss before it rallied
to hit our take profit but if we drop
out to the one hour time frame
and turn on our strategy script you can
see that the backtester system
picked this up as a winning trade
and so that is why i'm very skeptical
that this strategy has as high of a win
rate as the tester is telling us it has
and there's really no way to verify
how a trade played out at the moment at
least without doing it manually the way
i just showed you so that is why i'm
always telling traders to be very
skeptical of the backtester system in
trading view
quite frankly i don't like it at all
the backtester system is quite popular
among a lot of traders and you can see
why i mean every trader wants to speed
up their process no one enjoys
backtesting i don't think i've ever met
anyone who enjoyed back testing and if
they do
they're either lying or they're nuts
because it is one of the most boring
things you could ever do
but
this is an example of why you should
manually back test your strategies if
you want accurate results there is no
way to shortcut that process
at least not with pinescript one other
thing to mention is that the strategy
tester is trading a fixed position size
which is not something i would normally
do normally i trade with a percentage of
my account balance so in every single
trade i might risk one percent or two
percent
maximum of my account balance
this tester system doesn't allow you to
do that
instead it is just trading a fixed
position size in this case of ten
thousand contracts
or one mini lot on a hundred thousand
dollar account
so basically our max drawdown and our
net profit are not accurate figures and
so this is a great example of how the
strategy tester can be misleading and so
while the backtester system can be
helpful in identifying potentially
profitable strategies
do not under any circumstances
take this information as accurate it
should only be used as a very very rough
indication of a strategy that might have
potential to be profitable you still
need to manually back test all of your
strategies in order to get accurate
results and again if you're not sure how
to back test there will be a link in the
video description to
a guide i made a couple of years ago on
how to manually back test strategies and
with all that said there are some
strategies that perform a little bit
better in the backtester system
basically the more simple your strategy
is the better as strategies become more
complex the backtester system can give
more and more misleading results but
anyway for those traders who insist on
using pine script 2 test strategies
i hope that you found this lesson
interesting
at least there is a
decent back testing tool here
if you change this to a study script and
remove all the references to the
strategy
functionality we've got a pretty good
indicator here to assist in the back
testing process for a breakout strategy
like this anyway that'll do it for today
i think in my next video i'll record a
example of why the back tester system
on trading view
should be treated with a huge amount of
skepticism
and why when something like this seems
too good to be true it probably is so
this strategy might be profitable but we
can't know for sure unless we manually
back test it because the tester system
who knows how many times this has
happened
over 773 trades
where it gave a false reading
and the trade was filled but then
stopped out before our target was hit
and the tester system never accounted
for that but anyway to be honest um the
more simple your strategy is and
especially if your strategy operates on
candle closes instead of
like limit orders and buy stop orders
like we have here
or like we used here
then the chances of this sort of thing
happening are significantly reduced the
reason for that is say we were trading
daily breakouts but we only entered on
the closing price of this bar the
closing price of this bar would have
factored in that dip below our stop loss
and then rally back up to here
and so this trade would have gone from a
losing trade
into a winning trade just by operating
based on candle closes now the one time
that this does affect
strategies that operate on candle closes
is if your take profit and your
stop-loss is hit on the same bar
uh there is no way to know how the
tester handles that sort of situation
and so a trade that is recorded as a win
might have actually been a losing trade
depending on which price got hit first
on that intra bar price action
so anyway i hope you found this lesson
interesting at least
um
it's a good cautionary tale but it's
also
um i think interesting code and there
are a lot of ways you could use this
like i said if you remove all the
strategy code out of the script we've
got a decent indicator here to assist in
trading breakouts manually and if you
were to forward test this kind of
strategy over a few weeks
or months even you might find it to be
profitable i'll leave it there
thanks dj or daniel for sending in this
question and for all of you traders who
are not involved in the panscript
mastery program if you'd like to take
your coating to the next level or you
simply just want to steal the source
code to every script i've ever written
head over to panscriptmastery.com to
check out some of my courses over there
otherwise i'll be back soon with a free
lesson here on youtube so if you haven't
hit the subscribe button make sure to do
that as well and i will see you in the
next video take care best of luck with
your trading and be careful
using the trading view strategy tester
goodbye
you
NEW PINE SCRIPT V4 FEATURE Group & Inline Inputs
hello my friends and fellow traders
today's lesson is covering the latest
update to the panscript language that
the trading view development team have
added
this new update is a great one it's a
simple one
but it does improve pine script quite
dramatically in my opinion
so this new update now allows us to
organize script inputs
in sections and lines so this is
something i've personally wanted for a
long time because i have a number of
scripts
with a huge amount of settings and it
has always been
extremely difficult to organize those
settings visually
on the user interface so that the user
of my script
can quickly and easily navigate the
settings and keep everything neat and
organized
so this new update is just a simple user
interface visual
change to pine script and i'm going to
show you how we can use this new change
in our scripts to better organize
our settings interface but before we do
that let's read the words
so it says here our latest pine update
introduces two
improvements to inputs the new group
parameter allows programmers to define
a section header for a group of inputs
and the new inline parameter allows
multiple inputs to be joined on one line
using these new features you can
organize inputs more neatly
as we do here for our auto fib
retracement indicator so you can see
that they've
used the inline parameter to merge all
of these
fibonacci settings into two columns
instead of having these laid out all the
way down
on a single column they've also added
the option
to create section headers or titles
so you can see here that this section of
settings
applies to the date range header so
today's lesson is going to be a really
quick and easy one i'm going to jump
into the pine editor load up one of my
existing scripts and we're just going to
play around with these new parameters
and as always i will leave a link in the
video description to
this article here and i'll also leave a
link to the plan script
reference manuals entry for input which
describes
how you can use these new settings
in detail but i'll quickly read this out
to you the inline parameter
is a string parameter and it combines
all the input calls using the same
string or argument into one line
the string used as an argument is not
displayed it is only used to identify
inputs belonging to that same line so if
you apply the same
inline parameter string to a bunch of
inputs in your script then they will all
be merged onto the same line
where possible and the new group
parameter is also a string parameter
this creates a header above all inputs
using the same group
argument string the string is also used
as the header
text so this parameter is displayed on
your chart
inline is not it's just used to identify
which inputs you want to merge on the
one line
so let's jump into the pine editor and
play around with these new
input parameters so here i am with a
strategy script that i wrote
it has a bunch of inputs here as you can
see
not as many as some of my scripts do but
we're going to use this as an example
we're going to
segment some of our sections so this
section up here
is going to be our strategy settings and
this section down here is going to be my
auto view settings this is the settings
i use to
inform autoview how to auto trade my
strategies
and how to calculate my position size
for each trade that autoview takes
i'm not going to go into detail about
autoview in this lesson this is purely
for example purposes
if you want to learn how to use autoview
to automate your forex trading
i'll leave a link to that in the video
description and up
on the right side of your screen right
now will pop up a little eye
icon that will take you to that video
lesson that i did a few months ago
on how to set up auto view but anyway
today's lesson is going to cover input
parameters so let's get into it
so here i have a bunch of inputs bunch
of user inputs completely
unorganized we can now use the group
parameter to specify which inputs we
want to belong
to each group that we define so here i'm
going to just call this
strategy settings and now if i save the
script
and we come up to the settings menu you
can see that we now have a header here
that says strategy
settings but i've only applied it to one
input parameter so far
if i were to apply this to multiple
input parameters they would all fall
under this header
and that is one way we can separate our
script settings
using this new parameter so let me copy
this bit of code here and
paste it over all of these input
parameters
now all of these ones here are for auto
view all of these settings here
are for the strategy script so now i can
paste
this group parameter into these other
input variables
and we can change this to say auto view
settings
and now i copy this bit of code and
paste it over these few settings
and i save the script now when i come up
to the settings menu
you will notice that all my strategy
settings are grouped together
under one header and all of my order
view
settings are grouped together under one
header so on your more complicated
scripts that have
many different types of settings you
might have a bunch of candlestick
filters or candlestick patterns your
script wants to detect
like for example my ultimate
pullback indicator i need to go back and
modify the source code to the script
to include these new group parameters
and inline parameters because if i open
up the settings to this script
you'll notice that i have dozens of
settings here
and i have grouped them myself using
check boxes blank check boxes that do
nothing
but i can now use this new group
parameter to create a header
for all of these different various
script setting
sections so for example here i have a
section
that determines what my candle patterns
will be
so using the new group parameter i can
group all of these check boxes
under a nice neat header that isn't
as messy as using these blank check
boxes
so hopefully now you can see the power
of this new update
but let's get back to our script and
i'll show you how the inline parameter
works
so the group parameter is extremely
simple by combining the same group
parameter for all of my inputs
that groups them all together and the
group string is also what is displayed
in my settings menu the inline parameter
is a little bit different
it is not drawn onto your settings menu
and it can be named anything
so i could just write a one here if i
wanted to i can copy this
paste it there and now when i come to
the settings menu after i save my script
these two inputs will be merged onto
just one
line so let's save this script and i'll
show you what i mean
there we go come up here now these two
inputs
are on one line and this inline string
doesn't really matter what i call this
and that's really it it's quite a simple
update but it's very powerful
for organizing your script settings and
something that i've personally been
waiting for for many years now three
years
i could have used this feature and then
finally added it to
pine script and it is going to help a
lot with making your scripts look more
professional
more organized now the inline parameter
will
only merge as many inputs
as it can fit into your settings
screen so if i were to add another
inline here
to the next input here and save the
script now if i come to the settings
menu
these will not all be merged onto one
line but instead
they are just grouped together a little
bit closer however one thing you can do
is just put in a blank title for these
settings and that will group them all
onto one line so if i just backspace
all of this and save the script let me
come up to the settings menu
now all of these boxes are on one line
but they don't have a title explaining
what they do
but depending how you set up your script
maybe this would be obvious to your
script user you could use the header
title to explain what these three
boxes do and it's just a way to better
organize your script settings
one other thing i need to mention is
that if you wanted to merge
other boxes onto a single line such as
these two here
you would need to use a different inline
string
so here i can write inline equals
two copy that code onto the next line
save the script come up to the settings
and now these two boxes are on
a single line and these three boxes are
on their own line as well
so that's it for today's lesson i hope
you found that interesting if you want
to learn more about this new update go
and read the documentation
and go and play around with it with your
existing scripts it may seem like a
minor thing but if you've been using
panscript for any length of time
you will be just as excited as i am to
have this new feature added
anyway that's it i'll see you in the
next lesson take care guys best of luck
with your trading
and i will speak to you soon
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...
-
feb5G573mYo hey what's up traders in this video I want to revisit a system I made a few years ago during the last...
-
Bk5Okd1q10c [Music] solo there and welcome to another tutorial my name is Tamara Bakshi and this time we're going...
-
hi coders and traders this is Matthew from pine script mastery calm in today's lesson I'm gonna be addressing a questi...