Machine Learning: SuperTrend Strategy TP/SL [YinYangAlgorithms]The SuperTrend is a very useful Indicator to display when trends have shifted based on the Average True Range (ATR). Its underlying ideology is to calculate the ATR using a fixed length and then multiply it by a factor to calculate the SuperTrend +/-. When the close crosses the SuperTrend it changes direction.
This Strategy features the Traditional SuperTrend Calculations with Machine Learning (ML) and Take Profit / Stop Loss applied to it. Using ML on the SuperTrend allows for the ability to sort data from previous SuperTrend calculations. We can filter the data so only previous SuperTrends that follow the same direction and are within the distance bounds of our k-Nearest Neighbour (KNN) will be added and then averaged. This average can either be achieved using a Mean or with an Exponential calculation which puts added weight on the initial source. Take Profits and Stop Losses are then added to the ML SuperTrend so it may capitalize on Momentum changes meanwhile remaining in the Trend during consolidation.
By applying Machine Learning logic and adding a Take Profit and Stop Loss to the Traditional SuperTrend, we may enhance its underlying calculations with potential to withhold the trend better. The main purpose of this Strategy is to minimize losses and false trend changes while maximizing gains. This may be achieved by quick reversals of trends where strategic small losses are taken before a large trend occurs with hopes of potentially occurring large gain. Due to this logic, the Win/Loss ratio of this Strategy may be quite poor as it may take many small marginal losses where there is consolidation. However, it may also take large gains and capitalize on strong momentum movements.
Tutorial:
In this example above, we can get an idea of what the default settings may achieve when there is momentum. It focuses on attempting to hit the Trailing Take Profit which moves in accord with the SuperTrend just with a multiplier added. When momentum occurs it helps push the SuperTrend within it, which on its own may act as a smaller Trailing Take Profit of its own accord.
We’ve highlighted some key points from the last example to better emphasize how it works. As you can see, the White Circle is where profit was taken from the ML SuperTrend simply from it attempting to switch to a Bullish (Buy) Trend. However, that was rejected almost immediately and we went back to our Bearish (Sell) Trend that ended up resulting in our Take Profit being hit (Yellow Circle). This Strategy aims to not only capitalize on the small profits from SuperTrend to SuperTrend but to also capitalize when the Momentum is so strong that the price moves X% away from the SuperTrend and is able to hit the Take Profit location. This Take Profit addition to this Strategy is crucial as momentum may change state shortly after such drastic price movements; and if we were to simply wait for it to come back to the SuperTrend, we may lose out on lots of potential profit.
If you refer to the Yellow Circle in this example, you’ll notice what was talked about in the Summary/Overview above. During periods of consolidation when there is little momentum and price movement and we don’t have any Stop Loss activated, you may see ‘Signal Flashing’. Signal Flashing is when there are Buy and Sell signals that keep switching back and forth. During this time you may be taking small losses. This is a normal part of this Strategy. When a signal has finally been confirmed by Momentum, is when this Strategy shines and may produce the profit you desire.
You may be wondering, what causes these jagged like patterns in the SuperTrend? It's due to the ML logic, and it may be a little confusing, but essentially what is happening is the Fast Moving SuperTrend and the Slow Moving SuperTrend are creating KNN Min and Max distances that are extreme due to (usually) parabolic movement. This causes fewer values to be added to and averaged within the ML and causes less smooth and more exponential drastic movements. This is completely normal, and one of the perks of using k-Nearest Neighbor for ML calculations. If you don’t know, the Min and Max Distance allowed is derived from the most recent(0 index of data array) to KNN Length. So only SuperTrend values that exhibit distances within these Min/Max will be allowed into the average.
Since the KNN ML logic can cause these exponential movements in the SuperTrend, they likewise affect its Take Profit. The Take Profit may benefit from this movement like displayed in the example above which helped it claim profit before then exhibiting upwards movement.
By default our Stop Loss Multiplier is kept quite low at 0.0000025. Keeping it low may help to reduce some Signal Flashing while not taking extra losses more so than not using it at all. However, if we increase it even more to say 0.005 like is shown in the example above. It can really help the trend keep momentum. Please note, although previous results don’t imply future results, at 0.0000025 Stop Loss we are currently exhibiting 69.27% profit while at 0.005 Stop Loss we are exhibiting 33.54% profit. This just goes to show that although there may be less Signal Flashing, it may not result in more profit.
We will conclude our Tutorial here. Hopefully this has given you some insight as to how Machine Learning, combined with Trailing Take Profit and Stop Loss may have positive effects on the SuperTrend when turned into a Strategy.
Settings:
SuperTrend:
ATR Length: ATR Length used to create the Original Supertrend.
Factor: Multiplier used to create the Original Supertrend.
Stop Loss Multiplier: 0 = Don't use Stop Loss. Stop loss can be useful for helping to prevent false signals but also may result in more loss when hit and less profit when switching trends.
Take Profit Multiplier: Take Profits can be useful within the Supertrend Strategy to stop the price reverting all the way to the Stop Loss once it's been profitable.
Machine Learning:
Only Factor Same Trend Direction: Very useful for ensuring that data used in KNN is not manipulated by different SuperTrend Directional data. Please note, it doesn't affect KNN Exponential.
Rationalized Source Type: Should we Rationalize only a specific source, All or None?
Machine Learning Type: Are we using a Simple ML Average, KNN Mean Average, KNN Exponential Average or None?
Machine Learning Smoothing Type: How should we smooth our Fast and Slow ML Datas to be used in our KNN Distance calculation? SMA, EMA or VWMA?
KNN Distance Type: We need to check if distance is within the KNN Min/Max distance, which distance checks are we using.
Machine Learning Length: How far back is our Machine Learning going to keep data for.
k-Nearest Neighbour (KNN) Length: How many k-Nearest Neighbours will we account for?
Fast ML Data Length: What is our Fast ML Length?? This is used with our Slow Length to create our KNN Distance.
Slow ML Data Length: What is our Slow ML Length?? This is used with our Fast Length to create our KNN Distance.
If you have any questions, comments, ideas or concerns please don't hesitate to contact us.
HAPPY TRADING!
Machine
Machine Learning: Donchian DCA Grid Strategy [YinYangAlgorithms]This strategy uses a Machine Learning approach on the Donchian Channels with a DCA and Grid purchase/sell Strategy. Not only that, but it uses a custom Bollinger calculation to determine its Basis which is used as a mild sell location. This strategy is a pure DCA strategy in the sense that no shorts are used and theoretically it can be used in webhooks on most exchanges as it’s only using Spot Orders. The idea behind this strategy is we utilize both the Highest Highs and Lowest Lows within a Machine Learning standpoint to create Buy and Sell zones. We then fraction these zones off into pieces to create Grids. This allows us to ‘micro’ purchase as it enters these zones and likewise ‘micro’ sell as it goes up into the upper (sell) zones.
You have the option to set how many grids are used, by default we use 100 with max 1000. These grids can be ‘stacked’ together if a single bar is to go through multiple at the same time. For instance, if a bar goes through 30 grids in one bar, it will have a buy/sell power of 30x. Stacking Grid Buy and (sometimes) Sells is a very crucial part of this strategy that allows it to purchase multitudes during crashes and capitalize on sales during massive pumps.
With the grids, you’ll notice there is a middle line within the upper and lower part that makes the grid. As a Purchase Type within our Settings this is identified as ‘Middle of Zone Purchase Amount In USDT’. The middle of the grid may act as the strongest grid location (aside from maybe the bottom). Therefore there is a specific purchase amount for this Grid location.
This DCA Strategy also features two other purchase methods. Most importantly is its ‘Purchase More’ type. Essentially it will attempt to purchase when the Highest High or Lowest Low moves outside of the Outer band. For instance, the Lowest Low becomes Lower or the Higher High becomes Higher. When this happens may be a good time to buy as it is featuring a new High or Low over an extended period.
The last but not least Purchase type within this Strategy is what we call a ‘Strong Buy’. The reason for this is its verified by the following:
The outer bounds have been pushed (what causes a ‘Purchase More’)
The Price has crossed over the EMA 21
It has been verified through MACD, RSI or MACD Historical (Delta) using Regular and Hidden Divergence (Note, only 1 of these verifications is required and it can be any).
By default we don’t have Purchase Amount for ‘Strong Buy’ set, but that doesn’t mean it can’t be viable, it simply means we have only seen a few pairs where it actually proved more profitable allocating money there rather than just increasing the purchase amount for ‘Purchase More’ or ‘Grids’.
Now that you understand where we BUY, we should discuss when we SELL.
This Strategy features 3 crucial sell locations, and we will discuss each individually as they are very important.
1. ‘Sell Some At’: Here there are 4 different options, by default its set to ‘Both’ but you can change it around if you want. Your options are:
‘Both’ - You will sell some at both locations. The amount sold is the % used at ‘Sell Some %’.
‘Basis Line’ - You will sell some when the price crosses over the Basis Line. The amount sold is the % used at ‘Sell Some %’.
‘Percent’ - You will sell some when the Close is >= X% between the Lower Inner and Upper Inner Zone.
‘None’ - This simply means don’t ever Sell Some.
2. Sell Grids. Sell Grids are exactly like purchase grids and feature the same amount of grids. You also have the ability to ‘Stack Grid Sells’, which basically means if a bar moves multiple grids, it will stack the amount % wise you will sell, rather than just selling the default amount. Sell Grids use a DCA logic but for selling, which we deem may help adjust risk/reward ratio for selling, especially if there is slow but consistent bullish movement. It causes these grids to constantly push up and therefore when the close is greater than them, accrue more profit.
3. Take Profit. Take profit occurs when the close first goes above the Take Profit location (Teal Line) and then Closes below it. When Take Profit occurs, ALL POSITIONS WILL BE SOLD. What may happen is the price enters the Sell Grid, doesn’t go all the way to the top ‘Exiting it’ and then crashes back down and closes below the Take Profit. Take Profit is a strong location which generally represents a strong profit location, and that a strong momentum has changed which may cause the price to revert back to the buy grid zone.
Keep in mind, if you have (by default) ‘Only Sell If Profit’ toggled, all sell locations will only create sell orders when it is profitable to do so. Just cause it may be a good time to sell, doesn’t mean based on your DCA it is. In our opinion, only selling when it is profitable to do so is a key part of the DCA purchase strategy.
You likewise have the ability to ‘Only Buy If Lower than DCA’, which is likewise by default. These two help keep the Yin and Yang by balancing each other out where you’re only purchasing and selling when it makes logical sense too, even if that involves ignoring a signal and waiting for a better opportunity.
Tutorial:
Like most of our Strategies, we try to capitalize on lower Time Frames, generally the 15 minutes so we may find optimal entry and exit locations while still maintaining a strong correlation to trend patterns.
First off, let’s discuss examples of how this Strategy works prior to applying Machine Learning (enabled by default).
In this example above we have disabled the showing of ‘Potential Buy and Sell Signals’ so as to declutter the example. In here you can see where actual trades had gone through for both buying and selling and get an idea of how the strategy works. We also have disabled Machine Learning for this example so you can see the hard lines created by the Donchian Channel. You can also see how the Basis line ‘white line’ may act as a good location to ‘Sell Some’ and that it moves quite irregularly compared to the Donchian Channel. This is due to the fact that it is based on two custom Bollinger Bands to create the basis line.
Here we zoomed out even further and moved back a bit to where there were dense clusters of buy and sell orders. Sometimes when the price is rather volatile you’ll see it ‘Ping Pong’ back and forth between the buy and sell zones quite quickly. This may be very good for your trades and profit as a whole, especially if ‘Only Buy If Lower Than DCA’ and ‘Only Sell If Profit’ are both enabled; as these toggles will ensure you are:
Always lowering your Average when buying
Always making profit when selling
By default 8% commission is added to the Strategy as well, to simulate the cost effects of if these trades were taking place on an actual exchange.
In this example we also turned on the visuals for our ‘Purchase More’ (orange line) and ‘Take Profit’ (teal line) locations. These are crucial locations. The Purchase More makes purchases when the bottom of the grid has been moved (may dictate strong price movement has occurred and may be potential for correction). Our Take Profit may help secure profit when a momentum change is happening and all of the Sell Grids weren’t able to be used.
In the example above we’ve enabled Buy and Sell Signals so that you can see where the Take Profit and Purchase More signals have occurred. The white circle demonstrates that not all of the Position Size was sold within the Sell Grids, and therefore it was ALL CLOSED when the price closed below the Take Profit Line (Teal).
Then, when the bottom of the Donchian Channel was pushed further down due to the close (within the yellow circle), a Purchase More Signal was triggered.
When the close keeps pushing the bottom of the Buy Grid lower, it can cause multiple Purchase More Signals to occur. This is normal and also a crucial part of this strategy to help lower your DCA. Please note, the Purchase More won’t trigger a Buy if the Close is greater than the DCA and you have ‘Only Purchase If Lower Than DCA’ activated.
By turning on Machine Learning (default settings) the Buy and Sell Grid Zones are smoothed out more. It may cause it to look quite a bit different. Machine Learning although it looks much worse, may help increase the profit this Strategy can produce. Previous results DO NOT mean future results, but in this example, prior to turning on Machine Learning it had produced 37% Profit in ~5 months and with Machine Learning activated it is now up to 57% Profit in ~5 months.
Machine Learning causes the Strategy to focus less on Grids and more on Purchase More when it comes to getting its entries. However, if you likewise attempt to focus on Purchase More within non Machine Learning, the locations are different and therefore the results may not be as profitable.
PLEASE NOTE:
By default this strategy uses 1,000,000 as its initial capital. The amount it purchases in its Settings is relevant to this Initial capital. Considering this is a DCA Strategy, we only want to ‘Micro’ Buy and ‘Micro’ Sell whenever conditions are met.
Therefore, if you increase the Initial Capital, you’ll likewise want to increase the Purchase Amounts within the Settings and Vice Versa. For instance, if you wish to set the Initial Capital to 10,000, you should likewise can the amounts in the Settings to 1% of what they are to account for this.
We may change the Purchase Amounts to be based on %’s in a later update if it is requested.
We will conclude this Tutorial here, hopefully you can see how a DCA Grid Purchase Model applied to Machine Learning Donchian Channels may be useful for making strategic purchases in low and high zones.
Settings:
Display Data:
Show Potential Buy Locations: These locations are where 'Potentially' orders can be placed. Placement of orders is dependant on if you have 'Only Buy If Lower Than DCA' toggled and the Price is lower than DCA. It also is effected by if you actually have any money left to purchase with; you can't buy if you have no money left!
Show Potential Sell Locations: These locations are where 'Potentially' orders will be sold. If 'Only Sell If Profit' is toggled, the sell will only happen if you'll make profit from it!
Show Grid Locations: Displaying won't affect your trades but it can be useful to see where trades will be placed, as well as which have gone through and which are left to be purchased. Max 100 Grids, but visuals will only be shown if its 20 or less.
Purchase Settings:
Only Buy if its lower than DCA: Generally speaking, we want to lower our Average, and therefore it makes sense to only buy when the close is lower than our current DCA and a Purchase Condition is met.
Compound Purchases: Compounding Purchases means reinvesting profit back into your trades right away. It drastically increases profits, but it also increases risk too. It will adjust your Purchase Amounts for the Purchase Type you have set at the same % rate of strategy initial_capital to the amounts you have set.
Adjust Purchase Amount Ratio to Maintain Risk level: By adjusting purchase levels we generally help maintain a safe risk level. Basically we generally want to reserve X amount of % for each purchase type being used and relocate money when there is too much in one type. This helps balance out purchase amounts and ensure the types selected have a correct ratio to ensure they can place the right amount of orders.
Stack Grid Buys: Stacking Buy Grids is when the Close crosses multiple Buy Grids within the same bar. Should we still only purchase the value of 1 Buy Grid OR stack the grid buys based on how many buy grids it went through.
Purchase Type: Where do you want to make Purchases? We recommend lowering your risk by combining All purchase types, but you may also customize your trading strategy however you wish.
Strong Buy Purchase Amount In USDT: How much do you want to purchase when the 'Strong Buy' signal appears? This signal only occurs after it has at least entered the Buy Zone and there have been other verifications saying it's now a good time to buy. Our Strong Buy Signal is a very strong indicator that a large price movement towards the Sell Zone will likely occur. It almost always results in it leaving the Buy Zone and usually will go to at least the White Basis line where you can 'Sell Some'.
Buy More Purchase Amount In USDT: How much should you purchase when the 'Purchase More' signal appears? This 'Purchase More' signal occurs when the lowest level of the Buy Zone moves lower. This is a great time to buy as you're buying the dip and generally there is a correction that will allow you to 'Sell Some' for some profit.
Amount of Grid Buy and Sells: How many Grid Purchases do you want to make? We recommend having it at the max of 10, as it will essentially get you a better Average Purchase Price, but you may adjust it to whatever you wish. This amount also only matters if your Purchase Type above incorporates Grid Purchases. Max 100 Grids, but visuals will only be shown if it's 20 or less.
Each Grid Purchase Amount In USDT: How much should you purchase after closing under a grid location? Keep in mind, if you have 10 grids and it goes through each, it will be this amount * 10. Grid purchasing is a great way to get a good entry, lower risk and also lower your average.
Middle Of Zone Purchase Amount In USDT: The Middle Of Zone is the strongest grid location within the Buy Zone. This is why we have a unique Purchase Amount for this Grid specifically. Please note you need to have 'Middle of Zone is a Grid' enabled for this Purchase Amount to be used.
Sell:
Only Sell if its Profit: There is a chance that during a dump, all your grid buys when through, and a few Purchase More Signals have appeared. You likely got a good entry. A Strong Buy may also appear before it starts to pump to the Sell Zone. The issue that may occur is your Average Purchase Price is greater than the 'Sell Some' price and/or the Grids in the Sell Zone and/or the Strong Sell Signal. When this happens, you can either take a loss and sell it, or you can hold on to it and wait for more purchase signals to therefore lower your average more so you can take profit at the next sell location. Please backtest this yourself within our YinYang Purchase Strategy on the pair and timeframe you are wanting to trade on. Please also note, that previous results will not always reflect future results. Please assess the risk yourself. Don't trade what you can't afford to lose. Sometimes it is better to strategically take a loss and continue on making profit than to stay in a bad trade for a long period of time.
Stack Grid Sells: Stacking Sell Grids is when the Close crosses multiple Sell Grids within the same bar. Should we still only sell the value of 1 Sell Grid OR stack the grid sells based on how many sell grids it went through.
Stop Loss Type: This is when the Close has pushed the Bottom of the Buy Grid More. Do we Stop Loss or Purchase More?? By default we recommend you stay true to the DCA part of this strategy by Purchasing More, but this is up to you.
Sell Some At: Where if selected should we 'Sell Some', this may be an important way to sell a little bit at a good time before the price may correct. Also, we don't want to sell too much incase it doesn't correct though, so its a 'Sell Some' location. Basis Line refers to our Moving Basis Line created from 2 Bollinger Bands and Percent refers to a Percent difference between the Lower Inner and Upper Inner bands.
Sell Some At Percent Amount: This refers to how much % between the Lower Inner and Upper Inner bands we should well at if we chose to 'Sell Some'.
Sell Some Min %: This refers to the Minimum amount between the Lower Inner band and Close that qualifies a 'Sell Some'. This acts as a failsafe so we don't 'Sell Some' for too little.
Sell % At Strong Sell Signal: How much do we sell at the 'Strong Sell' Signal? It may act as a strong location to sell, but likewise Grid Sells could be better.
Grid and Donchian Settings:
Donchian Channel Length: How far back are we looking back to determine our Donchian Channel.
Extra Outer Buy Width %: How much extra should we push the Outer Buy (Low) Width by?
Extra Inner Buy Width %: How much extra should we push the Inner Buy (Low) Width by?
Extra Inner Sell Width %: How much extra should we push the Inner Sell (High) Width by?
Extra Outer Sell Width %: How much extra should we push the Outer Sell (High) Width by?
Machine Learning:
Rationalized Source Type: Donchians usually use High/Low. What Source is our Rationalized Source using?
Machine Learning Type: Are we using a Simple ML Average, KNN Mean Average, KNN Exponential Average or None?
Machine Learning Length: How far back is our Machine Learning going to keep data for.
k-Nearest Neighbour (KNN) Length: How many k-Nearest Neighbours will we account for?
Fast ML Data Length: What is our Fast ML Length?? This is used with our Slow Length to create our KNN Distance.
Slow ML Data Length: What is our Slow ML Length?? This is used with our Fast Length to create our KNN Distance.
If you have any questions, comments, ideas or concerns please don't hesitate to contact us.
HAPPY TRADING!
Flawless Victory Strategy - 15min BTC Machine Learning StrategyHello everyone, I am a heavy Python programmer bringing machine learning to TradingView. This 15 minute Bitcoin Long strategy was created using a machine learning library and 1 year of historical data in Python. Every parameter is hyper optimized to bring you the most profitable buy and sell signals for Bitcoin on the 15min chart. The historical Bitcoin data was gathered from Binance API, in case you want to know the best exchange to use this long strategy. It is a simple Bollinger Band and RSI strategy with two versions included in the tradingview settings. The first version has a Sharpe Ratio of 7.5 which is amazing, and the second version includes the best stop loss and take profit positions with a Sharpe Ratio of 2.5 . Let me talk a little bit more about how the strategy works. The buy signal is triggered when close price is less than lower Bollinger Band at Std Dev 1, and the RSI is greater than a certain value. The sell signal is triggered when close price is greater than upper Bollinger Band at Std Dev 1, and the RSI is greater than a certain value. What makes this strategy interesting is the parameters the Machine Learning library found when backtesting for the best Sharpe Ratio. I left my computer on for about 28 hours to fully backtest 5000 EPOCHS and get the results. I was able to create a great strategy that might be one of TradingView's best strategies out on the website today. I will continue to apply machine learning to all my strategies from here on forward. Please Let me know if you have any questions or certain strategies you would like me to hyper optimize for you. I'm always willing to create profitable strategies!
P.S. You can always pyramid this strategy for more gains! I just don't add pyramiding when creating my strategies because I want to show you the true win/loss ratio based buying one time and one selling one time. I feel like when creating a strategy that includes pyramiding right off the bat falsifies the win rate. This is my way of being transparent with you all. Have fun trading!
The Breakout Machine V2 BTCUSDT - Bitcoin BeatsHello, Hello, Hello and welcome back to Bitcoin Beats.
As the title suggests, this is Version 2 of The Breakout Machine. Unlike the previous version, this one has been fine-tuned to work best on Binance Futures(BTCUSDT).
The stats shown below are from 2020.
PLEASE BE CAREFUL WITH YOUR LEVERAGE AND DON'T GET REKT.
Trade at your own risk! Good luck!
This strategy takes MACD and Volume spikes to calculate pumps and dumps in the bitcoin market.
I've also added custom backtesting inputs and leverage for you all to experiment with and see the profitability of the Strategy.
Alerts version coming soon...
Thank you, And goodbye, from Bitcoin Beats.