🖐 5 Rules For Successful Trading!Hello TradingView Family / Fellow Traders. This is Richard, also known as theSignalyst.
Trading is simple, but not easy. Traders have difficulty succeeding simply because they are unable to follow clear rules over extended periods of time.
So what are the rules that every trader should follow?
💸 1- Only invest what you Can Afford to Lose.
Only invest money you can afford to lose, never ever borrow money or take a loan from the bank to invest. Because if you do, you will get emotional and make irrational mistakes.
⚔️ 2- 1% Risk per Trade.
We only risk a small portion of our account per trade. We enter with 1% risk per trade (2% max). We enter with a fixed risk per trade, not with a fixed stop loss in pips, nor with a fixed lot size.
Remember: All Trades Have To Have The Same Weight / Effect On Our Account!
📉 3- Three Confluences Trades. (Technical Edge)
Trading is nothing but a game probability. Moreover, we consider ourselves risk managers not only traders, as the only thing we have control over is "risk". The market can go anywhere.
To be on the winning side, we need to have an edge over the market.
One way to put the odds in our favor is by only entering trades when we have at least three confluences/clues, three things telling us to buy or sell lined-up together. One confluence may be random.
For example: Only enter when you have a pattern, support, and divergence. And your rules have to be objective following a well-defined / back-tested trading plan.
📕 4- Positive RRR - Risk Reward Ratio. (Risk Management Edge)
Our second edge is going to be through risk and money management by entering with a positive risk-reward ratio. That’s exactly why we enter with a ½ RRR (or higher), which means we always target at least double our stop loss. This way even with a 50% win rate, we are still profitable.
Remember: It is not about how many trades you win, what matters is how much you win when you are right, and how much you lose when you are wrong.
🧘♂️ 5- Emotional stability.
In the trading world, emotions are considered the enemy of traders. Knowing how to control emotions while trading can prove to be the difference between success and failure. When getting into a bad trade, the trader who can manage his psychology well will be able to minimize risk, while the trader who is emotional may make the situation worse.
Remember: You Are Getting Paid; To Wait!
Moreover, if you are not feeling well, don't trade.
Remember: You don't have to catch every trade, and you don't have to trade every week.
In fact, our 5 rules are all connected in a way or another.
If you invest money you can’t afford to lose or enter with 10% risk per trade, chances are that you will get emotional and not follow your trading plan objectively by closing your trades before reaching 2R or even entering trades that are not according to your strategy.
In parallel, even if you invest money you can afford to lose and risk 1% per trade, you won’t be consistently profitable if you don’t have a well-defined strategy that gives you an edge over the market technically or through risk management.
In brief, stay away from trading if you don’t have these 5 rules.
Always follow your trading plan regarding entry, risk management, and trade management.
Good luck!
All Strategies Are Good; If Managed Properly!
~Rich
Tricks
[Risk Management trick] Tilting the "Math" in your favor!We all try to find the strategies which offer best possible win probabilities.
Yet, we often overlook another crucial component of increasing your odds of winning => risk management.
Today, I am going to show you how you can use a simple risk management trick to tilt the "Math" in your favor.
Would you like to increase the output of your strategy by 25% without doing anything extra?
Imagine a 3R win suddenly increasing to 3.75R with no change in the strategy at all.
Consider this trade...
We are trying to setup a sell trade with a very defined -1R risk and +3R profit.
If we were to loose this trade, we will loose 1% of our capital - and if we win, we will make 3% in return (3RR).
Here, we assumed that we'll exit the trade when price moves -1R completely against us.
What if, we pivot our thinking and assume the trade is lost when price has moved -0.8R : because if the trade goes that much against you, there's a very high probability that it'll hit your stop loss too. There is no reason to pretend that it can still turn around at the last moment. Murphy's law truly applies here - "Anything that can go wrong will go wrong".
If we do really pivot our thinking, lets see how it works in our favor!
The Stop loss is now updated and set at -0.8R
So a win will still give us the same 3%, but the loss will only wipe out -0.8% from our account.
Now because our profit targets are still setup as per the original 1% trade, you can now see that we now get this extra reward if our trade hits its original 3R target
The moment we draw 3R as per our new -0.8R stop loss, we get this - You can see how the 3R with -0.8R stop loss is achieved much before than the 3R with -1R stop loss (obviously)!
That means, the extra reward you got when the trade reached your original 3R - is additional profit which you now have - without ever changing your trading strategy!
3/0.8 = 0.75 (which is 25% of your original 3R target)
0.75/3 = 25%
You now have extra an 25% reward for free!
New RR = 3.75
This is a very beautiful math equation for yet another reason!
Imagine you lost your trade with a -0.8R => the additional 0.75R you will achieve (for free) from another trade will extremely quickly cover up anything you lost.
As you can see, we can really use sound risk management techniques & Math to our benefit.
This is called : Tilting the "Math" in your favor!
Tips And Tricks In PinescriptConclusion
I’am starting with the conclusion since i don’t plan to be on tradingview for some time. Pinescript is a really easy to use and learn language and i had a lot of fun writing all my indicators, i remember the first time i used it, it was a really nice day and i opened the script editor to edit the awesome oscillator indicator, i changed the sma to an ema, how cute, changing a letter, i was 16.
However we made a lot of progress in three years, i have often heard that i was a prolific, creative and talented indicator maker, and since my only goal in tradingview was to share and help people, i will leave all the tips and tricks related to pinescript i have to help you make great indicators.
Show the code
When publishing you can hide the code of your indicator, my first tips is to always show the code of your indicator/strategy except if you have a really good reason to hide it. Showing your code can help other people spot errors thus making you improve. If you think that your code is the holy grail and this is why you have to hide it i must tell you that there are a lot of researchers publishing papers that you can read about machine learning and other mega complex stuff applied to financial markets. At the end sharing is caring so share everything from your indicator !
Structure Your Code
Its common to make an indicator, save it, and start a new project from scratch, then if you come back to the saved indicator you can get lost, this happened with me several times. First create sections in your code, then delimit each section with a commentary, commentaries can be made in pine with //, i personally use //---- but you can use whatever you want like //ma section or //plots etc. The name of your variables can also be important, i’am conformable with an alphabet like variable declaration. Therefore you could structure you code like this :
study(…..)
length = input(14)
//----
a = …
b = …
c = …
//----
plot(…)
So try to find a structure style such that you will be confortable with :)
Making Different Types Of Filters in Pine
There are different types of filters, i explain each ones in my post Digital Filters And DSP . Here is the code to compute all common types of filters :
low-pass (lp) = lp(x)
high-pass (hp) = x - lp(x)
bandpass (bp) = lp(x - lp(x))
band-reject (br) = x - lp(x - lp(x))
with a simple moving average this give you :
low-pass moving average = sma(close, length)
high-pass moving average = x - sma(x, length)
bandpass moving average = sma(x - sma(x,length),length)
bandreject moving average = x - sma(x - sma(x,length),length)
This is a easy way to compute each filters types. You can use other filters types instead of the simple moving average.
Understand The Exponential Window Function
The exponential window function is my favorite equation and in my opinion one of the most elegant thing i had the chance to use. This window function is widely used and have the following form :
alpha*x + (1-alpha)*y
or
y + alpha*(x - y)
alpha is called a smoothing constant, when a = 0.5 you are just computing the average between x and y because a = 0.5 and 1 - a = 0.5, therefore you end up with : 0.5*x + 0.5*y = (x + y)/2. But the beauty of this function is that as long as a is greater than 0 and lower than 1 you will give more weight to x or y depending of a. There are a lot of indicators using this, the most well known being the exponential moving average.
Rescaling Inputs in A Certain Range
Scaling involve putting the input in a certain range such that the output is always equal or lower than a certain value and always equal or higher than another value, there are several ways to rescale values in a certain range, here are some ways to rescale values in Pine :
rsi(x, length) - rescale values in range of (100,0), higher length will converge the results toward 50, if you don’t want that use smooth values for x.
stoch(x,x,x,length) - rescale values in range of (100,0)
correlation(x,n,length) - rescale values in range of (1,-1)
sign(x) - rescale values in a range of (1,-1), 1 when x > 0 and -1 when x < 0.
x/highest(x,length) - values will always be equal or greater than 0 and equal or lower than 1, when x is high the output will be closer to 1.
lowest(x,length)/x - values will always be equal or greater than 0 and equal or lower than 1, when x is low the output will be closer to 1.
a = change(src,length)
b = abs(a)/highest(abs(a),length) * sign(a) - rescale values in a range of (1,-1)
a/(a + b) - rescale values in a range of (1,0) if a > 0 or (1,-1) if a < 0 as long as a < (a + b)
(x - b)/(a - b) - rescale in a range of (1,0) if x > b and a > x.
see also :
Use operations to scale in a desired range, when the rescaling is in a range (1,-1) use the following operations :
0.5 * rescaling + 0.5 if you want to rescale in a range of
(1 + rescaling) * (maximum/2) if you need a custom range
Use Recursion With The Exponential Window Function
Recursion is the process of using outputs as inputs for a function. Pine allow you to use outputs as inputs thanks to the nz() function. Lets use an example, imagine the following code with the version 2 of pinescript :
a = change(nz(a ,close),9)
This code compute the difference between a and a 9 bars back, now when the code will make the first calculation you want a numerical value for a because a will be equal to na (non attributed), this is why you need to have an initial value (also called a seed) for a and this is what nz() do , attribute a value to a when a = na. By running the code above you will end up with a periodic results, so how can you use recursion with your indicators ? Here the following code example show you how :
alpha = 0.5
a = scale(close, length)
b = function(alpha*a+(1-alpha)*nz(b ,a))
When you want to use recursion in a function you must first declare alpha, alpha can be any value as long as alpha is greater than 0 and lower than 1, then you must scale your input (here the closing price), this is done because depending on the price scale you could get different results when using recursion, when your rescaling range is low (1,0) your results could be more periodic than in a range like (100,0).
function is the function you want to use, if you rescaled the input you should use a function that don’t plot in the chart, if your function is a simple moving average sma or another filter you won’t need to scale the input, however if you use function such as change, rsi, stochastic…or any other oscillator you will need to rescale the values in a certain range. Recursion can help you get smooth, predictive, periodic and reactive results. If you need adaptive results you can even make alpha a variable by rescaling something you want in a range of (1,0), for example :
alpha = scale(tr,length)
a = scale(close)
b = function(alpha*a+(1-alpha)*nz(b ,a))
Create Adaptive Exponential Filters Easily
Adaptive moving averages are greats because market exhibit a dynamical behavior, so adaptivity is a good way to have really great filters. An easy way to have adaptive filters is by using exponential averaging, in short using the structure of an exponential moving average, the ema of x is calculated as follow in pine :
y = alpha*x + (1-alpha)*nz(y ,x)
which can derived to :
y = nz(y ,x) + alpha*(x - nz(y ,x))
where alpha = 2/(length + 1)
As you can see we go back to the exponential window function and thanks to this function the ema is really efficient to compute. An adaptive filter will use a variable alpha instead of a constant one, so as long as 1 >= alpha >= 0 you will get an adaptive filter. If you want to adapt the filter to market volatility just rescale a volatility indicator like the atr in a range of (1,0), in pine this would look like :
alpha = scale(tr,length)
y = alpha*close + (1-alpha)*nz(y ,close)
If you need alpha to decrease when length increase you can divide your rescaling by length, for example if you use the stochastic of the true range as alpha you can make :
alpha = stoch(tr,tr,tr,length)/100 / sqrt(length)
y = alpha*close + (1-alpha)*nz(y ,close)
Create An Adaptive Simple Moving Average
In pine you can compute a simple moving average by using the sma() function :
sma = sma(x,length)
now imagine you want to use a non constant length, like for example the barssince() function, well you can’t because the sms function only work with constant integers, so how can you use non constant integers for calculating an adaptive sma ? Well you can derive the sma formula like this :
length = barssince(cross(close,vwap)) + 1
rsum = cum(close)
asma = (rsum - rsum )/length
Make sure that length is always greater or equal to 1, if length is a float use the round() function :
length = round(barssince(cross(close,vwap)) + 1)
Use Fixnan For Colors
When plotting an indicator with a plot fonction using a condition to change colors, you will have a different color if the indicator value is equal to its previous value, this image describe this case :
with :
a = highest(50)
c = if a > a
lime
else
if a < a
red
plot(a,color=c)
Instead you can use a ternary operator and use fixnan to fix this issue, the plot code look like this :
plot(a,color=fixnan(a>a ?lime:a 4000 ? 1 : 0
b = sma(a,length)
plot(a),plot(b)
The time it takes to the filter to get to the maximum value of the step function will tell you about its reactivity while seeing if the filter exceed the maximum value of the step function will tell you about its overshoot response, after an overshoot the filter can also go back under the step function, this is an undershoot, there are also tons of other things about the step response like ringing, but some only happen with recursive filter like the ema.
In order to check for smoothness against another filter you can use this code :
a = abs(change(filter1))
b = abs(change(filter2))
If you see that filter 1 have overall greater values than filter 2 it means that filter 1 smooth less.
Estimate A Gaussian Filter
You don’t really need fancy math’s to make a gaussian filter, the central limit theorem will help you estimate it just fine. A gaussian filter is a filter which impulse response is a gaussian function (bell shaped curve), a gaussian filter can be approximated with this code :
a = sma(sma(sma(sma(close,length/4),length/4),length/4),length/4)
In short the more sma function you add the better the estimation.
Some Other Tips
You can declare a float by using 0. instead 0.0
You can find the average highest frequency of a signal a with :
b = a > a and a < a or a < a and a > a ? 1 : 0
c = 1/(cum(b)/n) * 2
Learn all the shortcuts, some in mac :
cmd + enter = add to chart
cmd + i = new script
cmd + click on a function = display the reference manual of the function
Double click on one indicator line will display its settings window.
Know some maths, its not a requisite but it sure help.
And finally work and share with a group, its not something that i did but the truth is that it help a lot.
Final Words
I can’t cite all the person i want to thanks, there are to many, but without support its hard to improve, so thank you all. If this article helped you in any way then i’am more than satisfied. Oh and if you want to thanks and support me for all those years just use, change, improve and learn from my indicators as well as sharing your work or knowledge and have a lot of fun, that’s all i want.
Lets conclude this adventure with the memorable thanks for reading !