Trail Blaze - (Multi Function Trailing Stop Loss) - [mutantdog]Shorter version:
As the title states, this is a 'Trailing Stop' type indicator, albeit one with a whole bunch of additional functionality, making it far more versatile and customisable than a standard trailing stop.
The main set of features includes:
Three independent trailing types each with their own +/- multipliers:
- Standard % change
- ATR (aka Supertrend)
- IQR (inter-quartile range)
These can be used in isolation or summed together. A subsequent pair of direction specific multipliers are also included.
Two separate custom source inputs are available, both feature the standard options alongside a selection of 'weighted inputs' and the option to use another indicator (selected via 'AUX'):
- 'Centre' determines the value about which the trailing sum will be added to define the stop level.
- 'Trigger' determines the value used for crossing of stops, initiating trend changes and triggering alerts.
A selection of optional filters and moving averages are available for both.
Furthermore there are various useful visualisation options available, including the underlying bands that govern the stop levels. Preset alerts for trend reversals are also included.
This is not really an 'out-of-the-box' indicator. Depending upon the market and timeframe some adjustments will be necessary for it to function in a useful manner, these can be as simple or complex as the feature-set allows. Basic settings are easy to dial in however and the default state is intended as a good starting point. Alternatively with some experimentation, a plethora of unique and creative configurations are possible, making this a great tool for tweaking. Below is a more detailed overview followed by a bunch of simple example settings.
------------------------
Lengthy Version :
DESIGN & CONCEPT
Before we start breaking this down, a little background. This started off as an attempt to improve upon the ever-popular Supertrend indicator. Of course there are many excellent user created variants available utilising some interesting methods to overcome the drawbacks of the basic version. To that end, rather than copying the work of others, the direction here shifted towards a hybrid trailing stop loss with a bunch of additional user customisation options. At some point, a completely different project involving IQR got morphed into this one. After sitting through months of sideways chop (where this proved to be of limited use), at the time of publication the market has began to form some near term trend direction and it appears to be performing well in many different timeframes.
And so with that out of the way...
INPUTS
The standard Supertrend (and most other variants) includes a single source input, as default set to 'hl2' (candle mid-range). This is the centre around which the atr bands are added/subtracted to govern the stop levels. This is not however the value which is used to trigger the trend reversal, that is usually hard-coded to 'close'. For this version both source values are adjustable: labelled 'centre' and 'trigger' respectively.
Each has custom input selectors including the usual options, a selection of 'weighted inputs' and the option to use another indicator (selected from the Aux input). The 'weighted inputs' are those introduced in Weight Gain 4000, for more details please refer to that listing. These should be treated as experimental, however may prove useful in certain configurations. In this case 'hl-oc2' can be considered an estimate of the candle median and may be a good alternative to the default 'centre' setting of 'hl2', in contrast 'cc-ohlc4' can tend to favour the extremes in the trend direction so could be useful as a faster 'trigger' than the default 'close'.
To cap them off both come with a selection of moving average filters (SMA, EMA, WMA, RMA, HMA, VWMA and a simple VWEMA - note: not elastic) aswell as median and mid-range. 'Centre' can also be set to the output of 'trigger' post-filter which can be useful if working with fast/slow crosses as the basis.
DYNAMICS
This is the main section, comprised of three separate factors: 'TSL', 'ATR' and 'IQR'. The first two should be fairly obvious, 'TSL' (trailing stop loss) is simply a percentage of the 'centre' value while 'ATR' (average true range) is the standard RMA-based version as used in Supertrend, Volatility Stop etc.
The third factor is less common however: 'IQR' (inter-quartile range). In case you are unfamiliar the principle here is, for a given dataset, the greatest 25% and smallest 25% of samples are removed. The remainder is then treated as a set and the range is calculated by highest - lowest. This is a commonly used method in statistical analysis, by removing the extremes it is less prone to influence by outliers and gives a good representation of the main dispersion around the median. In practise i have found it can be a good alternative to ATR, translating better across multiple time-frames due to it representing a fraction of the total range rather than an average of per-candle range like ATR. Used in combination with the others it can also add a factor more representative of longer-term/higher-timeframe trend. By discarding outliers it also benefits from not being impacted by brief pumps/volatility, instead responding only to more sustained changes in trend, such as rallies and parabolic moves. In order to give an accurate result the IQR is calculated using a dataset of high, low and hlcc4 values for all bars within the lookback length. Once calculated this value is then halved which, strictly speaking, makes it a semi-interquartile range.
All three of these components can be used individually or summed together to create a hybrid dynamics factor. Furthermore each multiplier can be set to both positive and negative values allowing for some interesting and creative possibilities. An optional smoothing filter can be applied to the sum, this is a basic SWMA-4 which is can reduce the impact of sudden changes but does incur a noticeable lag. Finally, a basic limiter condition has been hard-coded here to prevent the sum total from ever going below zero.
Capping off this section is a pair of direction multipliers. These simply take the prior dynamics sum and allow for further multiplication applied only to one side (uptrend/lo-stop and downtrend/hi-stop). To see why this is useful consider that markets often behave differently in each direction, we've all seen prices steadily climb over several weeks and then abruptly dump in the process of a day or two, shorter time frames are no stranger to this either. A lack of downside liquidity, a panicked market, aggressive shorts. All these things contribute to significant differences in downward price action. This function allows for tighter stops in one direction compared to the other to reflect this imbalance.
VISUALISATIONS
With all of these options and possibilities, some visual aids are useful. Beneath the dynamics' section are several visual options including both sources post-filter and the actual 'bands' created by the dynamics. These are what govern the stop levels and seeing them in full can help to better understand what our various configurations actually do. We can even hide the stop levels altogether and just use the bands, making this a kind of expanded Keltner Channel. Here we can also find colour and opacity settings for everything we've discussed.
EXAMPLES
The obvious first example here is the standard %-change trailing stop loss which, from my experience, tends to be the best suited for lower time frames. Filtering should probably minimal here. In both charts here we use the default config for source inputs, the top is a standard bi-directional setup with 1.5% tsl while the bottom uses a 2.5% tsl with the histop multiplier reduced to 0 resulting in an uptrend only stoploss.
Shown here in grey is the standard Supertrend which uses 'hl2' as centre and 'close' as trigger, ATR(10) multiplied by 3. On top we have the default filtered source config with ATR(8) multiplied by 2 which gives a different yet functionally similar result, below is the same source config instead using IQR(12) multiplied by 2. Notice here the more 'stepped' response from IQR following the central rally, holding back for a while before closing in on price and ultimately initiating reversal much sooner. Unlike ATR, the length parameter for IQR is absolute and can more significantly affect its responsiveness.
Next we focus on the visualisation options, on top we have the default source config with ATR(8) multiplied by 2 and IQR(12) multiplied by 1. Here we have activated the switch to show 'bands', from this we can see the actual summed dynamics and how it influences the stop levels. Below that we have an altogether different config utilising the included filters which are now visible. In this example we have created a basic 8/21 EMA cross and set a 1% TSL, notice the brief fakeout in the middle which ordinarily might indicate a buy signal. Here the TSL functions as an additional requirement which in this case is not met and thus no buy signal is given.
Finally we have a couple of more 'experimental' examples. On top we have Lazybear's 'Variable Moving Average' in white which has been assigned via 'aux' as the centre with no additional filtering, the default config for trigger is used here and a basic TSL of 1.5% added. It's a simple example but it shows how this can be applied to other indicators. At the bottom we return to the default source config, combining a TSL of 8% with IQR(24) multiplied by -2. Note here the negative IQR with greater length which causes the stop to close in on price following significant deviations while otherwise remaining fairly wide. Combining positive and negative multiples of each factor can yield mixed results, some more useful than others depending upon suitable market conditions.
Since this has been quite lengthy, i shall leave it there. Suffice to say that there are plenty more ways to use this besides these examples. Please feel free to share any of your own ideas in the comments below. Enjoy.
Tweaker
WAP Maverick - (Dual EMA Smoothed VWAP) - [mutantdog]Short Version:
This here is my take on the popular VWAP indicator with several novel features including:
Dual EMA smoothing.
Arithmetic and Harmonic Mean plots.
Custom Anchor feat. Intraday Session Sizes.
2 Pairs of Bands.
Side Input for Connection to other Indicator.
This can be used 'out of the box' as a replacement VWAP, benefitting from smoother transitions and easy-to-use custom alerts.
By design however, this is intended to be a highly customisable alternative with many adjustable parameters and a pseudo-modular input system to connect with another indicator. Well suited for the tweakers around here and those who like to get a little more creative.
I made this primarily for crypto although it should work for other markets. Default settings are best suited to 15m timeframe - the anchor of 1 week is ideal for crypto which often follows a cyclical nature from Monday through Sunday. In 15m, the default ema length of 21 means that the wap comes to match a standard vwap towards the end of Monday. If using higher chart timeframes, i recommend decreasing the ema length to closely match this principle (suggested: for 1h chart, try length = 8; for 4h chart, length = 2 or 3 should suffice).
Note: the use of harmonic mean calculations will cause problems on any data source incorporating both positive and negative values, it may also return unusable results on extremely low-value charts (eg: low-sat coins in /btc pairs).
Long version:
The development of this project was one driven more by experimentation than a specific end-goal, however i have tried to fine-tune everything into a coherent usable end-product. With that in mind then, this walkthrough will follow something of a development chronology as i dissect the various functions.
DUAL-EMA SMOOTHING
At its core this is based upon / adapted from the standard vwap indicator provided by TradingView although I have modified and changed most of it. The first mod is the dual ema smoothing. Rather than simply applying an ema to the output of the standard vwap function, instead i have incorporated the ema in a manner analogous to the way smas are used within a standard vwma. Sticking for now with the arithmetic mean, the basic vwap calculation is simply sum(source * volume) / sum(volume) across the anchored period. In this case i have simply applied an ema to each of the numerator and denominator values resulting in ema(sum(source * volume)) / ema(sum(volume)) with the ema length independent of the anchor. This results in smoother (albeit slower) transitions than the aforementioned post-vwap method. Furthermore in the case when anchor period is equal to current timeframe, the result is a basic volume-weighted ema.
The example below shows a standard vwap (1week anchor) in blue, a 21-ema applied to the vwap in purple and a dual-21-ema smoothed wap in gold. Notably both ema types come to effectively resemble the standard vwap after around 24 hours into the new anchor session but how they behave in the meantime is very different. The dual-ema transitions quite gradually while the post-vwap ema immediately sets about trying to catch up. Incidentally. a similar and slower variation of the dual-ema can be achieved with dual-rma although i have not included it in this indicator, attempted analogues using sma or wma were far less useful however.
STANDARD DEVIATION AND BANDS
With this updated calculation, a corresponding update to the standard deviation is also required. The vwap has its own anchored volume-weighted st.dev but this cannot be used in combination with the ema smoothing so instead it has been recalculated appropriately. There are two pairs of bands with separate multipliers (stepped to 0.1x) and in both cases high and low bands can be activated or deactivated individually. An example usage for this would be to create different upper and lower bands for profit and stoploss targets. Alerts can be set easily for different crossing conditions, more on this later.
Alongside the bands, i have also added the option to shift ('Deviate') the entire indicator up or down according to a multiple of the corrected st.dev value. This has many potential uses, for example if we want to bias our analysis in one direction it may be useful to move the wap in the opposite. Or if the asset is trading within a narrow range and we are waiting on a breakout, we could shift to the desired level and set alerts accordingly. The 'Deviate' parameter applies to the entire indicator including the bands which will remain centred on the main WAP.
CUSTOM (W)ANCHOR
Ever thought about using a vwap with anchor periods smaller than a day? Here you can do just that. I've removed the Earnings/Dividends/Splits options from the basic vwap and added an 'Intraday' option instead. When selected, a custom anchor length can be created as a multiple of minutes (default steps of 60 mins but can input any value from 0 - 1440). While this may not seem at first like a useful feature for anyone except hi-speed scalpers, this actually offers more interesting potential than it appears.
When set to 0 minutes the current timeframe is always used, turning this into the basic volume-weighted ema mentioned earlier. When using other low time frames the anchor can act as a pre-ema filter creating a stepped effect akin to an adaptive MA. Used in combination with the bands, the result is a kind of volume-weighted adaptive exponential bollinger band; if such a thing does not already exist then this is where you create it. Alternatively, by combining two instances you may find potential interesting crosses between an intraday wap and a standard timeframe wap. Below is an example set to intraday with 480 mins, 2x st.dev bands and ema length 21. Included for comparison in purple is a standard 21 ema.
I'm sure there are many potential uses to be found here, so be creative and please share anything you come up with in the comments.
ARITHMETIC AND HARMONIC MEAN CALCULATIONS
The standard vwap uses the arithmetic mean in its calculation. Indeed, most mean calculations tend to be arithmetic: sma being the most widely used example. When volume weighting is involved though this can lead to a slight bias in favour of upward moves over downward. While the effect of this is minor, over longer anchor periods it can become increasingly significant. The harmonic mean, on the other hand, has the opposite effect which results in a value that is always lower than the arithmetic mean. By viewing both arithmetic and harmonic waps together, the extent to which they diverge from each other can be used as a visual reference of how much price has changed during the anchored period.
Furthermore, the harmonic mean may actually be the more appropriate one to use during downtrends or bearish periods, in principle at least. Consider that a short trade is functionally the same as a long trade on the inverse of the pair (eg: selling BTC/USD is the same as buying USD/BTC). With the harmonic mean being an inverse of the arithmetic then, it makes sense to use it instead. To illustrate this below is a snapshot of LUNA/USDT on the left with its inverse 1/(LUNA/USDT) = USDT/LUNA on the right. On both charts is a wap with identical settings, note the resistance on the left and its corresponding support on the right. It should be easy from this to see that the lower harmonic wap on the left corresponds to the upper arithmetic wap on the right. Thus, it would appear that the harmonic mean should be used in a downtrend. In principle, at least...
In reality though, it is not quite so black and white. Rarely are these values exact in their predictions and the sort of range one should allow for inaccuracies will likely be greater than the difference between these two means. Furthermore, the ema smoothing has already introduced some lag and thus additional inaccuracies. Nevertheless, the symmetry warrants its inclusion.
SIDE INPUT & ALERTS
Finally we move on to the pseudo-modular component here. While TradingView allows some interoperability between indicators, it is limited to just one connection. Any attempt to use multiple source inputs will remove this functionality completely. The workaround here is to instead use custom 'string' input menus for additional sources, preserving this function in the sole 'source' input. In this case, since the wap itself is dependant only price and volume, i have repurposed the full 'source' into the second 'side' input. This allows for a separate indicator to interact with this one that can be used for triggering alerts. You could even use another instance of this one (there is a hidden wap:mid plot intended for this use which is the midpoint between both means). Note that deleting a connected indicator may result in the deletion of those connected to it.
Preset alertconditions are available for crossings of the side input above and below the main wap, alongside several customisable alerts with corresponding visual markers based upon selectable conditions. Alerts for band crossings apply only to those that are active and only crossings of the type specified within the 'crosses' subsection of the indicator settings. The included options make it easy to create buy alerts specific to certain bands with sell alerts specific to other bands. The chart below shows two instances with differing anchor periods, both are connected with buy and sell alerts enabled for visible bands.
Okay... So that just about covers it here, i think. As mentioned earlier this is the product of various experiments while i have been learning my way around PineScript. Some of those experiments have been branched off from this in order to not over-clutter it with functions. The pseudo-modular design and the 'side' input are the result of an attempt to create a connective framework across various projects. Even on its own though, this should offer plenty of tweaking potential for anyone who likes to venture away from the usual standards, all the while still retaining its core purpose as a traders tool.
Thanks for checking this out. I look forward to any feedback below.