dex_RSIndex
Download scriptThis tool is designed to provide traders with a multi-currency perspective by calculating and visualizing a custom "Index" based on several major global currencies. Instead of looking at a single currency pair in isolation, this script helps you see how different denominations relate to each other within a unified mathematical framework.
Core Logic Overview
The script performs three primary stages of calculation to turn raw price data into a smooth, readable trend line:
1. Synthetic Price Calculation The tool starts by pulling the closing prices for four major currency pairs: GBP/USD, USD/CHF, EUR/USD, and USD/JPY. It then applies a specific mathematical formula to these prices to derive a base "USD" value. From this base, it calculates the relative values for five different currencies:
- US Dollar (USD)
- British Pound (GBP)
- Euro (EUR)
- Swiss Franc (CHF)
- Japanese Yen (JPY)
2. User Selection & Mapping The logic allows you to choose which of these five calculated currencies you want to monitor. You can select one primary currency to view on the first line and a second currency to view on the second line. This allows for a side-by-side comparison of two different currency strengths at any given time.
3. Smoothing and Trend Analysis To make the data easier to read, the script doesn't just show raw, jagged price movements. It passes the selected currency values through two layers of refinement:
- RSI (Relative Strength Index): First, it applies an RSI calculation to determine the momentum of the selected currencies.
- EMA (Exponential Moving Average): Finally, it applies a smoothing average to that momentum data.
What this means for the user
By combining these three steps, the indicator removes "noise" from the market. Instead of seeing every tiny price fluctuation, you are presented with two smooth lines that represent the underlying strength and trend of your chosen currencies. This helps in identifying whether a currency is becoming overextended or if it is maintaining a steady upward or downward trajectory relative to the others in the index.
//+------------------------------------------------------------------+
//| dex_RSIndex.mq4 |
//| Copyright © 2006, akadex. |
//| tohell |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, akadex"
#property link "tohell"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Aqua
#property indicator_level1 30
#property indicator_level2 50
#property indicator_level3 70
#property indicator_width1 2
#property indicator_minimum 0
#property indicator_maximum 100
//---- input parameters
extern string Çíà÷åíèÿ_âàëþò="0=USD 1=GBP 2=EUR 3=CHF 4=JPY";
extern int ShowCurrency=0;
extern int ShowCurrency1=2;
extern int RSIPeriod=12;
extern int Smooth=12;
extern int NumberBars = 1000;
extern int Shift = 0;
//---- buffers
double IndexBuffer[],Buffer[],Buffers[],RSIBuffer[];
double IndexBuffer1[],Buffer1[],Buffers1[],RSIBuffer1[];
double positive,negative,rel,positive1,negative1,rel1,RSI,RSI1,SRSI,SRSI1;
int PhaseRSI=-100;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
IndicatorBuffers(8);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,RSIBuffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,RSIBuffer1);
SetIndexBuffer(2,IndexBuffer);
SetIndexBuffer(3,IndexBuffer1);
SetIndexBuffer(4,Buffer);
SetIndexBuffer(5,Buffer1);
SetIndexBuffer(6,Buffers);
SetIndexBuffer(7,Buffers1);
IndicatorShortName("dex_RSIndex (Ïåðèîä RSI="+RSIPeriod+" Ñãëàæèâàíèå="+Smooth+")");
SetIndexLabel(0,"Ïåðâàÿ âàëþòà");
SetIndexLabel(1,"Âòîðàÿ âàëþòà");
SetIndexDrawBegin(0,NumberBars);
SetIndexDrawBegin(1,NumberBars);
SetIndexShift (0, Shift);
SetIndexShift (1, Shift);
//----
if (ShowCurrency<0 || ShowCurrency>4 || ShowCurrency1<0 || ShowCurrency1>4)
{ Comment ("Íîìåð âàëþòû äîëæåí áûòü >0 è <5"); return(-1); }
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
double USD, GBP, EUR, CHF, JPY;
double Data1,Data2,Data3,Data4;
int i;
for(i=NumberBars-1;i>=0;i--)
{
Data1=iClose("GBPUSD",0,i);
Data2=iClose("USDCHF",0,i);
Data3=iClose("EURUSD",0,i);
Data4=iClose("USDJPY",0,i);
USD = MathPow((0.036*Data2)*(0.136*Data4)/(0.119*Data1)/(0.576*Data3),0.2);
GBP = Data1 * USD;
EUR = Data3 * USD;
CHF = USD / Data2;
JPY = USD / Data4;
switch (ShowCurrency)
{
case 0: IndexBuffer[i]=USD; break;
case 1: IndexBuffer[i]=GBP; break;
case 2: IndexBuffer[i]=EUR; break;
case 3: IndexBuffer[i]=CHF; break;
case 4: IndexBuffer[i]=JPY; break;
}
switch (ShowCurrency1)
{
case 0: IndexBuffer1[i]=USD; break;
case 1: IndexBuffer1[i]=GBP; break;
case 2: IndexBuffer1[i]=EUR; break;
case 3: IndexBuffer1[i]=CHF; break;
case 4: IndexBuffer1[i]=JPY; break;
}
}
for(i=NumberBars-1;i>=0;i--)
{
Buffer[i]=iRSIOnArray(IndexBuffer,0,RSIPeriod,i);
Buffer1[i]=iRSIOnArray(IndexBuffer1,0,RSIPeriod,i);
}
for(i=NumberBars-1;i>=0;i--)
{
RSIBuffer[i]=iMAOnArray(Buffer,0,Smooth,0,MODE_EMA,i);
RSIBuffer1[i]=iMAOnArray(Buffer1,0,Smooth,0,MODE_EMA,i);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments