189
by JohnL33
A! Universal_Strength_Signal
Overall Summary
This MQL4 script is a Universal Currency Strength and Signal Indicator. Its primary purpose is to measure the overall strength of any currency you choose (the BaseCurrency) and then generate a simple BUY, SELL, or WAIT signal for any other financial instrument (the SignalSymbol).
It is designed to be a minimalist but powerful tool for traders who rely on correlation analysis. For example, you can use it to:
Measure AUD strength to get signals for XAUUSD (Gold).
Measure CAD strength to get signals for USOIL (Oil).
Measure EUR strength to get signals for EURUSD.
Measure JPY (a safe-haven) strength to get signals for a stock index like US30 during "risk-off" market conditions.
The on-screen display is clean and simple, showing only the calculated strength percentage and the resulting trade signal.
Core Functionality Explained
The indicator's logic can be broken down into two main steps:
1. Strength Calculation (The "Engine")
This is the most complex and important part of the indicator, handled by the calculateBaseCurrencyStrength() function.
Creates a Currency Basket: Instead of looking at just one pair, the indicator intelligently builds a "basket" of pairs to measure the BaseCurrency's strength. It does this by trying to pair your chosen BaseCurrency (e.g., "AUD") with all other major currencies (USD, EUR, GBP, JPY, etc.).
Finds Valid Pairs: It checks your broker's server to see which pairs actually exist. For example, it will find AUDUSD, EURAUD, GBPAUD, etc. This makes it robust and able to adapt to different brokers.
Measures Position-in-Range: For each valid pair in the basket, it calculates a strength score using the calculateAssetStrength() function. This formula measures where the current price is relative to the highest high and lowest low over the last Hours. A price near the high gets a high percentage; a price near the low gets a low percentage.
Isolates the Base Currency: This is the crucial step.
If the BaseCurrency is first in the pair (e.g., AUD in AUDUSD), the indicator uses the strength percentage directly.
If the BaseCurrency is second in the pair (e.g., AUD in EURAUD), the indicator uses the inverse percentage (100 - strength). This correctly attributes strength. For example, if EURAUD is falling, it means AUD is strong, and this inverse logic captures that.
Averages the Score: Finally, it averages the scores from all the pairs in the basket to produce one final, stable strength percentage for your BaseCurrency.
2. Signal Generation (The "Output")
This part is simple and direct:
The final strength percentage is compared against the BuyThreshold and SellThreshold you set.
If Strength >= BuyThreshold, it displays a BUY signal.
If Strength <= SellThreshold, it displays a SELL signal.
If the strength is between the two thresholds, it displays a WAIT signal.
Analysis of User Inputs (extern variables)
This indicator is highly customizable through its inputs.
BaseCurrency: The most important input. Type the 3-letter code of the currency whose strength you want to measure (e.g., "AUD", "EUR", "JPY").
SignalSymbol: The symbol you want the trade signal for. Can be a forex pair, commodity, or index (e.g., "XAU", "US30", "GBPUSD").
Hours: Controls the lookback period for the strength calculation. A smaller number (e.g., 1) makes the indicator very responsive and short-term. A larger number (e.g., 8) makes it a slower, more trend-focused tool.
BuyThreshold / SellThreshold: These control the sensitivity of the signals. Values closer to 50 (e.g., 60 and 40) will generate more signals. Values further from 50 (e.g., 80 and 20) will generate fewer, but potentially more significant, signals for extreme strength or weakness.
Indicator_ID (Magic Number): This is a critical feature. It allows you to run multiple copies of the indicator on the same chart. You must set a different ID for each instance. For example, you can have one instance with Hours = 1 and Indicator_ID = 1111 for a short-term view, and a second instance with Hours = 8 and Indicator_ID = 2222 for a long-term view.
Display & Color Inputs: The rest of the inputs allow you to fully customize the position, font, size, and colors of the text on your chart to match your template.
How to Use in Trading
This is not a standalone "blindly follow" system. It is a professional confirmation tool.
As a Confirmation Tool: The best use case. Do your own analysis on a chart (e.g., XAUUSD). If your analysis suggests a buy, check the indicator. If it also shows XAU BUY with a high AUD strength, it provides strong confirmation for your trade.
For Divergence Trading: An advanced technique. If the SignalSymbol is making a new high, but the BaseCurrency strength is falling, this is a bearish divergence and could signal a potential reversal.
To Gauge Market Sentiment: By setting the BaseCurrency to a risk-on currency like "AUD" or a risk-off currency like "JPY", you can get a quick reading of the overall market mood.
Code Quality
The code is well-structured and robust.
Modularity: Each task (calculating strength, updating the display) is separated into its own function.
Dynamic Object Naming: The use of Indicator_ID to create unique object names is the correct way to implement multi-instance capability.
Error Handling: It checks if symbols exist on the broker's server before trying to use them, preventing errors and crashes.
"My Forex Holy Grail? Sure, I'll share it. It's a magical PDF that costs $997 and the first chapter is titled: 'How to Sell a $997 PDF.'"
