OPEN-SOURCE SCRIPT

MA Strength Indicator Enhanced

102
The "MA Strength" is an indicator that measures market trend strength or (in the case of forex pairs) the relative strength of individual currencies based on up to five different moving averages (MA). It offers multiple calculation methods, such as simple summation, normalized value, or measuring ATR/percentage distance from the price. The results are summarized in a clear table, and it provides customizable alerts for trend changes or shifts in currency strength. The high level of configurability (e.g., MA weighting, "all MA alignment" requirement) allows for fine-tuning the strategy.

istantanea
istantanea



💬 Interpreting the Table (Top Rows)

The top row of the table shows the final output of the indicator. This changes according to the set "Table Mode".

Trend Mode: The top row shows the final, aggregated trend status (e.g., "BULLISH", "NEUTRAL") and the corresponding "Trend Value". This is the value the indicator compares to its thresholds.
Forex Mode: (Only on 6-character pairs): The top two rows show the strength of the Base currency and the Quote currency separately.
Calculation of the top rows:

The indicator calculates the individual score of all active MAs (according to the chosen method).

Trend Value: This is the final value calculated from the scores.
If "Enable Averaging" is ON, this will be the average of the scores (e.g., MA1 score is 5.0, MA2 score is 7.0 -> Trend Value is 6.0).
If averaging is OFF, this will be the sum of the scores (e.g., 5.0 + 7.0 = 12.0).


Forex Calculation: "Forex Mode" uses this "Trend Value". If the Trend Value is +6.0 (on an EURUSD pair):
The Base currency (EUR) value will be +6.0.
The Quote currency (USD) value will be -6.0.
The indicator compares these values to the thresholds to determine the "STRONG" status for EUR and "WEAK" status for USD.


📊 Calculation Methods

The indicator can calculate trend strength using 5 methods. The final "Trend Value" is derived from the results of these calculations.

Sum:

Description: Simply adds up the individual scores of all enabled moving averages (MA).
Formula: If the price is above an MA, it gets the "Score Above" value (e.g., +2.0); if below, it gets the "Score Below" value (e.g., -2.0).
Example: Result = (MA1 score) + (MA2 score) + ...

Normalized:

Description: Takes the sum obtained by the "Sum" method and converts it to a scale between -100% (maximally bearish) and +100% (maximally bullish). It takes into account the maximum possible positive and negative scores.
Formula: Result = (Total Score / Max Possible Score) * 100

Percentage Distance:

Description: This method also considers distance. The further the price is from the MA in percentage terms, the higher the score.
Formula: MA Score = (|Close Price - MA| / MA * 100) * Weight (The "Weight" is the "Score Above/Below" value set in settings).

ATR Distance:

Description: Similar to percentage distance, but normalizes the distance using volatility via ATR (Average True Range).
Formula: MA Score = (|Close Price - MA| / ATR) * Weight

Candle Count:

Description: Counts how many consecutive candles have been above or below the MA. It multiplies this number by the set weight.
Formula: MA Score = (Number of consecutive candles) * Weight



⚙️ Settings Options

Moving Averages (MA 1-5)
For each moving average, you can set:

Enable MA: Turn the specific MA on or off.
Type: The type of moving average (SMA, EMA, WMA, etc.).
Period: The period of the MA (e.g., 50, 200).
Score Above / Below: The most important setting. This defines the "weight" of the MA in the calculation. In "Sum" mode, this is a fixed score; in distance-based modes, this is a multiplier (weight). It is advisable to write a positive number for "Score Above" and a negative number for "Score Below".

Calculation Settings

Enable Averaging: If this is on, the indicator shows the average of the active MA scores, not the total score.
Exception: This function is not available in "Normalized" mode.
Require All MA Alignment: This is a strict filter. If enabled, the indicator only gives a "BULLISH" (or "STRONG") signal if the price is above all enabled moving averages. Similarly, a "BEARISH" signal only occurs if the price is below all moving averages. If the price is on the opposite side of even just one MA (e.g., above 4, below 1), the status becomes "NEUTRAL", regardless of the scores.

Strength / Trend Thresholds

Enable Extra Levels: If active, statuses are expanded: "EXT. BULLISH" / "EXT. BEARISH" (Trend mode) or "EXT. STRONG" / "EXT. WEAK" (Forex mode). This indicates stronger, overbought/oversold conditions.
Threshold setting: The thresholds (e.g., "Strong Above - ATR") determine when the calculated value counts as a "STRONG" or "WEAK" status.


🔢 Setting Thresholds via Calculation

If "Enable Averaging" is OFF, the "Trend Value" shown in the table will be the sum of the individual MA scores. Therefore, we must define the threshold by adding up the minimum expected performance from each moving average. This allows us to set different expectations for short, medium, and long-term averages.

Step 1: Determine MA weights
In our example, we use 3 active MAs with the following weights (Score Above values):

MA1 (Short): Weight = +2
MA2 (Medium): Weight = +3
MA3 (Long): Weight = +4

Step 2: Determine the minimum expected distance
Define a minimum distance expected from each MA to trigger a "Strong" signal.

Step 3: Calculate target scores and the final threshold
Note: If "Enable Averaging" is ON, the resulting value (sum of target scores) must be
averaged to get the final threshold.

Example 1: ATR Distance

