SumLogSample

Download script
Author: Igore
SumLogSample

This indicator is designed to provide a synthesized "USD Index" by aggregating price movements from four specific major currency pairs: EURUSD, GBPUSD, USDJPY, and AUDUSD. Instead of looking at just one currency, it attempts to capture a broader perspective of the US Dollar's strength or weakness across different global markets simultaneously.

How the Logic Works

1. Data Collection and Normalization The script monitors the closing prices of four different pairs. To ensure that these different currencies can be compared fairly against one another, the logic calculates the "logarithmic return" for each pair at every price candle. By using logarithms, the script measures the percentage-like change in value rather than the raw price, which allows it to combine diverse assets (like the Euro and the Japanese Yen) into a single unified calculation.

2. Dynamic Timeframe Adjustment The tool is designed to be "smart" regarding the chart timeframe you are using. It automatically adjusts its internal look-back period based on your current view:

  • On shorter timeframes (like 15 minutes), it looks at more recent data points.
  • On longer timeframes (like 1 day), it looks at a smaller number of historical points to maintain accuracy and smooth out noise.

3. Moving Average Smoothing To prevent the resulting line from being too erratic or "choppy," the script applies a Simple Moving Average (SMA) to the processed data of each of the four currency pairs. This smoothing technique helps identify the underlying trend of the USD by filtering out minor, momentary price fluctuations.

4. Weighted Synthesis The final "USD Index" value is created by combining the smoothed data from all four pairs into one single line. Each pair contributes to the final result, allowing you to see a composite view of the dollar's performance. The script also includes a "Reverse" feature that allows users to flip the direction of the indicator if they prefer to view the trend in an inverted manner.

Summary for the User

Essentially, this tool acts as a "composite thermometer." Rather than checking four different thermometers to see how hot the room is, it takes the readings from all four, averages them out based on their movement history, and gives you one single line that represents the overall "temperature" of the US Dollar.

Price Data Components
Series array that contains close prices for each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
7 Views
0 Downloads
0 Favorites
SumLogSample
//+------------------------------------------------------------------+
//|                                                 SumLogSample.mq4 |
//|                                                            Igore |
//|                             http://forum.alpari-idc.ru/index.php |
//+------------------------------------------------------------------+
#property copyright "Igore"
#property link      "http://forum.alpari-idc.ru/index.php"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- buffers
extern bool revers=false;
double A1=1,A2=1,A3=1,A4=1;
int N;// ïåðèîä
double IndexBuffer[];
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
int beginBar;
double sign;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  int per=Period();
//---- indicators
   IndicatorBuffers(5);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,IndexBuffer);
   SetIndexBuffer(1,ExtMapBuffer1);
   SetIndexBuffer(2,ExtMapBuffer2);
   SetIndexBuffer(3,ExtMapBuffer3);
   SetIndexBuffer(4,ExtMapBuffer4);
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
   SetIndexEmptyValue(3,0.0);
   SetIndexEmptyValue(4,0.0);
   SetIndexLabel(0,"USD Index");
   IndicatorShortName("Index USD Sample("+N+")");
   switch (per)
      {
      case 15: {N=32; break;}
      case 30: {N=16; break;}
      case 60: {N=24; break;}
      case 240: {N=30; break;}
      case 1440: {N=22;break;}
      default: N=0;
      }
   IndicatorShortName("Index USD Sample("+N+")");
   if (revers) sign=-1; else sign=1;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//---- 
   int i,limit,limit1,Bars1,Bars2,Bars3,Bars4;
   //if (Bars>beginBar)
   if (N==0) 
      {
      Alert("Ñìåíèòå òàéì-ôðåéì");
      return;
      }
   if (counted_bars==0) 
      {
      Bars1=iBars("EURUSD",Period())-1;
      Bars2=iBars("GBPUSD",Period())-1;
      Bars3=iBars("USDJPY",Period())-1;
      Bars4=iBars("AUDUSD",Period())-1;
      beginBar=MathMin(MathMin(Bars1,Bars2),MathMin(Bars3,Bars4));
      limit=MathMin(Bars-1,beginBar);
      limit1=limit-N;
      }
   if (counted_bars>0) 
      {
      limit=Bars-counted_bars;
      limit1=limit;
      }
   if (counted_bars<0) return(-1);
   limit--;
   for (i=limit;i>=0;i--)
      {
      ExtMapBuffer1[i]=-MathLog(iClose("EURUSD",Period(),i)/iClose("EURUSD",Period(),i+1));
      ExtMapBuffer2[i]=-MathLog(iClose("GBPUSD",Period(),i)/iClose("GBPUSD",Period(),i+1));
      ExtMapBuffer3[i]=MathLog(iClose("USDJPY",Period(),i)/iClose("USDJPY",Period(),i+1));
      ExtMapBuffer4[i]=-MathLog(iClose("AUDUSD",Period(),i)/iClose("AUDUSD",Period(),i+1));
      }
   for (i=limit1;i>=0;i--)
      {
      IndexBuffer[i]=sign*(A1*iMAOnArray(ExtMapBuffer1,0,N,0,MODE_SMA,i)+
         A2*iMAOnArray(ExtMapBuffer2,0,N,0,MODE_SMA,i)+
         A3*iMAOnArray(ExtMapBuffer3,0,N,0,MODE_SMA,i)+
         A4*iMAOnArray(ExtMapBuffer4,0,N,0,MODE_SMA,i))*N*1000;
      //if (i==0) Print(IndexBuffer[i]);
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments