RedK_Portfolio Tracker v2: few enhancements and display optionsThis is an update for the PTracker v1 that I published couple of days ago. wanted to publish this as a separate script to get a chance to show how the new Portfolio Summary Infobox can be displayed on the price chart as an option. In my opinion, that info box is the most important element in this tool and that's the piece i was most looking for.
quick note here: you can track your portfolio (if not so many positions) by entering something like (without the brackets) in TradingView's chart symbol area - TradingView will resolve these symbols and chart the total -- there's a nice post by our friend @boji1 about this in a lot more details - however, that wouldn't show the stats that i need to look at to track my portfolio on daily basis.
i also made couple of other enhancements, like adding the ability to include "free cash" in the portfolio - While this free cash value will impact the Total P/L and P/L %, as part of the overall portfolio (and the denominator), it will not impact the "cost of positions" or the (current) "value of positions" -- also "Cash" will not count towards the total 10 positions that we can track with this tool.
Using Portfolio Tracker as a floating panel on the price chart
====================================================
By default, when the Portfolio Tracker is added to the chart, it will occupy its own lower panel like the picture above.
if your charts are already busy (like mine :)) - you most probably already have a couple of lower studies and it's crowded there.
in this case, you can use the Object Tree tool after adding the PTracker, to drag it onto the price panel, or you can also do that by right-clicking on the infobox and choose to move up to the price panel.
when you do that, remember to also use the Style settings of PTracker to hide both Portfolio and PnL plots, and choose Scale = no scale - this way you get the infobox to work like a floating panel on the price chart
here's a screenshot that shows this scenario - also shows how the infobox color can be easily changed from the PTracker settings to suit your chart background and for best visibility
i hope this is useful in your trading - i look forward to @TradingView team surprising us with a real portfolio tracking capability soon :)
good luck.
Redk
Simple Portfolio TrackerThis is just a simple portfolio tracker that i started to play around with - i'm sure there are smarter ways to do this, but i chose the simpler way :) -- please feel free to use this, or consider it as a starting point to your own indicator.
i will come back later and add some more stuff once i get time. for example, show the total value, recent change, P&L % ..etc
So the simple idea is to track a portfolio of few positions and watch how the total portfolio and the PnL changes over time as the price of the individual holdings move up and down. it can be added to any chart.
The code is currently set to track 5 positions - settings allow to enter if the positions is used or not, symbol, amount and cost price..
** note: more positions can be added by editing the code and copying and pasting the marked "position block" that contains the input statements and the calculations, then changing/replacing the position identifier (_1, _2, ..etc) in all variables with new number..
--- don't forget to add these extra positions you insert in the code to the formula lines that calculate the totals
i tried to make this as easy as possible in the code. the code includes a sample portfolio as default values just to help "demo" how this works
the input is made easy, thanks to the recent addition of the "inline" feature in the input() statement
i don't know if some traders will find this useful ?? or if more about how to use it is needed.. let me know in the comments.. as i mentioned, i was just playing with the idea over the weekend so didn't really put a lot of work into it.
Credits and thanks to @boji1 for inspiring this :)
RedK Trader Pressure Index (TPX v1.0) Quick Summary
---------------------
The RedK Trader Pressure Index (REDK_TPX) analyzes the changes in price bars to give the trader a clear visual insight that represents the ongoing fight between the bulls (buyers) and bears (sellers) in the market - to determine who is in control of the price action, which in turn can be helpful in a trader’s decision about how the price action may be unfolding, what type of trade and positions to take (or to close) and when is the ideal time to action.
How the TPX calculation works
---------------------------------------
The TPX uses a simple logic and that’s one of the things I like about it – there is no complex calculation or magic stuff - and the core idea makes sense to me, as well as being one of the ways I needed to analyze my price charts.
The underlying assumption is that the buyers and sellers are competing for control of the market at all time.
- if there’s more buyers than sellers in the market, and if the buyers’ (or bull) pressure is stronger (than the sellers’), they will be able pull the “price range” up – and that means that on the price chart we can expect to see an increase in value in both the “high” and the “low” of the next price bar.
- Similarly, if there’s more sellers than buyers in the market, and if the sellers’ (or bear) pressure is stronger (than the buyers’), they will be able push the “price range” down – on the price chart we can expect to see a decrease in value in both the “high” and the “low” of the next price bar.
So, we will use the change in high and low price, between 2 consecutive price bars, as a proxy for the bull and bear “pressures” – a (weighted) moving average of these “pressure” values are then calculated along with the “Net Pressure” – the final results are plotted.
The importance of the "Control Level"
-----------------------------------------------
As in similar price-action based indicators, there’s a certain threshold or “control level”, above which, the pressure becomes “dominant”
when the bull or bear pressure is above that threshold, they will dominate and control the price move – this level can be found around the 25 or 30. I have included the ability to plot and adjust that control level in the TPX’s settings – and I also show some examples in the chart above (weekly chart for MSFT)
The code is commented and the chart is annotated to explain how to “read” the TPX – and how to interpret the values on the price chart
Using the Trader Pressure Index (TPX) in trading
------------------------------------------------------------
TPX can be valuable in showing well-supported (up or down) price moves that may lead to a strong trend that we can ride (when the pressure value is above the control level) - see exampled above
TPX is also valuable in showing when there’s “lack of interest” from the buyers or the sellers (or both) – which is great in exploring chub or no-trade zones - so basically when to avoid trading.
As usual, it's always recommended to use these types of "price action insight" indicators in conjunction with other trend and momentum indicators (moving averages, MACD..etc), so the insight we gain from them can be properly placed within the broader "context" - and to receive additional confimtion signals to support the trading decision.
I will come back later to post something about how the TPX differs from my recently-posted Strength of Movement (SoM) because they wok completely differently but can be used together with great synergy – and also how the TPX compares to the classic DMI/ADX which uses a similar concept.
Please feel free to integrate in your trading – hope you find this useful - comments and feedback are always welcome
RedK Dual-Color Zero-Lag Moving Average (RedK ZLMA v1)Here's my Dual-color Zero-Lag Moving Average indicator - with alerts - as a separate study
This is published in response to couple of requests i received. Please refer to previous posts on TA Basics on creating zero-lag MAs for more background.
This version adds couple of extras
---------------------------------------------
- the ability to choose the price being used (close vs hl2, hlc3..etc)
- ability to change resolution
the example chart below on the right uses a weekly resolution for the ZLMA on top of a daily chart - the left chart shows the same view but with the ZLMA resolution set to "same as chart"
- Alerts-enabled for when trend change is detected
- optional smoothing - keep the smoothing low (3 or 4) else it introduces lagging again
i hope some will find this useful
- the code is light and can easily be integrated into other indicators of your own - or you can add this ZLMA to your charts in combination with other MA's you use to easily identify trends and swings.
let me know your feedback.
Good luck!
RedK Strength of MovementThis is a quick indicator i wrote to inspect the strength of price movement and show when what i consider to be "a quality trend" has been established. the code is open and commented - the "math concept" is really simple and i'm not sure if this has already been coded before :) - my apologies if it was.
my main goal was to identify opportunities to establish "simple, straight" long call or put positions for the stocks i follow
- what i noticed thru the years is that some opportunities will present themselves to take these basic option positions but they are "rare", maybe once or twice a year -- for example, in 2020, TSLA presented 2 such opportunities around the split and the index inclusion - so i needed an indicator that exposes these setups. if you can time yourself with these setups, they are incredibly rewarding.
these setups will happen when the SoM reaches 100% (in either directions) while it's in agreement with the prevailing trend (hence the need to use the SoM with a MACD or something like the Ribbon) - if the SoM hits the 100% in one direction and the trend is not in the same direction, that signal is invalid. see the chart for some examples.
a quick useful observation, is that the SoM will sometimes also act as a leading indicator for an imminent change in trend direction, which makes sense .. given that the SoM relies on exposing the "relative" movement or change of price (close for example) - thru the use of the stoch() function - and that this "change value" will usually expand in the direction of a strong trend and starts to contract ahead of a reversal.
Please fee free to use this code, leverage the indicator, or give feedback
i may come back later and update this with some features (like making this volume-weighted)
best of luck!
RedK_xMACD: Extending the classic MACD with a simple filterThis is a simple concept that attempts to squeeze more price action insights from the classic MACD
we add a 3rd (longer length, slower) Moving Average line that acts as a trend filter - so whenever we are ("we" = the price and the 2 other MAs) are above that filter line, we consider ourselves to be in the up-trend territory, and vica versa .. so the MACD calculation here - that is represented by the main (reg/green) line in the plot - will represent the distance between the slow MA and the filter MA - when that MACD line crosses the zero axis up or down, that represents the trand reversing from one direction to the other.
A signal line (a smoothed version of that MACD line) is still added for 2 reasons
1 - the signal line makes it easy to see if an eminent trend reversal is to be expected
2 - to stay visually-consistent with the classic MACD :)
the distance (or delta) between the other 2 MAs continues to reflect an indication of the short-term momentum and is what the histogram represents.
we still have the benefit of the convergence/diversion between the price itself and the histogram similar to the classic MACD
this MACD version will also clearly show how price and momentum action will lead the trend -- i know that's a big discussion topic :)
i added a classic MACD at the bottom panel, and used the same length settings (fast / slow) for side-by-side comparison
i coded this when i found that i use 3 moving averages all the time during my chart analysis, and while i'm a big fan of the classic MACD, i wanted to find a simple way to get my MACD to reflect what the 3 MAs on the price chart show. turned out to be insightful - i hope other fellow traders may find this useful
the code is simple and i started it from the built-in MACD in TradingView. Other annotations are added to the chart here as i believe this will better explain how the eXtended MACD works
- there are 4 reversals that occur in that chart, and i chose to show one in step-by-step fashion.
if more explanation is needed to how this can be used, pls let me know in the comments.
Ultimate Trader Oscillator - UTO v1Note; this is experimental / learning work -- has nothing to do with the existing "Ultimate Oscillator" -- i call this project UTOpia :)
This is based on some research work i was doing around the Balance Of Power - which i posted about in the past
the conclusion form there was a questions of, what would we get if we create an indicator that takes into consideration other factors that may be affecting momentum - so while the classic Balance of Power formula looks at where the open and close of a bar are compared to the full bar range, this is only a small part of the insight we need - when we visually inspect a price chart, we also look at many other factors. for example, how the bar closes compared to previous bar(s), how much did the bulls (or bears) managed to move the high (or low) of the bar compared to previous one, how much volume, how is the price spread ...etc
so i wanted to build an indicator that does exactly that - we will give a score of +100 / -100 to each bar based on these factors (some were identified in the linked post) -- imagine here that we are a judge in a tug of war contest (or a beauty contest if you would :)) and we give a score to the participating teams - the scores are given in different "categories" as these teams make effort to win the game (each bar) - to be totally fair, in some scoring categories, we choose to take the average of 3 points for a fair assessment - the final score is calculated based on the average from all judges - and then and average over the desired length is calculated. this score should be very fair and represents the true effort from all angles, right? that would be our UTOPIA :)
in our case, we don't use an average of total score after each category is evaluated, but rather create a directional index (similar to RSI) -- so we can avoid big spikes in the resulting numbers, and maintain a oscillator -like result.
-- the code is commented to explain the various pieces - and how the scoring happen.
the results are interesting - and you can see how the UTO stacks against the classic RSI and BoP - but it's more of a work to build on, rather than a usable indicator - although i do use it in my own trading :)
one final thought here, i came to learn after few years that the best indicators do not necessarily lead to profitable trading. from an indicator standpoint, if everyone else is trading using (for example) a moving average crossover or RSI, then a successful trader should be looking at these classic indicators too, cause these common indicators will drive the mass behavior - and will at many times trigger "self- fulfilling prophesies" in price action - but that's not the only or the biggest reason - the big reasons have to do with the fact that trading needs a lot of effort outside the charts, in researching markets, learning the discipline, then managing positions and managing the portfolio. these are all big topics to put in such short words.
i hope some will find this work inspiring.
RedK_AvgMoneyFlow Oscillator v1This is a compact & simple study that tracks the short-term average price change and the (average) volume associated with it, to generate a very clear signal when a change of buying/selling flow is detected. these buy/sell cycles can happen within a longer "demand / trend-up" or "supply / trend down" phases as we know.
this concept is a bit different from MFI or CMF. The math we use here is simpler, and more "relative" and short-term focused, deliberately.
how does it work
===============
once the average price change and the average volumes are calculated for the specified length, we then turn that into a +100/-100 oscillator format - using the stoch() function - which helps to generate a clearly identifiable unambiguous signal (crossing the zero line up or down) that help traders (mainly with entries)
-- the stoch() function also makes the oscillator "relative" to the specified period length, meaning, we can be in a uptrend (demand mode) and the MFO is showing flow "out" (negative) - that's specific to the short-term period - and that's exactly what i was trying to see
- the thinking here is that the best spot to go long is when the existing selling has been depleted and no more supply exists (during an uptrend), and vice verca.
- other stuff: i use WMA() throughout the script -- and we apply a smoothing for the final plot. keep smoothing to a minimum to avoid unnecessary lag in the signals
- the signal should be considered *after* a bar is fully closed.
Suggested Use
==============
i suggest you use this in combination with other indicators that can show the overall short-term and long-term bias (for example, i use the Ribbon here for that) - and take only entry signals in the same direction - a signal to go long, for example, would be when the bias / trend is up *and* the MFO crosses the zero line *going up* .. you may need to wait for that setup to show before you hit the trigger.
another benefit here, is that MFO will also detect strengths and weaknesses - when we see diversion with price movement. this shows couple of times in the example below
Please Note
============
i do not do short-term trading / scalping - those who do, i hope may find this useful - if you decide to use it and you do find it useful, please post feedback here for the common learning
Good luck!
RedK Ribbon v2: Tracking Trend Made EasyThis is an update for the previously published RedK_Ribbon v1 -- and it adds some (hopefully) useful improvements:
1 - the Zero-Lag line is color-coded, to provide an early visual alert that momentum is fading, and the trend direction may change soon
2 - better colors for the ribbon :) - for the visually-oriented folks like me :)
3 - i added two optional EMAs that can be utilized as filters for the longer sentiment - to help a trader take positions only in the direction of the prevailing trends. note that these 2 EMA lines will be hidden by default until selected in the settings - to avoid clutter . Set to 30 and 50 by default but these lengths can be changed as needed
4 - code is open and commented
If you need to learn how we create the zero-lag moving average, pls refer to the "TA Basics" series - and if you need to learn more about how the Ribbon works, pls read the Ribbon v1 post
hope this is useful in your trading - and good luck!
TA Basics: further "Steps" with our Moving AverageSo far in this series of posts, we have worked thru creating a basic zero-lag moving average, then moved forward all the way to coding a "Fibonacci" Weighted Moving Average.
in this post we take a look at a technique that can help traders minimize noise in the underlying data and get better insight on the changes that are happening in the data series represented by the moving average. we'll look at adding "stepping" to our Fibonacci Moving Average as an example. we introduce the Stepping Fibonacci Moving Average , or Step_FiMA
note that you can use the same technique with any plot you may have. feel free to copy or leverage the relevant parts of the script - the script is commented to make this easier.
How is this useful?
==================
with "stepping", you get your indicator to "round" the outcome into pre-specified bands or ranges. this works very similar to how, for example, range or Renko charts work. you can easily see the difference in the chart above once we look at a non-stepped and a stepping moving average of the same length side-by-side
the more granular your timeframe is, you will see the effect of the stepping clearer - here's how the same chart looks when we go into the 1-hr aggregation
Notes about this script
====================
there are couple of pieces i wanted to highlight in the script if you plan to use some of it :
1 - the step(x) function is meant to try to automatically pick the best "suitable" step size based on the range of the underlying series (for example, the closing price). these ranges i included here in the code are just my own "best choices" - you are totally welcome to adjust these ranges and the resulting step size to your own preference
2 - we applied the stepping as a user-choice. user can choose a manual entry, or "0" to get the code to automatically pick the step size, or enter -1 (or actually any value below zero) to cancel the stepping option altogether - this gives us some flexibility on how to use the stepping in an indicator
3 - very important (and somehow confusing): on the "rounding" approach:
the magic math formula that actually creates the stepping is this one
result = round(input / step) * step
now, this tells the script to "round" the result up or down (the basic rounding) -- so for example, a price of 17 with a step of 5 would be rounded (down) to 15, where as a price of 18 would be rounded "up" to 20 -- this is not the way some of us would expect or want, cause the price never reached 20 and they would want an 18 to still be rounded to 15 - and the stepping line not to show 20 *until* the price actually hits or exceeds 20 -- in that case, you would need to replace the function "round" with the function "floor" --
so the new formula becomes: floor(input / step) * step
-- in an ideal world, we can make this rounding choice a user-option in the settings -- maybe in an improved version
4 - we kept the smoothing option, and it takes place before the stepping is applied - we continue to use that smoothing to further minimize the level changes in the FiMA line.
I hope you find this script useful in your journey with technical analysis and DIY scripting, and good luck in your trading.
TA Basics: Creating a Fibonacci Weighted Moving AverageIn the previous 2 posts in this series, we played around with simple math concepts to create a zero-lag moving average that can deliver fast response and less lag - that we can use to enable better trend following, or as filter / signal.
here we take a step further - instead of using equal weight for the moving average (as in the Simple moving average) or linear weights (as in the weighted moving average), we get to pick THE MAGIC SEQUENCE, Fibonacci.
we will use the Fibonacci Sequence as weights to produce our moving average - so practically, we create a "Fibonacci Weighted Moving Average" (let's call it FiMA) - and compare the result with other commonly-used moving averages of the same length
in a Fibonacci moving average, the data will be weighted based on the Fibonacci Series starting from 1 (for the furthest data point)
so for example, if we use a length of 10, the weights will be 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 with the 55 being the weight applied to the most recent / current bar's selected value (close, hl2, hc3..etc) and moving backward
before i posted this script, i searched around to see if someone else has already wrote this - i found a couple, but the approach we use here in this code is different - i can't claim it to be more efficient - i honestly don't know - but the resulting code here, IMHO, is more compact and easier to integrate in other studies that you may like to put together to leverage this idea, to create your own indicators and strategies.
the reason the code here is more compact, is that it utilizes a shorter formula to calculate the FIb(n) - i included the source where i found that formula, and i tested it before using it in the code.
i also added an optional "extra smoothing" for the resulting MA, by simply calling the fima() function a second time (so like doing a 2-pass filter), with a smaller length on the result of the 1st pass. keep this smoothing small not to produce too much lag.
i like the outcome when compared to other moving averages - it has a fast response to data/trend change and less overshoot - but honesty i didn't see any real "Fibonacci Magic" :) .. but i'll leave the final judgement to those who use it - this is more of an experimental code in all cases - please feel free to use, change and share feedback.
RedK_Supply/Demand Volume Viewer v1Background
============
VolumeViewer is a volume indicator, that offers a simple way to estimate the movement and balance (or lack of) of supply & demand volume based on the shape of the price bar. i put this together few years ago and i have a version of this published for another platform under different names (Directional Volume, BetterVolume) in case you come across them
what is V.Viewer
=====================
The idea here is to find a "simple proxy" for estimating the demand or supply portions of a volume bar - these 2 forces have the potential to affect the current price trend so we want an easy way to track them - or to understand if a stock is in accumulation or distribution - we want to do this without having access to Level II or bid/ask data, and without having to get into the complexity of exploring the lower timeframe price & volume data
- to achieve that, we depend on a simple assumption, that the volume associated with an up move is "demand" and the volume associated with a down move is "Supply". so we basically extrapolate these supply and demand values based on how the bar looks like - a full "green" price bar / candle will be considered 100% demand, and a full "red" price bar will be considered 100% supply - a bar that opens and closes at the same level will be 50/50 split between supply & demand.
- you may say this is a "too simple" of an assumption to make, but believe me, it works :) at least at the basic scenario we need here: i'm just exploring the volume movement and finding key levels - and it provides a good improvement compared to the classic way we see volume on a chart - which is still available here in VolumeViewer.
in all cases, i consider this to be work in progress, so i'd welcome any ideas to improve (without getting too complicated) - there's already a host of great volume-based indicators that will do the multi timeframe drill down, but that's not my scope here.
Technical Jargon & calculation
===========================
1. first we calculate a score % for the volume portion that is considered demand based on the bar shape
skip this part if it sounds too technical => if you're into coding indicators, you would probably know there are couple of different concepts for that algorithm - for example, the one used in Balance Of Power formula - which i'm a big fan of - but the one i use here is different. (how?) this is my own, ant it simply applies double weight for the "wick" parts of a price bar compared to the "body of the bar" -- i did some side-by-side comparison in past and decided this one works better. you can change it in the code if you like
2. after calculating the Bull vs Bears portion of volume, we take a moving average of both for the length you set, to come up with what we consider to be the Demand vs Supply - as usual, i use a weighted moving average (WMA) here.
3. the balance or net volume between these 2 lines is calculated, then we apply a final smoothing and that's the main plot we will get
4. being a very visual person, i did my best to build up the visuals in the correct order - then also to ensure the "study title" bar is properly organized and is simple and useful (Full Volume, Supply, Demand, Net Volume).
- i wish there was a way in Pine to hide a value that i still need to visually plot but don't want it showing its value on the study title bar, but couldn't find it. so the last plot value is repeated twice.
How to use
===========
- V.Viewer is set up to show the simplified view by default for simplicity. so when you first add it to a chart, you will get only the supply vs demand view you can see in the middle pane in the above chart
- Optional / detailed mode: go into the settings, and expose all other plots, you will be able to add the classic volume histogram, and the Supply / Demand lines - note these 2 lines will be overlay-ed on top of each other - this provides an easy way to see who is in control - especially if you change the display of these 2 lines into "area" style. This is what is showing in the lower pane in the above chart.
** Exploring Key Price Levels
- the premise is, at spots where there's big lack of balance, that's where to expect to find key price levels (support / resistance) and these price levels will come into play in future so can be used to set entry / exit targets for our trades - see the example in the AAPL chart where you can easily locate these "balance or reversal levels" using the tops/bottoms/zero-crossings from the Net Volume line
** Use for longer-term Price Analysis
- we can also use this simple indicator to gain more insights (at a high level) of the price in terms of accumulation vs distribution and if the sellers or buyers are in control - for example, in the above AAPL chart, V.Viewer tells us that buyers have been in control since October 19 - even during the recent drop, demand continued to be in play - compare that to DIS chart below for the same period, where it shows that the market was dumping DIS thru the weakness. DIS was bleeding red most of the time
Final thoughts
=============
- V.Viewer is an attempt to enhance the way we see and use Volume by leveraging the shape of the price bar to estimate volume supply & demand - and the Net between the 2
- it will work for stocks and other instruments as long as there's volume data
- note that V.Viewer does not track trend. each bar is taken in isolation of prior bars - the price may be going down and V.Viewer is showing supply going up (absorption scenario?) - so i suggest you do not use it to make decisions without consulting other trend / momentum indicators - of course this is a possible improvement idea, or can be implemented in another indicator, add in trend somehow, or maybe think of making this a +100 / -100 Oscillator .. feel free to play with these thoughts
- all thoughts welcome - if this is useful to you in your trading, please share with other trades here to learn from each other
- the code is commented - please feel free to use it as you like, or build things on top of it - but please continue to credit the author of this code :)
good luck!
-
TA Basics: Evolving our Zero Lag Moving Average.In the previous Zero-Lag MA post, we introduced the "mirroring" technique and the associated calculation.
In this post, we will see how we can use the same technique, with a slight variation, to evolve our zero lag moving average line, add more "smoothness" and still maintaining the low lag and fast response to data series changes.
to use the "mirroring" technique, we need to use 2 MA lines with varying speeds - this is essential to produce the delta between the lines, that can then be mirrored around the fast line to produce the final line. in the first example, we used a Simple MA (slow) and a Weighted MA (fast) of the same length to achieve that.
here we introduce a different way of doing that. we will use a Weighted MA of the length (slow) and another Weighted MA of half the length (fast) -- the difference in "speed" between these 2 lines should produce the delta we need, we mirror it around the fast line, and we get our desired Zero-lag line. Check!
then while we're at it, why don't we introduce an additional smoothing just to ensure the new line is not too "broken" and jumpy .. and flows smoothly across the data series. but what length should we use for smoothing?
smoothing length should be enough to make an actual smoothing effect, but not too large else it will introduce lagging on its own. how about 3? usually 3 or 4 are good values for smoothing. A brilliant idea here is to use a number related to the same input length of the original line, which can always be relatively small -- the square root (integer portion) of that original length - and in that case, the user will only need to enter 1 input for the moving average, just the length - everything will be calculated from there. Check again!
I commented the code if you like to follow the simplified build-up of the formula, now that the concept is explained.
the (more complex-looking) 1-line, condensed form of that formula to use is (alert: watch out for the ()'s -- they're tricky :) )
----------------------------------------------
ZLMA_Line = wma((2*wma(close,int(length/2)) - wma(close,length)), int(sqrt(length)))
------------------------------------------
the one thing i do not like about this technique, is that we introduce the use of the half length MA. i do not like to build indicators that make decisions like this on behalf of the trader - the trader wants to analyze the data for a specific length, and we should continue to stick to that consistently across the moving average (or whatever indicator) calculation. I would always be caution about "hardcoding" some optional values (in this case 0.5 * length) within the indicator itself - others may not mind that.
Now to a nice surprise for the patient folks who got so far in this post - Congratulations, we have just discovered the concept and the formula behind the famous Hull Moving Average .. the big thing here is, we just had the opportunity to learn how to create the whole thing ourselves from the ground up step by step, and had fun doing it (I hope!)
-- these posts are meant to provide those who are new to the world of technical analysis and want to learn how and why to build their own technical indicators. i hope some of you find them useful and interesting, and i wish you the best of luck.
TA Basics: Creating a Zero Lag Moving Average using "Mirroring"we all know how moving averages suffer from lag - they have a delayed response to change in the underlying values - regardless if the underlying values are price movement or some kind of indicator formula that we are trying to smooth using a moving average.
here's a simple technique that can help minimize the lag built into the moving average - you can use this technique while building your own indicator (say modifying RSI) or simply apply it to a price chart to generate some sort of signal.
the concept here is simple and it actually depends on the fact that there's lag in moving averages - however, it was also observed that this lag is less when we use a weighted moving average (WMA) vs a simple moving average (SMA). (for a quick intro / refresher on Moving Averages, there's an awesome write-up here on TradingView that you can easily find with a quick search)
so the idea is to take the delta between these 2 lines (which is mathematically equal to SMA - WMA) , and "mirror it" on the other side of the WMA to produce the new Zero-lag line (let's call it ZLMA. sounds easy, right?
now, expanding on this concept just one step further, while we're at it, why don't we take, say, 1.5 times that delta, or 2 times and mirror it - wouldn't that produce an even less lagging line that moves in lockstep with the price (or whatever data series)? -- yes it would, we added that in the sample code here, but be careful with that, if you increase that factor too much, the ZLMA starts behaving "wildly" and loses relevance to the underlying data. so keep it from 1 to 2.5 -- an ideal value would be around the 1.5 (and of course, for the mathematically gifted, as you expect, you make that factor -1.0, and you end up with a ZLMA that is exactly same as the SMA :) ..
if you don't use a ZLMA factor "f" -- then the simple equation is ZLMA = 2W - S, which you can simply add to any indicator to smoother it without introducing a lot of lag -- however, i still suggest you keep that smoothing to a small value between 3 and 6 -- to stay relevant to underlying data
hope you like this and find it useful. let me know -- i'd like to know if there's interest in these types of concepts and there's more to come.
pls stay safe,
RedK_Directional Index / K xDMIHere's a modern take on the famous DMI/ADX. i first wrote this on another platform few years ago, so i'm happy to be able to share it on TradingView
quick refresher: what does DMI/ADX tell us:
------------------------------------------------------
in simple terms, at the core of this indicator, there are 3 main calculations / lines: the Plus Directional Index ( +DI ) which represents how much the bulls are able to push the high of a bar compared to previous one, the Minus Directional Index ( -DI ), showing how much the bears are able to push the low of a bar from previous one, then the Average Directional index ( ADX ) line, which creates an oscillator of the +DI and -DI to represent the strength of a trend -- usually the lines will be colored accordingly (bulls = green, bears = red, and any different color for the ADX )
Similar to my version of the RSI , we take a classic concept, then use the computing and visualization "super powers" available to us today, to extend and improve on what those masters created in the past. I guess they sort of expected us to do exactly that :)
this "extended" version of DMI/ADX provides couple of highly needed features (in my opinion) -- let's explore:
trying as much as possible to avoid jargon - pls forgive me if i failed in some places.
-------------------------------------------------------------------------------------------------
1 - the big change: the ability to visualize the ADX in a way that makes some more sense.
- the original calculation restricted the ADX to oscillate below zero - i'm sure they had a good reason to build it that way in the past - but to me, it becomes super hard to interpret what the ADX line means, especially when a negative trend (the bears) take over. by removing that restriction and allowing the ADX to oscillate up or down (and we're free to do that, so the indicator shows *us* what *we need* to see), we end up with an improved representation of the trend and the trend strength.
- also the original calculation applies a moving average (default 14 bars) of a moving average (another 14 of the Directional Indexes, which represent the strength of bulls vs bears) to calculate the ADX - that makes the ADX very "removed" from the base price values - i change that, and just smooth the initial +Di / -Di then calculate the ADX from there. again, this shows me the outcome of the (relatively) immediate moves.
2 - i use weighted average WMA () in all my averaging calculations .. i believe this type of average is the best to express the importance of recent days / bars vs the ones further in the past, compared to other averaging techniques
3 - ability to make the DMI volume-weighted .. but contrary to my RSI , this is not set by default.
4 - couple of options to view the unrestricted ADX (as an area or as histogram/columns .. which i call Vertical Bars) for improved visualization
other stuff:
5 - a "step" option for the ADX .. you can set the step option to an increment of, say 5 or 10. this is in case you prefer to see the trend more in "quality" terms - so the equivalent of weak, medium, strong, v. strong...etc -- since in reality, a number like 47.7683 doesn't really mean anything specific
6 - optional "strong trend" adjustable level
Settings & usage suggestion:
-----------------------------------
i prefer to use the defaults (length = 7, smoothing = 3, ..etc) -- i believe these are more suitable to the much faster trading that we have now. you can review the comparison chart and see if this works for you, and adjust as you need.
from a "signal" standpoint, you can use the xDMI as you use the classic DMI/ADX, bulls (or bears) are in control when the corresponding DI line crosses the other going up, *AND* moving above the "strong trend" level that you can set as an extra filter (usually a value between 20 to 30), while ADX will show the quality/strength of the trend.
i suggest you also utilize this indicator with other trend / momentum confirmation methods, and additional analysis and not in isolation - as well as inspecting the prevailing / longer time frame to ensure you're acting in the direction of the broader move / trend.
the above chart includes a side-by-side comparison between our new xDMI with the classic DMI/ADX using the same settings - then we add at the bottom panel also the xDMI, but with my default (faster) settings and showing other visualization options that can be utilized - the Moving Averages on the top / price panel is just to help put the price movement into perspective in terms of trend and trend strength.
The code is open and commented - please feel free to use, share, comment & provide feedback. if you're a DMI fan, and you find this useful in your trading, i would be more than happy to hear about it
Good luck!
RedK Vol_Weighted RSI: Extending the power of the classic RSILet's take the classic Relative Strength Index (RSI) and give it couple of modern upgrades - the results are better visuals with improved signals and trade decision support:
Options and features:
- Dual period: look at the short term RSI vs a backdrop of a longer period RSI (expressing the longer-term "prevailing sentiment") - get clearer "re-entry" points in long bull or bear runs
- Longer period RSI has a "Step" option - since what we won't be really interested in the fractions, but more of the broad "strength" of the sentiment (weak, medium..) - default set to a step of 5. please experiment with what works best for you.
- Option to make the RSI volume-weighted. (On by default) - won't say much here, but possibly this is the biggest and most important added feature for those keen on the combined price - volume effect (and Wyckoff'ians)
- Smoothing option -- i would keep this set to 3 to avoid extra lag due to the smoothing
- scaled to +100 / -100 with zero as the signal line - that's how i like oscillators to work
- Adjustable optional overbought / oversold levels - can also be used to also mark strong up/down levels
- designed for the "visually oriented" -- like me :)
- code is open and commented
What Values to use:
many setting combinations possible. play around and find your sweet spot based on what/how you trade. for me, i usually prefer what i set as defaults in the study.
tip: if you set Length = 14, smoothing = 1, Sent. factor =1, Vol Weighted = No, you're back (almost) with a classic RSI - the only difference would be that i use Weighted Moving Average in my calculation of the RSI (i tend to believe WMA is the most naturally-suited for looking at "market price" data series)
Please feel free to use, share or give feedback.