OPEN-SOURCE SCRIPT

Momentum adjusted Moving Average by DGT

Diupdate
A brand new Moving Average, calculated using Momentum, Acceleration and Probability (Psychological Effect).

Momentum adjusted Moving Average(MaMA) is an indicator that measures Price Action by taking into consideration not only Price movements but also its Momentum, Acceleration and Probability. MaMA, provides faster responses comparing to the regular Moving Average

Here is the math of the MaMA idea

Momentum measures change in price over a specified time period

momentum = source – source(length)
where,
source, indicates current bar’s price value
source(length), indicates historical price value of length bars earlier

Lets play with this formula and rewrite it by moving source(length) to other side of the equation

source = source(length) + momentum

to avoid confusion let’s call the source that we aim to predict as adjustedSource

adjustedSource = source(length) + momentum


looks nice the next value of source simply can be calculated by summing of historical value of the source value and value of the momentum. I wish it was so easy, the formula holds true only when the momentum is conserved/constant/steady but momentum move up or down with the price fluctuations (accelerating or decelerating)

Let’s add acceleration effects on our formula, where acceleration is change in momentum for a given length. Then the formula will become as (skipped proof part of acceleration effects, you may google for further details)

adjustedSource = source(length) + momentum + 1/2 * acceleration

here again the formula holds true when the acceleration is constant and once again it is not the case for trading, acceleration also changes with the price fluctuations

Then, how we can benefit from all of this, it has value yet requires additional approaches for better outcome

Let’s simulate behaviour with some predictive approach such as using probability (also known as psychological effect), where probability is a measure for calculating the chances or the possibilities of the occurrence of a random event. As stated earlier above momentum and acceleration are changing with the price fluctuations, by using the probability approach we can add a predictive skill to determine the likelihood of momentum and acceleration changes (remember it is a predictive approach). With this approach, our equations can be expresses as follows

adjustedSource = source(length) + momentum * probability
adjustedSource = source(length) + ( momentum + 1/2 * acceleration ) * probability
, with acceleration effect

Finally, we plot MaMA with the new predicted source adjustedSource, applying acceleration effect is made settable by the used from the dialog box, default value is true.

What to look for:
• Trend Identification
• Support and Resistance
• Price Crossovers

Recommended settings are applied as default settings, if you wish to change the length of the MaMA then you should also adjust length of Momentum (and/or Probability). For example for faster moving average such as 21 period it would be suggested to set momentum length to 13
Alternative usage, set moving average length to 1 and keep rest lengths with default values, it will produce a predictive price line based on momentum and probability. Experience acceleration factor by enabling and disabling it

Conclusion

MaMA provide an added level of confidence to a trading strategy and yet it is important to always be aware that it implements a predictive approach in a chaotic market use with caution just like with any indicator

Trading success is all about following your trading strategy and the indicators should fit within your trading strategy, and not to be traded upon solely

Disclaimer: The script is for informational and educational purposes only. Use of the script does not constitutes professional and/or financial advice. You alone the sole responsibility of evaluating the script output and risks associated with the use of the script. In exchange for using the script, you agree not to hold dgtrd TradingView user liable for any possible claim for damages arising from any decision you make based on use of the script
Catatan Rilis
This update introduces an experimental application of feedback concept common in Electronic Engineering, attempting to present additional value/insight to the Indicator

Feedback concept in Electronic Engineering
Negative feedback (or balancing feedback) is applied to reduce the fluctuations, whether caused by changes in the source or by other disturbances. The applied negative feedback can improve performance, gain stability, linearity and reduce sensitivity to parameter variations due to environment.
Whereas positive feedback tends to lead to instability via exponential growth, oscillation or chaotic behaviour

mainly all testing is performed with crypto market, others sometimes requires to reduce feedback multiplier

Detailed explanation and calculation approach can be found in the description of "Rate of Return (RoR) by DGT"
Catatan Rilis
backtest ability added for price crosses above or below MaMA line

optimization can be performed with available settable variables

Catatan Rilis
alert condition added
Catatan Rilis
Enable Non-Repaint Version option added
Catatan Rilis
exit price calculation error fixed when stop loss condition meets

many many thanks for you highly valuable comments sotiri 🙏
Catatan Rilis
removed "Enable Non-repaint Vertion" option and made Alerts and BackTest Non-Repaint
Catatan Rilis
Enhancements in BackTest Framework

1-) Historical Data Evaluation
in the real-time processing when the condition is satisfied to avoid repainting the signals are presented on the next bar, this feature was already available with this study
change implemented with this update is to made historical data evaluation behavior same as real-time behavior and all plottings, statistical panel calculations are performed based on the next bar

Hence;
- traders will observe the same behavior both in real-time and in historical bars (even when the study is reloaded)
- trade statistics will display whatever the user traded on the real-time bars with the signals generated
- since the signals are generated on the next bar, “Entry/Exit Price Assumption” input necessity is no longer required, trades with the backtest framework will be assumed as open price on the next candle

2-) Early Warning : Alert + Label
As a rule as explained above, signals are triggered on the next bar in case the condition is still valid and the logic of the study is already aware of the likelihood of an signal occurrence on the next bar but the trader who is analyzing the chart is not (according to this study’s logic of course). So to increase the awareness, with this update ;
 - a label with a warning sign is going to be plotted which of course is subject to repaint but will warn the trader to keep eyes closer on the instrument and proceed trading immediately on the next bar if the signal is confirmed and presented on the chart.
 - for the same warning also an alert is defined (using new alert() function call), so the trader will be able to be notified with the probable not yet confirmed trade opportunity in advance, even if the trader is not monitoring the instrument.
Having said that, I would like to remind : Trading success is all about following your trading strategy and the indicators should fit within your trading strategy, and not to be traded upon solely.

3-) Improved Conditions
 Avoid Sudden Price Changes : Since the long/short conditions are triggered on next bar there might be cases where a sudden change in price direction and hence signal change may occur especially in sideway market conditions with low volatility, this option is to avoid such cases

 Candle Direction as Confirmation : confirms signal if the candle formation is in favor of the trade

Please note : selecting the above options will cause the signals to be executed on the second bar so to have the study non-repaint. For test purposes only you may enable "❗❗❗ Simulate Trade on Next Bar : Only For Test Purpose (REPAINTS)" option to simulate the trade on the next bar.

Important note : stop loss condition will be executed when price fall below the calculated value and trade will be closed with the close price on bar close (not yet able to get the price value at the moment of the cross). Stop loss condition is subject to repainting and to avoid any further loss an alert can be triggered at the moment the first cross is observed. Since stop loss is subject to repaint and in case it happens the statistical panel calculation will not be able to calculate till the bar is closed. You may disable application of stop loss from user dialog box to avoid any inconsistency that may appear on statistical panel and observe results of the trades executed without stop loss.

Other updates in Study
• Enhanced Alerts setup to have two alerts settings for bull condition and two for bear condition, one with the repaint version (early warning) and one non-repaint version (on the next bar if still condition holds true).
accelerationbacktestDGTfeedbackMomentum Indicator (MOM)Moving AveragesnegativeoptimizationpositivepredictionprobabilityTrend Analysis

Skrip open-source

Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menerbitkannya sebagai sumber terbuka, sehingga para trader dapat memahami dan memverifikasinya. Hormat untuk penulisnya! Anda dapat menggunakannya secara gratis, namun penggunaan kembali kode ini dalam publikasi diatur oleh Tata Tertib. Anda dapat memfavoritkannya untuk digunakan pada chart

Inggin menggunakan skrip ini pada chart?

Pernyataan Penyangkalan