TradingView

# Aligned Moving Average Index

538 lượt xem
Moving averages are considered as aligned when either all faster moving averages are placed above their next slower moving averages or all faster moving averages are placed below their next slower moving averages. In this script, we are considering moving averages of 5, 10, 20, 30, 50, 100 and 200. User can select different moving average types from input : sma , ema , hma , rma, vwma , wma .

Moving average is considered as positively aligned when close > ma5 > ma10 > ma20 > ma30 > ma50 > ma100 > ma200
Moving average is considered as negatively aligned when close < ma5 < ma10 < ma20 < ma30 < ma50 < ma100 < ma200

Whenever there is positively aligned moving average, alignment value is considered as +1 and whenever there is negatively aligned moving average, alignment value is considered as -1. Aligned moving average index is sum of n periods of alignment value.

We can optionally apply another moving average on this index to see the overall direction.

Phát hành các Ghi chú: Added option include partial alignment.

## Bình luận

Hi @HeWhoMustNotBeNamed,

I am new to TradingView so I decided to check out some public scripts to get started. Thanks for sharing this script!

I read through your script and was wondering if I have spotted an oversight or an intentional skewing of your partial alignment scoring. It seems to me that there are 6 upward scores that can result in partial scoring (1,2,3,4,5,6), leaving 0 and 7 for full alignment.

With your formula on line 49, an upward score of 1 or 2 can result in -0.5, while only 6 can result in 0.5; similarly only 3 can result in -0.25, while 4 and 5 can result in 0.25. Was this unbalanced scale intentional? Again, I am very new to this, so I am sure its possible that I am just not understanding the intended behaviour of this indicator.
Phản hồi
BitsOfCash
@BitsOfCash,

I don’t think so. I have used < 2. Hence only score 1 can result in -0.5

7 => +1
6 => +0.5

4,5 => 0.25
3,2 => -0.25

1 => -0.5
0 => -1

Do you think the code isn’t reflecting this?
Phản hồi
HeWhoMustNotBeNamed
@HeWhoMustNotBeNamed, I have looked at it again and you are correct. I must have overlooked the "<" that day. Not sure why. Sorry for the false alarm!
Phản hồi