This script is a specialized technical analysis tool designed for traders who want to observe the relative strength of major world currencies (USD, EUR, GBP, JPY, and CHF) rather than just individual currency pairs. Instead of looking at one pair in isolation, it calculates synthetic "indices" to show which currency is currently leading or lagging in the global market.
Core Logic and Functionality
1. Currency Index Calculation The tool identifies specific "strength" values for each major currency. It does this by analyzing multiple exchange rates simultaneously. For example, to determine the strength of the Euro (EUR), it looks at its performance against the US Dollar, British Pound, Swiss Franc, and Japanese Yen. By combining these various cross-rates using a mathematical average, it creates a unified value for each individual currency.
2. Dynamic Pair Identification The script is intelligent enough to recognize which pair you are currently viewing on your chart (e.g., EURUSD or GBPJPY). Based on your selection, it automatically separates the two currencies involved into their respective "Base" and "Quoted" indices. This allows you to see, for instance, how the Euro's general strength compares specifically against the British Pound's general strength.
3. Momentum and Trend Analysis Once the currency indices are established, the script applies several layers of technical analysis:
- Relative Strength Index (RSI): It calculates the RSI for both currencies involved in your current pair. This helps identify if a currency is becoming "overbought" or "oversold."
- ADX-style Divergence: It calculates a custom difference between the two currency strengths to highlight how far apart they are moving.
- Smoothing: To filter out market "noise" and erratic price jumps, the script applies Moving Averages (EMA) to both the RSI and the strength differences. This results in smoother, more readable lines on your chart.
Key Features for the User
- Compatibility: The tool is specifically designed to work on major pairs involving USD, EUR, GBP, JPY, and CHF. If applied to a pair not supported by the logic, it will alert the user.
- Visual Clarity: It provides three distinct visual components: two smoothed RSI lines (representing the strength of each currency) and a third line representing the gap or difference between them.
- Data Integrity: The script includes safeguards to ensure that if market data is missing or returns a zero value, the calculation doesn't break, ensuring a continuous line for your analysis.
Summary of Purpose
Essentially, this tool transforms a standard currency pair chart into a "battle of strengths." Instead of just seeing that EURUSD is going up, it helps you see if the Euro is getting stronger as a whole, or if the US Dollar is simply getting significantly weaker compared to the rest of the world.
//+-------------------------------------------------------------------------+
//| Index_pair_v23b.mq4 |
//| GrayMan77&akadex |
//| Ðàñ÷åò RSI îò èíäåêñîâ âàëþò ïàðû |
//| Èäåÿ ðàñ÷åòà èíäåêñà: |
//| - Þ.Ìàêàðîâ |
//| http://www.may.nnov.ru/mak/ |
//| - À.Ïëÿñóíîâ |
//| http://www.umis.ru/clients1/study/trading_school/fc_methods?start=0 |
//| Èäåÿ ïðèìåíåíèÿ RSI - akadex |
//| http://www.kroufr.ru/forum/index.php?topic=2692.msg6724;topicseen |
//| Ðåàëèçàöèÿ - GrayMan77 |
//| |
//| ÏÐÈÌÅÍßÒÜ ÒÎËÜÊÎ ÄËß ÏÀÐ ÂÀËÞÒ USD,EUR,GBP,JPY,CHF! |
//| ----------------------------------------------------------------------- |
//| v1 - ïåðåïèñàí èíäèêàòîð îò akadex dex_RSIndex.mq4: |
//| äîáàâëåíî àâòîîïðåäåëåíèå ïàðû, IndicatorCounted è |
//| ïåðâè÷íîå ñãëàæèâàíèå öåíû (FirstEMA). |
//| |
//| v2 - âû÷èñëåíèå èíäåêñîâ äðóãèõ âàëþò ÷åðåç êðîññû |
//| (áåç âåñîâûõ êîýôôèöèåíòîâ) |
//| |
//| v21 - èíäèêàòîð ïåðåïèñàí ñ öåëüþ îïòèìèçàöèè |
//| |
//| v22 - ðàñ÷åò èíäåêñîâ - â ôóíêöèÿõ |
//| |
//| v23 - ðàñ÷åò ADX |
//| |
//| v23b - îñâîáîæäåí áóôåð |
//| ïîèñê áàðîâ â èñòîðèè íå ïî ñìåùåíèþ, à ïî âðåìåíè |
//+-------------------------------------------------------------------------+
#property copyright "GrayMan77 & akadex"
#property link ""
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 White
#property indicator_level1 30
#property indicator_level2 50
#property indicator_level3 70
#property indicator_width3 2
//#property indicator_minimum 0
//#property indicator_maximum 100
//---- Âíåøíèå ïàðàìåòðû
extern int RSIPeriod=5;
extern int Smooth=10;
extern int SmoothADX=10;
extern int PeriodFirstEMA=1; // Ïåðâè÷íîå ñãëàæèâàíèå - ïåðèîä
extern int PriceFirstEMA=6; // Ïåðâè÷íîå ñãëàæèâàíèå - öåíà:
// 0-Close; 1-Open; 2-High; 3-Low; 4-(H+L)/2; 5-(H+L+C)/3; 6-(H+L+C+C)/4.
//---- Áóôåðû èíäèêàòîðà
double IndexBuffer[],Buffer[],RSIBuffer[],ADXtemp[];
double IndexBuffer1[],Buffer1[],RSIBuffer1[],ADX[];
//---- Ïåðåìåííûå
int BarsMin;
double div;
bool Show=false;
int indBars; // õðàíèì çíà÷åíèå Bars
//----
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(7);
SetIndexBuffer(0,RSIBuffer);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(1,RSIBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(2,ADX);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(3,IndexBuffer);
SetIndexBuffer(4,IndexBuffer1);
SetIndexBuffer(5,Buffer);
SetIndexBuffer(6,Buffer1);
// SetIndexBuffer(7,ADXtemp);
ArraySetAsSeries(ADXtemp,true);
IndicatorShortName("Index_pair_v23b: "+Symbol() + "(" + Period() + "): ");
SetIndexLabel(0, StringSubstr(Symbol(),0,3));
SetIndexLabel(1, StringSubstr(Symbol(),3,3));
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit,i;
string S=Symbol();
int counted_bars=IndicatorCounted();
//---- ïðîâåðêà íà âîçìîæíûå îøèáêè
if(counted_bars<0) return(-1);
if(Show==false)
{
if(S=="GBPUSD" || S=="USDCHF" || S=="EURUSD" || S=="USDJPY" || S=="EURGBP" ||
S=="EURCHF" || S=="EURJPY" || S=="GBPCHF" || S=="GBPJPY" || S=="CHFJPY")
Show=true;
}
if(Show==false)
{
Alert("- ERROR! - Èíäèêàòîð íå ðàáîòàåò íà ïàðå ",S," !!!");
Print("--- ERROR ! --- Èíäèêàòîð íå ðàáîòàåò íà ïàðå ",S," !!!");
return(-1);
}
//---- âû÷èñëåíèå ìèíèìàëüíîãî êîë-âà áàðîâ (äëèíû îòîáðàæàåìîãî ãðàôèêà)
if(counted_bars==0)
{
BarsMin=iBars("GBPUSD",NULL);
if(BarsMin>iBars("USDCHF",NULL)) BarsMin=iBars("USDCHF",NULL);
if(BarsMin>iBars("EURUSD",NULL)) BarsMin=iBars("EURUSD",NULL);
if(BarsMin>iBars("USDJPY",NULL)) BarsMin=iBars("USDJPY",NULL);
if(BarsMin>iBars("EURGBP",NULL)) BarsMin=iBars("EURGBP",NULL);
if(BarsMin>iBars("EURCHF",NULL)) BarsMin=iBars("EURCHF",NULL);
if(BarsMin>iBars("EURJPY",NULL)) BarsMin=iBars("EURJPY",NULL);
if(BarsMin>iBars("GBPCHF",NULL)) BarsMin=iBars("GBPCHF",NULL);
if(BarsMin>iBars("GBPJPY",NULL)) BarsMin=iBars("GBPJPY",NULL);
if(BarsMin>iBars("CHFJPY",NULL)) BarsMin=iBars("CHFJPY",NULL);
}
// Åñëè ïîÿâèëñÿ íîâûé áàð, óâåëè÷èâàå ðàçìåðíîñòü ìàññèâà è ñäâèãàåì çíà÷åíèÿ íà åäèíèöó
if (isNewBar())
{
ArrayResize(ADXtemp,Bars);
for(i=Bars-1;i>0;i--)
{
ADXtemp[i]=ADXtemp[i-1];
}
ADXtemp[0]=0.;
}
//---- ïîñëåäíèé ïîñ÷èòàííûé áàð áóäåò ïåðåñ÷èòàí
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
if(limit>BarsMin-2) limit=BarsMin-2;
//---- îñíîâíîé öèêë
for(i=limit;i>=0;i--)
{
//---- Âûáîð íóæíîé ïàðû èíäåêñîâ
if (Symbol() == "EURUSD") { IndexBuffer[i]=EUR(i); IndexBuffer1[i]=USD(i); }
if (Symbol() == "EURGBP") { IndexBuffer[i]=EUR(i); IndexBuffer1[i]=GBP(i); }
if (Symbol() == "EURCHF") { IndexBuffer[i]=EUR(i); IndexBuffer1[i]=CHF(i); }
if (Symbol() == "EURJPY") { IndexBuffer[i]=EUR(i); IndexBuffer1[i]=JPY(i); }
if (Symbol() == "GBPUSD") { IndexBuffer[i]=GBP(i); IndexBuffer1[i]=USD(i); }
if (Symbol() == "GBPCHF") { IndexBuffer[i]=GBP(i); IndexBuffer1[i]=CHF(i); }
if (Symbol() == "GBPJPY") { IndexBuffer[i]=GBP(i); IndexBuffer1[i]=JPY(i); }
if (Symbol() == "USDCHF") { IndexBuffer[i]=USD(i); IndexBuffer1[i]=CHF(i); }
if (Symbol() == "USDJPY") { IndexBuffer[i]=USD(i); IndexBuffer1[i]=JPY(i); }
if (Symbol() == "CHFJPY") { IndexBuffer[i]=CHF(i); IndexBuffer1[i]=JPY(i); }
}
//---- Âû÷èñëåíèå RSI îò èíäåêñîâ
for(i=limit;i>=0;i--)
{
Buffer[i]=iRSIOnArray(IndexBuffer,0,RSIPeriod,i);
Buffer1[i]=iRSIOnArray(IndexBuffer1,0,RSIPeriod,i);
//---- Âû÷èñëåíèå ADX îò RSI
div=MathAbs(Buffer1[i]+Buffer[i]);
if(div==0.00) {ADXtemp[i]=0;}
else {ADXtemp[i]=100*(MathAbs(Buffer1[i]-Buffer[i])/div);}
}
//---- Ñãëàæèâàíèå RSI è ADX
for(i=limit;i>=0;i--)
{
ADX[i]=iMAOnArray(ADXtemp,0,SmoothADX,0,MODE_EMA,i);
RSIBuffer[i]=iMAOnArray(Buffer,0,Smooth,0,MODE_EMA,i);
RSIBuffer1[i]=iMAOnArray(Buffer1,0,Smooth,0,MODE_EMA,i);
if(RSIBuffer[i]>100.) RSIBuffer[i]=100.;
if(RSIBuffer1[i]>100.) RSIBuffer1[i]=100.;
}
//----
return(0);
}
//+------------------------------------------------------------------+
double USD(int j)
{
double value;
datetime TimeBar=Time[j];
double GBP_USD=iMA("GBPUSD",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("GBPUSD",NULL,TimeBar,false));
double USD_CHF=iMA("USDCHF",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("USDCHF",NULL,TimeBar,false));
double EUR_USD=iMA("EURUSD",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("EURUSD",NULL,TimeBar,false));
double USD_JPY=iMA("USDJPY",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("USDJPY",NULL,TimeBar,false));
// Ïðîâåðêà äëÿ èñêëþ÷åíèÿ äåëåíèÿ íà 0
if(GBP_USD==0) GBP_USD=1.;
if(EUR_USD==0) EUR_USD=1.;
value = MathPow(USD_CHF*USD_JPY/GBP_USD/EUR_USD,0.2);
return(value);
}
//+------------------------------------------------------------------+
double GBP(int j)
{
double value;
datetime TimeBar=Time[j];
double GBP_USD=iMA("GBPUSD",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("GBPUSD",NULL,TimeBar,false));
double EUR_GBP=iMA("EURGBP",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("EURGBP",NULL,TimeBar,false));
double GBP_CHF=iMA("GBPCHF",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("GBPCHF",NULL,TimeBar,false));
double GBP_JPY=iMA("GBPJPY",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("GBPJPY",NULL,TimeBar,false));
// Ïðîâåðêà äëÿ èñêëþ÷åíèÿ äåëåíèÿ íà 0
if(EUR_GBP==0) EUR_GBP=1.;
value = MathPow(GBP_USD*GBP_CHF*GBP_JPY/EUR_GBP,0.2);
return(value);
}
//+------------------------------------------------------------------+
double EUR(int j)
{
double value;
datetime TimeBar=Time[j];
double EUR_USD=iMA("EURUSD",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("EURUSD",NULL,TimeBar,false));
double EUR_GBP=iMA("EURGBP",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("EURGBP",NULL,TimeBar,false));
double EUR_CHF=iMA("EURCHF",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("EURCHF",NULL,TimeBar,false));
double EUR_JPY=iMA("EURJPY",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("EURJPY",NULL,TimeBar,false));
value = MathPow(EUR_USD*EUR_GBP*EUR_CHF*EUR_JPY,0.2);
return(value);
}
//+------------------------------------------------------------------+
double CHF(int j)
{
double value;
datetime TimeBar=Time[j];
double USD_CHF=iMA("USDCHF",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("USDCHF",NULL,TimeBar,false));
double EUR_CHF=iMA("EURCHF",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("EURCHF",NULL,TimeBar,false));
double GBP_CHF=iMA("GBPCHF",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("GBPCHF",NULL,TimeBar,false));
double CHF_JPY=iMA("CHFJPY",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("CHFJPY",NULL,TimeBar,false));
// Ïðîâåðêà äëÿ èñêëþ÷åíèÿ äåëåíèÿ íà 0
if(USD_CHF==0) USD_CHF=1.;
if(EUR_CHF==0) EUR_CHF=1.;
if(GBP_CHF==0) GBP_CHF=1.;
value = MathPow(CHF_JPY/USD_CHF/EUR_CHF/GBP_CHF,0.2);
return(value);
}
//+------------------------------------------------------------------+
double JPY(int j)
{
double value;
datetime TimeBar=Time[j];
double USD_JPY=iMA("USDJPY",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("USDJPY",NULL,TimeBar,false));
double EUR_JPY=iMA("EURJPY",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("EURJPY",NULL,TimeBar,false));
double GBP_JPY=iMA("GBPJPY",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("GBPJPY",NULL,TimeBar,false));
double CHF_JPY=iMA("CHFJPY",NULL,PeriodFirstEMA,0,1,PriceFirstEMA,iBarShift("CHFJPY",NULL,TimeBar,false));
// Ïðîâåðêà äëÿ èñêëþ÷åíèÿ äåëåíèÿ íà 0
if(USD_JPY==0) USD_JPY=1.;
if(EUR_JPY==0) EUR_JPY=1.;
if(GBP_JPY==0) GBP_JPY=1.;
if(CHF_JPY==0) CHF_JPY=1.;
value = MathPow(1./USD_JPY/EUR_JPY/GBP_JPY/CHF_JPY,0.2);
return(value);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| âîçâðàùàåò true åñëè ïîÿâëèñÿ íîâûé áàð, èíà÷å false |
//+------------------------------------------------------------------+
bool isNewBar()
{
//----
bool res=false;
if (indBars!=Bars)
{
indBars=Bars;
res=true;
}
//----
return(res);
}
Comments