today's strategy uses a very simple candl pattern and it performed extremely well in the back test yielding 107% in returns and a win rate of 70% I back tested this strategy on some stocks like the triple Q the S&P 500 and the Dax although these results are actually good but to me they are not really impressive and I will tell you why in The Book of Michael Harris where I took the strategy from there's a long list of similar strategies that are all impressively profitable and actually this is not difficult to achieve if you're trading
stock if you apply long-only strategies on any asset with constantly increasing price like the Apple Microsoft or the German Dax we should end up with substantial profits because we're basically only buying and the long-term trend is bullish so climbing up most of the time so our strategy will be on The Winning Side to test the robustness of an indicator we need to apply it in different conditions so I also tested this strategy on Forex data allowing both long and short trades to avoid any bias and I still got the same positive results as you can
see from the back test with 101% in returns and the win rate of 65% however notice that the equities results can be split into two clusters this time one cluster on the winning side and the other cluster is kind of a break even side the strategy is very simple we will consider a set of conditions defining a specific candle's pattern the high of the current candle should be greater than the high of the previous candle and the high of the previous candle should be greater than the low of the current candle so in other words
the high of the previous candle should be somewhere in the middle between the edges of the current candle then the low of the current candle has to be greater than the low of position minus 2 and the high of position minus 2 has to be greater than the low of position minus one or the previous candle so we're also looking at the same figure here where the high of position minus 2 is somewhere in the middle between the edges of the following candle then the low of position minus one is greater than the high of
position minus 3 and the high of position minus 3 is greater than the low low of the following candle at position minus 2 so also the high in this case of position minus 3 is in the middle between the edges of the following candle which is position minus 2 and the low of position minus 2 is greater than the low of position minus 3 now this might seem like a lot of conditions to think about but in Python it's very easy to implement these and actually it's not that complicated we are basically looking for an
increasing lows of consecutive candles and the high of each candle must be contained with in the edges of the following candle as we have explained in the conditions when the conditions are met we enter at the open of the next candle we set the uh stop-loss and takeprofit levels within a certain percentage of the current entry price okay now let's go through the code and I will show you how I did the back test but before we continue the code is available for download from the link in the description so you can download it and
run it on any data of any asset and maybe apply in your modifications so this is our jupter notebook file the first function reads CSV to data frame reads a file path where we have a CSV and it will return a data frame it transform the data into a data frame then we have read data folder it's going to read a folder of csvs saving these into a list of data frames with the file names as well then we have total signal this is where we put our conditions the buy conditions that we've just explained
at the beginning of this video I also applied the symmetrical conditions for short positions although this was not really explained and introduced in Michael Harris's book but I think we can apply the symmetrical conditions for short signals and we're going to test this in a while so whenever we have um bu conditions or long conditions we return to or function returns two and whenever we have a short conditions that are uh verified we return one in any other case we return zero then we apply the uh total signal function and we add to the data
frame a new column called total signal so we're going to generate these signals one and two and zero and add them to the data frame uh for each of these candles then we have add Point position column so this is going to add positions of points where we have signals this is going to help just to visualize these purple points where the signals occurred on a chart so this is just for visualization purposes then we have one more condition that's going to plot the charts and add points or purple points where we have signals on
top of the chart so this will allow us to verify if the code is working correctly then I can run the first part where we're reading the uh data for uh let's say stocks at this stage and we're going to read all the csvs I think I have four different csvs the vix the um Dax the SNP 500 and the triple Q so we can run this we can see that we have four files we're also applying the add total signal to each of those data frames and the add Point position column to be able
to visualize these signals for each of the data frames if needed this cell just counts the number of signals the total number of signals so we have 90 bearish signals and and 133 bullish signals it's just to verify that we have any signals happening in the data frame then we can plot any of the data frames here visualizing the uh signals we can verify that it's working well by checking the uh the conditions and checking where the signals exactly occurred as you can see for the short part here we have a low that's lower than
all of these and if you measure each candle's high is actually between the previous edges of the previous candle so actually this is what was mentioned in the previous part of the video so these are the conditions and the low of each candle is in the middle of the edges as well of the following candle as you can see so anyway you can verify these take your time check the conditions and check if everything is working as we've coded I've checked them from my side and it's working well so we can go on with our
back testing part for back testing I'm using back testing. pi as usual I'm defining the total signal function right here and then the size of the trade is going to be 10% of the equity the stop-loss percentage and takeprofit percentage are the percentages of the prices so this is how we're going to define the stop loss and takeprofit levels however we're going to optimize these so it's not going to be 4% and 2% we're going to start with these values but then we're going to modify these within a certain range we're going from 1% up
to 8% for each of these two parameters if the signal is equal to two so we have a bullish signal and we don't have any open position position on the market we're going to open a buying position using the size the stop loss and the take Profit just as we have defined right here in the opposite direction if we have a bearish signal and we don't have any open position we're going to go for a short position so now for the back test I'm using U $5,000 to start a margin one over five and a
small commission to account for the spread we're changing as I've mentioned the range of the stop-loss percentage and the takeprofit percentage between 1 to 8% we're maximizing the returns and we're going to run this and we're going to store the results in a list of results here because we have multiple data frames multiple assets multiple stock data so it's going to run the back test and the optimization for each of these and then we're storing the uh results in a list of results and the heat maps are actually if you want to plot a heat
map later on I'm going to show you this and how it works this cell basically was going to aggregate the results so we have the aggregated returns 107% a total number of Trades of 120 maximum drow down of minus 20% that's U kind of large I think in my opinion but that's mainly because we've applied long and short positions if we come at the part where we um allow for short positions just like Michael Harris defined in his book defined the strategy in his book we can run this again and you can see that we
will have probably less aggregated results because we are sacrificing some of our trades so we have 94% however the drug down actually the maximum drow down is now cut by half minus 10% and I do prefer this style of safer trading to be honest instead of maximizing the profits but also increasing the risk so the average drow down in this case is minus 1% almost so this is really great and win rate of 63% we can also plot the equity curves for the stocks as you can see we have the triple Q the S&P 500
the Dax and the vix actually the Dax and the vix are not doing well these are the um the green and the red curve what's saving the situation here is the triple Q triple Q has some uh powerful patterns that it's repetitive on the market apparently and it's still working as you can see it's through the years it's still working well this is between 2017 up to 2024 so whatever used to work 5 years ago is still working nowadays as well now I'm always careful ful when I'm optimizing because I don't need to overfit overfitting
is very disappointing because you test and you get really nice results and then when you deploy to trade live on the market with real data or even with a demo account you don't have exactly the same results and this is why I'm plotting the heat map here and it's very important this is very important to understand what's happening these are the return percentages when we're changing the stop-loss percentage and takeprofit percentage so one thing we should know here we're not fitting any parameter related to our indicator the indicator is the pattern the candles pattern it's
Untouchable it's as defined in the book of Michael Harris so this is good because we can't really overfit in this case we're just using the um optimization to change the range of the trade management part so the stop- loss and the take profit so in other words you will not have a problem to enter the market entering the market will always be the same when do you exit the market this is where things can vary so you need to know how to manage your trade and in this case the results that you can see here
can be further improved if you are trading manually so if you allow the uh the bot or whatever the indicator or your automated algorithm to enter the market or to Signal you to enter the market and then you manage manually as a Trader when do you exit the market you might beat these numbers by far because this is how it works you can combine automated trading with manual trading for the trade management part but in any case I wanted to show you this heat map where all of the numbers are positive so no matter how
you are trading this on the triple Q it's going to yield a positive result that's because apparently the pattern fits very well with the triple Q asset now I will repeat the whole thing using Forex data instead of the um stocks data so instead of my data stocks I'm loading a different folder called Data Forex I'm going to run this and we're going to onun all the cells again for the back test remember that we have closed the short positioning for now and here we have 36% with a maximum drow down of minus 8% a
win rate of 63% however when I allow for short positions because remember that Forex is not always climbing the assets are not always climbing like stocks so we need to allow also short positions to uh trade in both directions and now we have 101% in returns and the maximum throw down of - 10% and this is really good an average throw down of minus 1% and win rate of 65% these results are excellent actually for trading and I'm plotting the equities here Australian US dollar EUR US dollar and so on you can see I also
tested on gold that's the uh purple uh curve going up so it's working well for gold also um the best cluster of assets actually is the red one so it's the New Zealand US dollar then we have the the blue one Australian US dollar this is normal because New Zealand and the Australian dollars are correlated together statistically so if one works the other one should work as well I mean a strategy works for one it should work for the other and the purple one is the gold so the rest is not working well surprisingly but
at least we can see this from the back testing part and we can verify where this pattern works and where it doesn't really work and this was it for this video I hope you guys liked it and found the information helpful if so please give a like support the channel subscribe and leave a comment share your ideas until our next video trade safe and see you next time