Warning: Declaration of ElementorPro\Modules\Posts\Skins\Skin_Content_Base::register_controls(Elementor\Widget_Base $widget) should be compatible with Elementor\Controls_Stack::register_controls() in /home/customer/www/backtest-rookies.com/public_html/wp-content/plugins/elementor-pro/modules/theme-builder/widgets/post-content.php on line 17
When we place a trade in the Forex market we are stating our belief about two economies at the same time. In other words we are betting that one economy is, or will be, stronger than the other. Before placing a trade it would be useful to validate our belief by looking at the overall strength of both the currencies in the pair that we are going to trade. After all, if one currency in the pair is weak against all major currencies, it is likely to be weak in the pair you are trading. With this in mind, a currency strength indicator would be a useful tool for analysis. For the US dollar we could argue that it is not needed. We have the USDOLLAR index to gauge USD strength but what about other currencies?
Currency strength indicator
The currency strength indicator shall take up to 4 currency pairs and calculate the average percentage change compared to the daily time frame. It will then plot all pairs on the chart along with an aggregate line that indicates the overall strength. An option is provided to flag a currency as the counter currency so that the percentage change is inverted. Consider this example. I want to know the strength of the British pound. In most pairs the pound is the base currency except against the Euro. This means that when the EURGBP rises, it the pound is weakening and vice versa. Therefore to get an accurate reading, I need to flag the pound as the counter currency and invert the percentage change result.
study(title="Currency Strength", shorttitle="CUR-STR", precision=4, scale=scale.left)
sym1 = input(title='FX Pair 1', type=symbol, defval='OANDA:GBPUSD')
sym1_counter = input(title='Counter Currency?', type=bool, defval=false)
sym2 = input(title='FX Pair 2', type=symbol, defval='OANDA:EURGBP')
sym2_counter = input(title='Counter Currency?', type=bool, defval=true)
sym3 = input(title='FX Pair 3', type=symbol, defval='OANDA:GBPJPY')
sym3_counter = input(title='Counter Currency?', type=bool, defval=false)
sym4 = input(title='FX Pair 4', type=symbol, defval='OANDA:GBPCHF')
sym4_counter = input(title='Counter Currency?', type=bool, defval=false)
inst1_daily = security(sym1, "D", close, lookahead=barmerge.lookahead_on)
inst2_daily = security(sym2, "D", close, lookahead=barmerge.lookahead_on)
inst3_daily = security(sym3, "D", close, lookahead=barmerge.lookahead_on)
inst4_daily = security(sym4, "D", close, lookahead=barmerge.lookahead_on)
inst1_current = security(sym1, period, close)
inst2_current = security(sym2, period, close)
inst3_current = security(sym3, period, close)
inst4_current = security(sym4, period, close)
inst1_change = ((inst1_current - inst1_daily) / inst1_daily) * 100
inst2_change = ((inst2_current - inst2_daily) / inst2_daily) * 100
inst3_change = ((inst3_current - inst3_daily) / inst3_daily) * 100
inst4_change = ((inst4_current - inst4_daily) / inst4_daily) * 100
inst1_change := sym1_counter == true ? inst1_change * -1 : inst1_change
inst2_change := sym2_counter == true ? inst2_change * -1 : inst2_change
inst3_change := sym3_counter == true ? inst3_change * -1 : inst3_change
inst4_change := sym4_counter == true ? inst4_change * -1 : inst4_change
overall_strength = (inst1_change + inst2_change + inst3_change + inst4_change) / 4
plot(inst1_change,title='Sym1', color=lime, style=area, transp=80)
plot(inst2_change,title='Sym2', color=blue, style=area, transp=90)
plot(inst3_change,title='Sym3', color=red, style=area, transp=90)
plot(inst4_change,title='Sym4', color=purple, style=area, transp=90)
plot(overall_strength,title='Overall Strength', color=black, linewidth=3, style=line)
// Test Plots
If you are wondering why I have lookahead on and want to know more about it, I have a post which describes lookhead in more detail here: Tradingview: Understanding lookahead, historical and realtime data
In addition, using the security() function to get data from another timeframe or instrument is covered in more detail here: Tradingview: Create an Indicator
The rest of the code is just calculating the percentage change and overall strength of the currency. If you are interested in the maths behind calculating a percentage change, I can point you to this tutorial:
Before I move on, I think it is worth noting why I chose to use area style plotting and transparency for all plots except the “overall strength” line. I did this because I felt the indicator would become over crowded otherwise. Additionally, in my opinion, the “overall strength” line is the most important plot and I was concerned it could become masked or harder to read.
Adding another currency
Should you feel 4 currency pairs are not enough, you can easily add more. As you can see from the code, we have 6 basic steps:
- Select the currency pairs
- Get the daily close for those pairs
- Get the close prices for the current time frame
- Calculate the difference between the current close price and the yesterday’s close
- Average the differences between each
- Finally plot the results.
Therefore to add another currency pair to the indicator you can:
- First, add new inputs from the pair. Be sure to create new variable names and default values. E.g sym5 below.
sym5 = input(title='FX Pair 5', type=symbol, defval='OANDA:GBPAUD')
sym5_counter = input(title='Counter Currency?', type=bool, defval=false)
- Second, Get the daily and current timeframe data for the pair. Again be careful to update the variable names and security() parameters
inst5_daily = security(sym5, "D", close, lookahead=barmerge.lookahead_on)
inst5_current = security(sym5, period, close)
- Third, Calculate the change and invert the value if the currency is the counter currency. If you see an error telling you that inst5_change is already declared, pay special attention to the “:=” operator. To update a variable that is already declared, you need to add a colon “:” in front of the equals operator.
inst5_change = ((inst5_current - inst5_daily) / inst5_daily) * 100
inst5_change := if sym5_counter == true
inst5_change * -1
- Finally add the new pair to the overall strength calculation and plot it.
overall_strength = (inst1_change + inst2_change + inst3_change + inst4_change + inst5_change) / 5
plot(inst5_change,title='Sym5', color=yellow, style=area, transp=80)
Usage Examples & Tips
Setup 2 indicators to compare strength
The example above shows GBPJPY with a GBP currency strength indicator and a JPY currency strength indicator. Both currencies are trending stronger. However the JPY is showing more strength and that is then reflected in a drop in the GBPJPY.
Identify opposing trends
Next we have an example showing how opposing trends can accelerate price movements. In the example below, the GBP starts to trend stronger whilst at the same time the USD starts to trend weaker. This causes a steady increase in prices followed by a final pop up.
Setting up for JPY and verifying the output
Finally, here is a screenshot of how to set up the indicator to monitor Japanese Yen strength. In all cases the JPY is the counter currency to set this up, open the settings page for the indicator and fill it out with the JPY pairs you are interested in as follows. If you want to save your settings don’t forget to click the down arrow next to the defaults button and select “Save As Default“.
For peace of mind, you may wish to verify the indicator. To do this simply add some currencies to your watchlist. Currencies added here will show the daily change percentage. It is the same time frame that the currency strength indicator uses.
Find This Post Useful?
If this post saved you time and effort, please consider support the site! There are many ways to support us and some won’t even cost you a penny.