TradingView
loxx
5 ספט׳ 2022 16:52

Variety N-Tuple Moving Averages [Loxx] 

U.S. Dollar/Canadian DollarFXCM

תיאור

Variety N-Tuple Moving Averages [Loxx] is a moving average indicator that allows you to create 1- 30 tuple moving average types; i.e., Double-MA, Triple-MA, Quadruple-MA, Quintuple-MA, ... N-tuple-MA. This version contains 5 different moving average types including T3. A list of tuples can be found here if you'd like to name the order of the moving average by depth: Tuples extrapolated

You'll notice that this is a lot of code and could normally be packed into a single loop in order to extract the N-tuple MA, however due to Pine Script limitations and processing paradigm this is not possible ... yet.

If you choose the EMA option and select a depth of 2, this is the classic DEMA; EMA with a depth of 3 is the classic TEMA, and so on and so forth this is to help you understand how this indicator works. This version of NTMA is restricted to a maximum depth of 30 or less. Normally this indicator would include 50 depths but I've cut this down to 30 to reduce indicator load time. In the future, I'll create an updated NTMA that allows for more depth levels.

This is considered one of the top ten indicators in forex. You can read more about it here: https://forex-station.com/viewtopic.php?f=579496&t=8473244

How this works

Step 1: Run factorial calculation on the depth value,

Step 2: Calculate weights of nested moving averages

factorial(nemadepth) / (factorial(nemadepth - k) * factorial(k); where nemadepth is the depth and k is the weight position

Examples of coefficient outputs:

6 Depth: 6 15 20 15 6
7 Depth: 7 21 35 35 21 7
8 Depth: 8 28 56 70 56 28 8
9 Depth: 9 36 34 84 126 126 84 36 9
10 Depth: 10 45 120 210 252 210 120 45 10
11 Depth: 11 55 165 330 462 462 330 165 55 11
12 Depth: 12 66 220 495 792 924 792 495 220 66 12
13 Depth: 13 78 286 715 1287 1716 1716 1287 715 286 78 13

Step 3: Apply coefficient to each moving average

For QEMA, which is 5 depth EMA, the caculation is as follows

ema1 = ta.ema(src, length)
ema2 = ta.ema(ema1, length)
ema3 = ta.ema(ema2, length)
ema4 = ta.ema(ema3, length)
ema5 = ta.ema(ema4, length)

qema = 5 * ema1 - 10 * ema2 + 10 * ema3 - 5 * ema4 + ema5

Included:
  • Alerts
  • Loxx's Expanded Source Types
  • Bar coloring

הערות שחרור

Corrected display error and updated titles.
תגובות
siq-trader
> however due to Pine Script limitations and processing paradigm this is not possible ... yet.

Could you tell more about pine script limitations you met?
Ether2020
Thank you for the script. Unfortunately, I see a lot of errors when adding this script to a chart:

line 122: The function 'ta.ema' should be called on each calculation for consistency. It is recommended to extract the call from this scope
line 124: The function 'ta.wma' should be called on each calculation for consistency. It is recommended to extract the call from this scope
line 126: The function 'ta.sma' should be called on each calculation for consistency. It is recommended to extract the call from this scope
line 128: The function 'ta.rma' should be called on each calculation for consistency. It is recommended to extract the call from this scope
line 130: The function '#f1' should be called on each calculation for consistency. It is recommended to extract the call from this scope

There are more, but the post will get too long. If you add it, you can see it yourself.
loxx
@Ether2020, yep, doesnt matter, ignore the errors
Ether2020
@loxx, Thanks!
עוד