OPEN-SOURCE SCRIPT

FULL MA Optimization Script

Zaktualizowano
Hello!
This script measures the performance of 10 moving averages and compares them!
Crossover and crossunders are both tested.
The tested moving averages include: TEMA, DEMA, EMA, SMA, ALMA, HMA, T3 Average, WMA, VWMA, LSMA.
You can select the length of the moving averages and the data source (I.E, close, open, ohlc4, etc.) and the script will calculate your selections!
For instance, if you select a length of 32 and a source of ohlc4 for crossovers, the script will assign the ten moving averages that length and data source and compare the performance for ohlc4 crossovers of the 32TEMA, 32DEMA, 32SMA, 32WMA, etc. If you select crossunder, the script will calculate the performance of ohlc4 crossunders of the same moving average lengths.

Moving average performances are listed in descending order (best to worst) and are categorized by tier: Upper-Tier, Mid-Tier, Lower-Tier. The Upper-Tier displays the three best performing averages relative to the MA length and data source, for the asset on the relevant chart timeframe. The Lower-Tier displays the three worst performing averages. The Mid-Tier displays the moving averages whose performance did not achieve a top three spot or a bottom three spot.


Also calculated is the moving average which achieved the highest cumulative gain/loss and the lowest cumulative gain/loss. Any asset and timeframe can be tested; the script recalculates relative to the chart timeframe. I added a "Benchmark Moving Average" free parameter and a "Custom Moving Average" free parameter. The two operate identically; you can set the length and data source of both for quick and simple comparison between differing average lengths and sources.

If "Crossover" is selected, the "(X Candles)" displayed on the tables reflects the average number of sessions the data source remains above a moving average following a crossover. If "Crossunder" is selected, the "(X Candles)" reflects the average number of sessions the data source remains below the moving average following a crossunder.

If "Crossover" is selected, the listed "X%" reflects the average percentage gain/loss following a source crossover of a moving average up until the source crosses back under the moving average. If "Crossunder" is selected, the listed "X%" reflects the average percentage gain/loss following a source crossunder of a moving average up until the source crosses back over the moving average.

If "Crossover" is selected, the listed "X Crosses" reflects the number of instances in which the source crossed over a moving average. If "Crossunder" is selected, the listed "X Crosses" reflects the number of instances in which the source crossed under a moving average.

Additional tooltips and instructions are included should you access the user input menu.

The moving averages can be plotted as a gradient (highest priced MA to lowest priced MA) alongside the best performing moving average. The moving averages can be plotted in full color, light color alongside the best performing average, or not plotted.

This script improves upon a similar script I have released: tradingview.com/v/lqKiGbsP/.
I decided not to update the previous script. The previous script calculates crossovers only and, due to being less code intensive, calculates much quicker. If a user is concerned only with price crossovers, not crossunders, the original script is a better option! It's faster, making it the preferable choice!

This script "FULL MA Optimization" calculates crossovers/crossunders and incorporates additional plot styles. I ran into trouble a few times where the script was too large to run on TV. This script is not "slow", I suppose; however, calculations and parameter modifications take a bit longer than the original script!

Informacje o Wersji
Fixed early data NaN values
Informacje o Wersji
Identifier name clean up!
Informacje o Wersji
More identifier name clean up
Informacje o Wersji
Hello!

I was recently questioned why I did not mention the potentially disastrous consequences of optimization scripts.

So, I am posting a quick update to outline the advantages and disadvantages of indicator/strategy optimization!

An optimization script is best implemented to discover what won't work, not what will work. The best performing "optimized" parameters are not a guaranteed profitable investment system. While we may see an exceptionally positive performance for a set of parameters, it's impossible to know how much of that performance is the beneficiary of market noise in the absence of additional testing. Most market moves are noise - irreplicable sequences that offer no predictive utility - and most "good" backtests overwhelmingly benefit from these irreplicable sequences. An investor unfamiliar with this concept may be lead to believe they have found a valid correlation between an indicator sequence and subsequent price movement, despite the correlation being illusory.

Consequently, it should be assumed that the best performing parameters strongly benefitted from market noise and will not work in a live market - until further rigorous statistical tests are performed on an investment system built around the best performing parameters. This includes out-of-sample, in-sample, and forward testing in addition to testing negatively correlated, positively correlated and zero-correlation assets; testing additional assets should be treated as prerequisite to live implementation.

Of course, all trading strategies, even one's that methodically exploit a valid correlation/replicable sequence, will benefit from market noise - it's impossible to avoid. However, a "legit" trading strategy has a chance to work on future price data, while an overoptimized strategy will fail miserably on new price data!

This script tests 102 parameter combinations concurrently and returns the performances in descending order. An overoptimized strategy is virtually guaranteed to have a better backtest performance than a valid strategy. The overoptimized strategy will fail in a live market while the valid strategy has a chance of working. So, should you notice the best performing SuperTrend parameters, be sure to build a comprehensive trading system around the parameters and perform additional tests. This is the only way to know if the optimized parameters will truly work in a live market!

Unfortunately, they often will not!


Informacje o Wersji
Memory calculation compliant
Moving Averages

Skrypt open-source

W prawdziwym duchu TradingView autor tego skryptu opublikował go jako open source, aby inwestorzy mogli go zrozumieć i zweryfikować. Pozdrowienia dla autora! Możesz go używać bezpłatnie, ale ponowne użycie tego kodu w publikacji podlega Zasadom Regulaminu. Możesz go oznaczyć jako ulubione, aby użyć go na wykresie.

Chcesz użyć tego skryptu na wykresie?


•Access to Next-Gen Optimization Tools: kiosefftrading.com

•Discord Server: discord.gg/3cKVU28Z9Z
Również na:

Wyłączenie odpowiedzialności