Login Page - Create Account

Support Board


Date/Time: Thu, 28 Mar 2024 16:31:11 +0000



Post From: Offering To The Community: Forex: Currency Decorrelation (and Currency Strength)

[2016-05-02 07:18:44]
bjohnson777 (Brett Johnson) - Posts: 284
Since "Forex: Currency Strength" relies on this program, I've compiled them together and posted them here. Please keep discussions about "Forex: Currency Decorrelation" here and "Forex: Currency Strength" at the separate link below.

For documentation on "Forex: Currency Strength" go here:
Offering To The Community: Forex: Currency Strength

This currency decorrelation program is a little more advanced than most. Having the price scale in a currency is far easier to read and compare movements.

----------
From the "Display Study Documentation" button:

Forex: Currency Decorrelation. Also allows for calculating Cross Currencies/Minor Currencies. This program will form the base for my Forex currency strength programs. The Sierra Chart Data Service has the 8 major currencies decorrelated, but the scaling between each has diverged and is hard to compare. Other currency decorrelation programs are also like that. This program displays the price scale in the currency that is decorrelated. In settings, check "Display As Main Price Graph" to see this. There is also an option to convert the currency price scale to a different currency. This is helpful for those people wishing to see the index line(s) in their native currency.

This program includes a function to decorrelate other currencies and display them on the graph with the same scaling. This will show currency movement relative to the others and their highs and lows. This will help you select the best pair for trading. Since all currencies are proportionally scaled to each other, they will be normalized to 1.0 using the "Bars Back" option. A generally good number is 300 for this. You don't want the bars to be too far back or the index lines will separate and be hard to compare. This is discussed in the settings option below.

Note: The various calculations used to produce the index lines are a type of average. They are close but not exact. There is no absolute price for an index line. This is also true of other programs using these calculations. Multiple index lines will be properly scaled to each other. Expect them to move up and down a little. This is normal. The relationships between the index lines will still be the same. The distance relationships and patterns are what's important.
In physics, there are fixed known quantities that graph lines can be converted against. In finance, there is no such thing. Ideally one of the major commodities "should" fill that role, but over the past several years they all have moved around too much to be useful.

Default Example. To decorrelate USD and see the other 7 major currencies in scaled USD spacing, open any historical/daily symbol into a new chartbook, select Main Menu >> Chart >> Chart Settings and change "Use Number Of Days To Load" to greater than 500, load this program, change "Are you ready for MANY open windows?" to Yes, change "Decorrelate Other Currencies?" to Yes, select "Display As Main Price Graph", and hit OK. Go to Main Menu >> CW to select your original chart again. You may need to select Main Menu >> Chart >> Recalculate after the other charts finish loading their data (default keys: CTRL-INSERT or just INSERT). Select the graph region and hit the down arrow on the keyboard to bring the bar spacing down to 1. The white line will be USD. The colored lines are labeled at the top of the chart.

Note: This program will open a chart window for each symbol in the list. Sierra Chart requires an open window to get the symbol data. With a long symbol list, the number of windows will quickly become difficult to manage. It is recommended to run this program in its own chartbook so the extra windows are contained. The extra windows can be hidden or minimized. This is recommended to reduce the CPU load for drawing graphics that won't be seen. To return to your first window, use the CW menu to find your original symbol. The new index will be on this chart and not any of the others. If a source chart window gets closed, the program will have an internal error for that symbol. To bring the window back, go back into the study settings, exit the window, and everything should be recreated (or use Main Menu >> Chart >> Recalculate, CTRL-INSERT, or INSERT). If the chart's time frame is changed, new data chart windows will be opened for each symbol in the new time frame. This can create an excessive number of windows if you're not paying attention.

Note: The index lines will not be correctly drawn until all the other charts have finished downloading historical data. Sometimes malformed index lines get drawn until the other charts finish downloading. Sometimes those lines will be jumping around, too. This is normal behavior. If the index lines get stuck, either select Main Menu >> Chart >> Recalculate, hit CTRL-INSERT, hit INSERT, or go into the study settings and exit to manually force a redraw.

