# Momentum adjusted Moving Average by DGT

4158 visitas
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

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

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
Notas de prensa: 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"
Notas de prensa: backtest ability added for price crosses above or below MaMA line

optimization can be performed with available settable variables
Notas de prensa: Enable Non-Repaint Version option added
Notas de prensa: exit price calculation error fixed when stop loss condition meets

many many thanks for you highly valuable comments @sotiri 🙏
Notas de prensa: removed "Enable Non-repaint Vertion" option and made Alerts and BackTest Non-Repaint

## Comentarios

thank you so much for quick answer!
Responder
smartiesss
;-) Thank You @smartiesss
Responder
this is a wonderful piece of work - plus the code is written for 5-year old programmer (thank you).

have one thought/question for you: was wondering whether trading acceleration could be multiplied by some m "mass" to get some demand output Force(d) and some supply output Force(S)? Essentially the goal is to calculate Force Normal on any given candlestick to determine the probabilities underlying

1) short-term direction retroactively (not just up and down, but specific angle of ascent/descent as well), and,

2) the probability that a "throw over" results in binary success(bears win)/failure(bulls squeeze).

Would really find your thoughts interesting, so please let me know if you have any.

Thanks again, this script is awesome.
Responder
Hi dgtrd, thank you so much for this wonderful indicator! i am new here just want to know why the indicator only show Long opportunity but it didn't really show up short opportunity? i have tried with different graph like XAUBTC which is obvious downward trend but only long position is showing up...
Responder
smartiesss
hello @smartiesss, thanks for the interest to this study.

the aim of backtest was to be able to optimize the indicator based on instrument selected, time frame etc. and yes it only assumes long's for time being. once i free myself i will concentrate to include shots as well

regards
Responder
dgtrd
@dgtrd, sorry for more questions
is it mean that when the blue arrow start to change to orange arrow, it will be a short opportunity? can i do zig zag trade for every time there is signal?
Responder
smartiesss
@smartiesss, you are welcome

please be careful, in the ranging market as many other technical indicators this may generate many signals. i will recommend volatility based indicators for confirmations during raning markets. you may try the one i have published (please note i have not tested them toghether)

just try to analyze the bactest results, also when you hover over lables you will find some stats

Responder
Hey dgtrd, thanks for your script, in the backtest trade statistics when using the daily timeframe, the stop mechanism calculates a hard stop of the user selection by default -1%.
But if the symbol opens with a gap down while we are in the trade I think it should be calculating the opening price if it is >greater than the -1%.

If we don't follow the above approach in the daily timeframe the stats are not showing the real PnL of the trades.

Cheers and thanks again for your sourcecode
Responder
sotiri
Hello again, I just realised that the backtest statistics are not accurate at all.

In a daily candlestick if the price flactuates up and down the stop can be hit and then if the price retraces back the stop label disappears and it doesn't count in the final value calculation as a lost trade, like it never happened.
I was monitoring BTCUSD in the daily timefame and what I mentioned above happened with the entry and the SL just a few hours ago. Entry price: 19262.88 Stop Loss 19070.2512 the stop was hit it closed the trade with a loss. The price went above the entry level again and the SL that was hit previously has disappeared and it doesn't even been calculated in the final value...

I reckon the functionality of the trade statistics either should be fixed or scraped... It is quite unreliable.

Cheers
Responder
sotiri
Hello @sotiri, thank alot for the both comments, much appreciated your feedback and thanks to take your time and test this

it is a backtest, which you should consider for historical bar statistics only, where the bar are already confirmed

for real time bars yes it will repaint and you will observe the cases as you expalined with the example, for this study some have i skipped to add the option to enable non-repaint version i will add it the soonest possible and the problem your observed will be solved

by the time i do the update i will invite you to test with the exactly same backtest logic i have added to some of my other studies (of course entry/exit conditions are different)

please make sure "Enable Non-Repaint Version" is selected

finally i would like to add

backtest tool is not one of the sophisticated ones, its logic is simple and limited, roughly what it does
-measures the estimated success rate, starts with a predefined capital (default 1.000 units) and enters a long position when condition is met with all available capital (you may observe this when you hover over small labels that indicates entries and exits)
-display areas of trading zone and non-trading zones based on the indicators possible trading opportunity areas (only long entries and their corresponding exists are calculated and displayed)

the main idea is
-to add the ability to optimize the study for better outcomes, such as to find out the best timeframe that fits with the indicator, adjust variables for best outcome (just as a reminder, historical performance does not guarantee future outcomes to be identical) and even identify whether the study is suitable for the financial instrument selected
-to add the ability to visualize strengths and weaknesses of the study, knowing the weaknesses could be powerful to turn them to an advantage
-emphasis importance of stop loss
-emphasis the fact not to be traded upon single technical indicator
-measure/observe the effects for different techniques available in the study, experience usage for different sources