Dataanalysis
The Cores of Price Analysis: Trend Following vs. Mean ReversionIn the world of financial markets, predicting future price movements is akin to unlocking a treasure chest. Two of the most prominent methodologies used by traders and analysts to decipher market movements are Trend Following and Mean Reversion. Each approach offers a unique perspective on how markets behave and provides strategies for capitalizing on this behavior. In this article, we'll dive into the core concepts of these methodologies, explore how they can be implemented, and touch on basic processing techniques like smoothing and normalization, which enhance their effectiveness.
Trend Following: Surfing the Market Waves
Trend Following is based on the premise that markets move in trends over time, and these trends can be identified and followed to generate profits. The essence of trend following is to "buy high and sell higher" in a bull market, and "sell low and buy back lower" in a bear market. This method relies on the assumption that prices that have been moving in a particular direction will continue to move in that direction until the trend reverses.
How to Implement Trend Following
1. Identifying the Trend: The first step is to identify the market trend. This can be done using technical indicators such as moving averages, MACD (Moving Average Convergence Divergence), or ADX (Average Directional Index). For example, a simple strategy might involve buying when the price is above its 200-day moving average and selling when it's below.
2. Entry and Exit Points: Once a trend is identified, the next step is to determine entry and exit points. This could involve using breakout strategies, where trades are entered when the price breaks out of a consolidation pattern, or using momentum indicators to confirm trend strength before entry.
3. Risk Management: Implementing stop-loss orders and adjusting position sizes based on the volatility of the asset are crucial to managing risk in trend-following strategies.
Basic Processing Techniques
- Smoothing: To reduce market noise and make the trend more discernible, smoothing techniques such as moving averages or exponential smoothing can be applied to price data.
- Normalization: This involves scaling price data to a specific range, often to compare the relative performance of different assets or to make the data more compatible with certain technical indicators.
Mean Reversion: Betting on the Elastic Band
Contrary to trend following, Mean Reversion is based on the idea that prices tend to revert to their mean (average) over time. This methodology operates on the principle that extreme movements in price – either up or down – are likely to revert to the mean, offering profit opportunities.
How to Implement Mean Reversion
1. Identifying the Mean: The first step is to determine the mean to which the price is expected to revert. This could be a historical average price, a moving average, or another indicator that serves as a central tendency measure.
2. Identifying Extremes: The next step is to identify when prices have moved significantly away from the mean. This can be done using indicators like Bollinger Bands, RSI (Relative Strength Index), or standard deviation measures.
3. Entry and Exit Points: Trades are typically entered when prices are considered to be at an extreme deviation from the mean, betting on the reversal towards the mean. Exit points are set when prices revert to or near the mean.
Basic Processing Techniques
- Smoothing: Similar to trend following, smoothing techniques help in clarifying the mean price level by reducing the impact of short-term fluctuations.
- Normalization: Especially useful in mean reversion to standardize the deviation of price from the mean, making it easier to identify extremes across different assets or time frames.
Conclusion
Trend Following and Mean Reversion are two fundamental methodologies in financial market analysis, each with its unique perspective on market movements. By employing these strategies thoughtfully, along with processing techniques like smoothing and normalization, traders and analysts can enhance their understanding of market dynamics and improve their decision-making process. As with any investment strategy, the key to success lies in disciplined implementation, thorough backtesting, and effective risk management.
Development Log for Neural Network PrototypeThe idea, at the core:
Port a limited RNN/LSTM Neural Network model from Python with a reduced training set and dimension size for layers to demonstrate that a fully functional (even if limited) Neural Net can work in Pine.
Limited model + having the python code on hand = Able to test and verify components in Pine at every step, in theory
The model/script I'm attempting to implement a limited subset of is detailed here:
iamtrask.github.io
A dataset in binary is required, but binary does not exist in pinescript, thus:
To do this, decimal to binary and binary to decimal functions are required. This didn't exist previously - I've written a script to accomplish just that:
Originally, this was going to have a input_dim of 2, hidden_dim of 16, but I've changed the hidden_dim to 8 (binary dimensions from 8 to 5) to reduce the dataset range to max 32 while I figure out to implement working pseudo-arrays and state updates. I've looked at RicardoSantos's scripts for Markov and Pseudoarrays, and will be using them as a reference going forward.
I've verified the output of the Sigmoid function and 1st derivative of the Sigmoid function in Python for values of (-1,0,0.5,1 ). I've yet to publish the Sigmoid script pending approval from TV moderators about including python code that is commented out at the bottom to verify the results of that script.
What I'm trying to do here with training dataset generation was unsuccessful, for multiple reasons:
Lack of formal array constructs in pine
Psuedorandom Number generator limitations
Manual state weighting and updating as per RicardoSantos's Function Markov Process is required:
What's being plotted for are the first three layers, but without the full range of the input_dimensions, hidden_dimensions:
syn_0 (blue)
syn_1 (green)
syn_h (red)
While there's more than a few technical hurdles to overcome (i.e. potential pine issues from max variables to runtime/compile limits, no real arrays, functions to do state updates RichardoSantos Markov Function style, etc), I'm fairly confident a limited working model should be possible to create in Pine.
Backtesting Became Cool Again!Hello traders
Hope you're all doing fantastic
I learned a few weeks ago that TradingView released a CSV Export feature. Basically, you can export any indicator outputs/plots and get the data in your favorite Excel/Google Sheet/Open office, etc.
Using that software is relatively easy and learning how to construct pivot tables/charts will expand your analytics beyond the realm of what you thought was even possible... #way #too bold #statement
In that video:
I exported the data provided by Backtest Premium Suite in Google Sheet
In Google Sheet, I built a pivot table and a few pivot charts (requires a few clicks only)
Allows me to get insightful analytics and understand better where I can improve (how much opportunity do I capture? for which risk? are my winners increasing faster than my losers are decreasing?...)
Thank you TradingView for enabling this feature.
All the BEST
Dave