The symbol list format is discussed in the settings section below. Be careful that everything is typed in accurately. A malformed symbol list will have an undefined behavior. At the bottom of the settings window are 2 flags for number of symbols found and number of symbols used. If the used flag is less than found, there was an error loading one of the charts. A weight for each symbol is allowed for manipulation. Generally weights are not used in Forex, but the option is there. The symbol list was chosen to be a text string for ease of use, backup, and sharing. Once the graph loads, you can go back into settings and copy out a cleaned symbol list to a text editor to save as a backup or as a different version of an index you are working on. If you create an interesting index, you are encouraged to share it by copying and pasting the symbol list to a message board. If someone else posts an interesting symbol list, copy and paste it into the symbol list box in the settings window to see the new index.

Calculation. Equation: Index = 1.0 / ( sum(1.0/USDXXX) + sum(YYYUSD) )
Where: USDXXX is all the symbols with USD in the base currency position (like USD/JPY). YYYUSD is all the symbols with USD in the counter currency position (like EUR/USD).
For a USD index, calculating another currency keeping the scaling ratio: Base Currency Position: JPYi = USDi / USDJPY. Counter Currency Position: EURi = USDi * EURUSD.
Problem: None of the currencies are normalized in these equations. Some will have much greater weights than others. Solution: USD should be in the counter currency position (invert if not). Set a multiplier so that the USD currency value of the current bar equals $1.00 (USD in this example). Other currencies set to decorrelate are also set to 1.0 on the current bar when this program is loaded or recalculated. This essentially sets the high and low to a percentage value above and below 1.0. Each currency can be accurately compared internally to generate the decorrelated average. If data is missing, Sierra Chart might use the last completed bar to fill it in. If the bar is 0.0, this program will remove it from the average for that bar.

General Sierra Chart Notes. For each chart, Sierra Chart will try to load as many days as in Chart Settings >> Use Number Of Days To Load. Do NOT load an excessive number of days for an intra day chart. It will create a very heavy processing load and slow down Sierra Chart. With the way the index is calculated, I could not use Sierra Chart's internal moving averages to smooth the lines out. It is still easy to add one, though. Go into "Study Settings", select this study and mark it hidden, add a moving average study after this one, change "Based On" to "Forex: Currency Decorrelation", change "Input Data" to "XXX Index", and change "Scale" to "Independent". The same steps can be used for my Moving Average Ribbon or Bollinger Band Ribbon. To get rid of the source graph, use the "Display As Main Price Graph" settings option. Be sure to rename the graph tab to something meaningful. From there, studies like moving averages and Bollinger Bands (even MACD) will use the index as their data sources. SAR, trend, and Fibonacci lines can also be drawn. This offers some interesting index analysis options. Studies that depend on bars and volume will not work since the index is only a line.

Ideal Trading: Pick currencies that are moving opposite to each other. Less Ideal: pick one currency that's moving and the other is flat. Less Ideal: Pick both currencies moving the same direction but one is much faster than the other. Don't Trade: If the 2 currencies are flat, that is a bad trade. Don't Trade: If the 2 currencies are moving evenly with each other, that is a bad trade.

Observation: Open a 5min or 15min chart with the entire day visible on the screen and enable all the Other Currencies option. Change the Bars Back option if all the index lines are away from each other. It's easy to see when the market is active and dies off when the index lines go flat. Use this to determine the best time of day for your trading style.

Currency Lists. If you have the Sierra Chart Data Service, these can be copied and pasted into this program to generate an index for the listed currency.

Major Currencies:
AUD (Australian Dollar): AUDCAD (AUD CAD), AUDCHF (AUD CHF), AUDJPY (AUD JPY), AUDNZD (AUD NZD), AUDUSD (AUD USD), EURAUD (EUR AUD), GBPAUD (GBP AUD)
CAD (Canadian Dollar): AUDCAD (AUD CAD), CADCHF (CAD CHF), CADJPY (CAD JPY), EURCAD (EUR CAD), GBPCAD (GBP CAD), NZDCAD (NZD CAD), USDCAD (USD CAD)
CHF (Swiss Franc): AUDCHF (AUD CHF), CADCHF (CAD CHF), CHFJPY (CHF JPY), EURCHF (EUR CHF), GBPCHF (GBP CHF), NZDCHF (NZD CHF), USDCHF (USD CHF)
CHF (Swiss Franc extended): AUDCHF (AUD CHF), CADCHF (CAD CHF), CHFJPY (CHF JPY), CHFNOK (CHF NOK), CHFSEK (CHF SEK), EURCHF (EUR CHF), GBPCHF (GBP CHF), NZDCHF (NZD CHF), USDCHF (USD CHF)
EUR (Euro): EURAUD (EUR AUD), EURCAD (EUR CAD), EURCHF (EUR CHF), EURGBP (EUR GBP), EURJPY (EUR JPY), EURNZD (EUR NZD), EURUSD (EUR USD)
EUR (Euro extended): EURAUD (EUR AUD), EURCAD (EUR CAD), EURCHF (EUR CHF), EURCZK (EUR CZK), EURDKK (EUR DKK), EURGBP (EUR GBP), EURJPY (EUR JPY), EURNOK (EUR NOK), EURNZD (EUR NZD), EURSEK (EUR SEK), EURTRY (EUR TRY), EURUSD (EUR USD)
GBP (British Pound): EURGBP (EUR GBP), GBPAUD (GBP AUD), GBPCAD (GBP CAD), GBPCHF (GBP CHF), GBPJPY (GBP JPY), GBPNZD (GBP NZD), GBPUSD (GBP USD)
GBP (British Pound extended): EURGBP (EUR GBP), GBPAUD (GBP AUD), GBPCAD (GBP CAD), GBPCHF (GBP CHF), GBPDKK (GBP DKK), GBPHKD (GBP HKD), GBPJPY (GBP JPY), GBPMXN (GBP MXN), GBPNOK (GBP NOK), GBPNZD (GBP NZD), GBPSEK (GBP SEK), GBPSGD (GBP SGD), GBPUSD (GBP USD)
NZD (New Zealand Dollar): AUDNZD (AUD NZD), EURNZD (EUR NZD), GBPNZD (GBP NZD), NZDCAD (NZD CAD), NZDCHF (NZD CHF), NZDJPY (NZD JPY), NZDUSD (NZD USD)
JPY (Japanese Yen): AUDJPY (AUD JPY), CADJPY (CAD JPY), CHFJPY (CHF JPY), EURJPY (EUR JPY), GBPJPY (GBP JPY), NZDJPY (NZD JPY), USDJPY (USD JPY)
JPY (Japanese Yen extended): AUDJPY (AUD JPY), CADJPY (CAD JPY), CHFJPY (CHF JPY), DKKJPY (DKK JPY), EURJPY (EUR JPY), GBPJPY (GBP JPY), HKDJPY (HKD JPY), NOKJPY (NOK JPY), NZDJPY (NZD JPY), SEKJPY (SEK JPY), SGDJPY (SGD JPY), TRYJPY (TRY JPY), USDJPY (USD JPY), ZARJPY (ZAR JPY)
USD (US Dollar): AUDUSD (AUD USD), EURUSD (EUR USD), GBPUSD (GBP USD), NZDUSD (NZD USD), USDCAD (USD CAD), USDCHF (USD CHF), USDJPY (USD JPY)
USD (US Dollar extended): AUDUSD (AUD USD), EURUSD (EUR USD), GBPUSD (GBP USD), NZDUSD (NZD USD), USDCAD (USD CAD), USDCHF (USD CHF), USDCHN (USD CHN), USDDKK (USD DKK), USDHKD (USD HKD), USDJPY (USD JPY), USDMXN (USD MXN), USDNOK (USD NOK), USDRUB (USD RUB), USDSEK (USD SEK), USDSGD (USD SGD), USDTRY (USD TRY), USDZAR (USD ZAR)