-Goal: I want a "Strong" signal if the price is...
...at least 1.0 ATR above MA1 (Short),
...at least 1.5 ATR above MA2 (Medium),
...and at least 2.0 ATR above MA3 (Long).
-Calculation (Expected Distance * Weight):
MA1 Target Score: 1.0 * 2 = 2.0
MA2 Target Score: 1.5 * 3 = 4.5
MA3 Target Score: 2.0 * 4 = 8.0
-Final Threshold (Sum of Target Scores): 2.0 + 4.5 + 8.0 = 14.5
-Setting: Set "Strong Above - ATR" threshold to 14.5.
If "Enable Averaging" is ON, the obtained value must be averaged, and the result will be the
threshold: 4.8 (14.5 / 3 = 4.83).

Example 2: Percentage Distance

-Goal: I want a "Strong" signal if the price is...
...at least 0.5% above MA1,
...at least 1.0% above MA2,
...and at least 1.5% above MA3.
-Calculation (Expected Distance * Weight):
MA1 Target Score: 0.5 * 2.0 = 1.0
MA2 Target Score: 1.0 * 3.0 = 3.0
MA3 Target Score: 1.5 * 4.0 = 6.0
-Final Threshold (Sum): 1.0 + 3.0 + 6.0 = 10.0
-Setting: Set "Strong Above - Percentage" threshold to 10.0.
If "Enable Averaging" is ON, the obtained value must be averaged, and the result will be the
threshold.

Example 3: Candle Count

-Goal: I want a "Strong" signal if...
...at least 3 consecutive candles are above MA1,
...at least 5 consecutive candles are above MA2,
...and at least 10 consecutive candles are above MA3.
-Calculation (Expected Candle Count * Weight):
MA1 Target Score: 3 * 2.0 = 6.0
MA2 Target Score: 5 * 3.0 = 15.0
MA3 Target Score: 10 * 4.0 = 40.0
-Final Threshold (Sum): 6.0 + 15.0 + 40.0 = 61.0
-Setting: Set "Strong Above - Candle" threshold to 61.0.
If "Enable Averaging" is ON, the obtained value must be averaged, and the result will be the
threshold.

Example 4: Sum

In this mode, distance does not matter, only whether the price is above or below the MA.

-Goal: "Strong" signal if the price is above the long-term averages, but can be below the short-term (MA1).
MA1 (Short): Can be below (Weight: -2.0)
MA2 (Medium): Must be above (Weight: +3.0)
MA3 (Long): Must be above (Weight: +4.0)
-Calculation: -2.0 + 3.0 + 4.0 = 5.0
-Setting: Set "Strong Above - Sum" threshold to 5.0.
If it must be above all three moving averages, the threshold would be 2.0 + 3.0 + 4.0 = 9.0.
If "Enable Averaging" is ON, the obtained value must be averaged, and the result will be the
threshold.

Example 5: Normalized

The basic logic is similar to the "Sum" method.

-Goal: "Strong" signal if price is above MA2 and MA3, but potentially below MA1.
-Calculation: Target Sum: 5.0. Max Possible Score (above all): 9.0.
-Threshold: (5.0 / 9.0) * 100 = 55.5
In this calculation method, averaging cannot be set.


The Usage of the "ATR %" Row

The "ATR %" row shows the percentage movement of an average candle.
How to use this with "Percentage Distance" mode:
This number gives a baseline. It helps decide if the "Percentage Distance" threshold is realistic.

Example: You see the "ATR %" value is hovering around 1.2%. This means a "normal" candle moves about 1.2%.
If you set the Percentage threshold to 0.5%, it is too low. The indicator will constantly give a "Strong" signal because even average movement (noise) exceeds the threshold.
Correct Usage: If "normal" movement is 1.2%, then a "strong" movement (trend) needs to be significantly larger. For example, set the threshold to double the ATR %: 2.4 (2 * 1.2). Thus, you only get a "Strong" signal if the movement is twice the average volatility.


Supplementary Information

Rounding Differences:

The numbers displayed in the table and the precision of calculations in the background differ.

Table Display: The indicator rounds numbers to two decimal places in the table. So, if the value is 0.996, the table shows 1.00 (rounded up).
Internal Calculation: The background calculation uses much higher precision. When determining status (STRONG vs NEUTRAL), the program compares the precise, unrounded value to the threshold.
Result: Due to rounding, it may happen that if the threshold is 1.00 and the table shows 1.00, the status flickers between Strong and Neutral. If this is bothersome, it is advisable to set a slightly lower threshold (e.g., 0.98).


🔔 Alert Settings

The indicator can send alerts when the status changes.

Alert Method:
Trend: Alerts when the main trend status changes (e.g., from "NEUTRAL" to "BULLISH"). You can specify which direction to alert for (e.g., only "BULLISH").
Forex: Works only on 6-character forex pairs. You can set separate alerts for the Base or Quote currency.
Forex Strength Level: You can specify at which status level to alert (e.g., "WEAK" or "EXT. STRONG").


📈 Trading Tips

Trend Confirmation: Use the "BULLISH" / "BEARISH" status to confirm your existing strategy (e.g., breakouts, bounces off support).
Forex Pairing: In Forex mode, look for pairs where the Base currency is "STRONG" and the Quote currency is "WEAK" (or "EXT. STRONG" / "EXT. WEAK") for a long position.
Short Position: Reverse the above (Base: WEAK, Quote: STRONG).

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.