Cross Currencies
NOK (Norwegian Krone): CHFNOK (CHF NOK), EURNOK (EUR NOK), GBPNOK (GBP NOK), NOKJPY (NOK JPY), USDNOK (USD NOK)
SEK (Swedish Krone): CHFSEK (CHF SEK), EURSEK (EUR SEK), GBPSEK (GBP SEK), SEKJPY (SEK JPY), USDSEK (USD SEK)
DKK (Danish Krone): DKKJPY (DKK JPY), EURDKK (EUR DKK), GBPDKK (GBP DKK), USDDKK (USD DKK)
TRY (Turkish Lira): EURTRY (EUR TRY), TRYJPY (TRY JPY), USDTRY (USD TRY)
HKD (Hong Kong Dollar): GBPHKD (GBP HKD), HKDJPY (HKD JPY), USDHKD (USD HKD)
MXN (Mexican Peso): GBPMXN (GBP MXN), USDMXN (USD MXN)
SGD (Singapore Dollar): GBPSGD (GBP SGD), SGDJPY (SGD JPY), USDSGD (USD SGD)
ZAR (South African Rand): USDZAR (USD ZAR), ZARJPY (ZAR JPY)

Observations:
Most decorrelations should have 3 or more currency pairs to start being accurate.
Some of the lightly traded cross currencies may be missing data and might skew the index line. This is a data source problem, not a problem with this program.
The Sierra Chart Data Service also has symbols like "^USDINR" for US Dollar / Indian Rupee. In the Symbol List it would be entered as "^USDINR (USD INR)". Note that some of the symbols starting with ^ are lightly traded and some are missing data. Check them carefully before using them. The symbols that are complete can be used to decorrelate many other currencies.
The GBPDKK 2015 spike problem throws off the calculation for both. DKK should normally be left out of a GBP decorrelation on higher time scales.
If you have XAUUSD, it is set up kind of like a currency. Gold: XAU, Currency: USD, USD per troy ounce of gold. Enter "XAUUSD (XAU USD)" in the Symbol List. The Sierra Chart Data Service also has other currencies paired up with gold.
The US Dollar Index (USDX) is a complex calculation with a couple dozen different currencies each of different weights that periodically get changed. Reproducing that index with this program is mostly possible but not really recommended. The USDX doesn't follow Forex actuality very well.

If you're running linux, you can use the command line to search for a symbol and generate a CSV list. For this program, the list will still need cleaning and the currency symbols split up, but this is much easier than manually searching through the "Find Symbol" scroll box. First go into the install directory and generate the symbol list:

cat GlobalSymbolSettings.xml | grep -i '<symbol>' | tr -d '\t' | tr -d ' ' | cut -d\> -f2 | cut -d\< -f1 > sc_symbols.lst

Search for the symbol (USD in this example):

grep -i 'USD' sc_symbols.lst | tr '\n' ' ' | sed s/' '/', '/g | sed s/', $'/''/ ; echo

----------------------------------------
Input Descriptions


Are you ready for MANY open windows?
Enables study. A window for each symbol must be open to get data from it. A long symbol list will create a lot of windows. It is recommended to put each index in its own chartbook for organization.

Currency To Decorrelate
This is the currency to decorrelate (extract) from the symbol list. If you want to create a graph of USD, then enter USD here.
Symbol List (sym1 (XXX YYY) 1.0, ...)
Enter a list of broker symbols containing the extraction currency that will be used to decorrelate that currency. Format: BrokerSymbolName (BaseCurrency CounterCurrency) Weight. BrokerSymbolName is the name of the symbol used by the broker to load the chart. It may be a complex name (as opposed to EURUSD) and capitalization may matter. BaseCurrency is the currency name of the symbol in the base currency position (for EURUSD, it would be EUR). CounterCurrency is the currency name of the symbol in the counter currency position (for EURUSD, it would be USD). Weight is a floating point number and is optional. A weight of 1.0 corresponds to 100%. A weight of 0.5 corresponds to 50%. Manually entering in BaseCurrency and CounterCurrency allows for a BrokerSymbolName that may not be easily automatically parseable. An invalid symbol list will produce undefined results.

Input Data
Usually "Last" for Close or "HLC Avg" for Typical Price.

Intraday: Load Weekend Data?
Load weekend intraday data if available. This does not load weekend data for historical daily bars.

Convert Scale To Another Currency?
If No, the price scale will be in the units of the extracted currency. If Yes, the price scale will be converted to the conversion currency below. You need to select "Display As Main Price Graph" to see the new scale.

Currency To Convert Scale To
If enabled, the price scale will be converted to this currency.

Currency Conversion Symbol (sym1 (XXX YYY))
This is the Broker Symbol that contains both the extraction currency and the conversion currency. The format is the same as the Symbol List above but without the weight.

Decorrelate Other Currencies?
Once the main decorrelated currency at the top is extracted, other currencies with the decorrelated currency in them can be extracted.

Other Currencies Bars Back
Number of bars back to go to set the other currencies equal to 1.0 for normalization. From that point forward, the other currencies will move normally proportional to each other. If there is no data, this function will hunt forward until it finds something so the index line won't be set to zeros. Set this to 0 for the first bar in the graph. The generally best setting would have all of the currencies in a roughly rectangular area without one going too high or too low beyond all the others. This gives a rough estimation of currencies that are overbought or oversold. Keep in mind that if a currency breaks past the rectangular area, it may not be in an over bought/sold condition if the Bars Back number is changed. The price numbers are not absolute (it will shift some), but all numbers are scaled properly to each other. 300 bars back seems to be a good choice for most time frames.

Other Currencies Symbol List (sym1 (XXX YYY), sym2 (XXX YYY), ...)
This format is the same as the Symbol List above. Enter symbols that contain the main decorrelated currency and the other currency will be graphed with the main decorrelated currency. The scales of the newly graphed currencies will be proportional to the main decorrelated currency for easy comparison. To see the numbers, you need to select "Display As Main Price Graph".

Limit Number Of Open Charts
Safety Setting. Opening different time frames will open matching charts for that time frame. The number of charts can quickly get out of hand and eat up all the system resources. Any chart above the given number will cause this program to disable itself and remove the index line. There is also a strange upgrade condition that might cause an infinite chart loop. This setting will stop that once the limit number is reached. Use "Close Charts" to close the unused charts. Set to 0 to disable (not recommended). If you do disable, make sure your symbol list and other charts in the chartbook are backed up because you will not be able to get back to them in an infinite loop.

Close All Other Charts?
If set to "One Shot", will close all other charts in the chart book except this one. This is used to close charts that are not part of the index and taking up resources. You will need to go back into settings and exit to redraw the index after this runs. WARNING: This will not save any data from an opened chart that gets closed.

Highest Chart Number To Close
Used with "Close All Other Charts". Sierra Chart does not have an open charts array, yet. This is the highest chart number you see open that will be closed. Default is 210. Higher is OK but will slow down the program call slightly.

FLAG: Number Of Symbols Found
This is a Flag reporting the number of symbols found in the Symbol List (not necessarily openable symbols). Changing it will not do anything.

FLAG: Active Symbols Used
This is a Flag reporting the number of symbols actively being used in the calculations. If this number is less than the found symbols above, then there were errors opening the missing charts. Changing it will not do anything.

FLAG: Other Active Symbols Used
This is a Flag reporting the number of symbols actively being used in the Other Currencies Symbol List calculations. Changing it will not do anything.

-----
Update: 2022-07-10. Fixed compile issue with latest version (2411).
Regular compiles moved to "Brett Johnson's Standard Tool Kit" DLL.
Offering To The Community: Brett Johnson's Standard Tool Kit
Date Time Of Last Edit: 2022-07-10 07:41:22
attachmentForex_CurrencyDecorrelationAndCurrencyStrength.cpp - Attached On 2022-07-10 07:41:18 UTC - Size: 127.48 KB - 113 views