Multi pair CoeffOfLine

Download script
Author: mladen

This script is designed to monitor and visualize market behavior across multiple currency pairs simultaneously within a single, organized window. Rather than looking at standard price charts, it analyzes mathematical relationships between different types of moving averages to identify trends and momentum.

Core Functionality

The tool works by taking several different financial instruments (defined by the user in a list) and calculating two specific "coefficients" for each one. These coefficients are derived from:

  • A Fast Setting: Captures immediate price movement.
  • A Slow Setting: Captures the broader, underlying trend.

By comparing these two values, the script can determine the strength and direction of a trend more effectively than looking at price alone.

Visual Layout and Organization

To keep the interface clean, the script organizes the data as follows:

  • Multi-Pair Display: It automatically processes all pairs listed in your settings (e.g., EURUSD, GBPUSD) and displays them side-by-side in a separate window.
  • Scaling & Equalization: The script includes an "equalize" feature. This ensures that even if one currency pair is much more volatile than another, they appear visually balanced on your screen so you can compare their movements accurately.
  • Dynamic Labeling: Each pair is automatically labeled with its name. If the script detects a specific type of trend reversal (a "signal crossing"), it highlights the text in a distinct color (Gold) to draw your attention.
  • Visual Separators: To prevent the data from blurring together, the script inserts clear physical gaps between the graphs of different currency pairs.

Key Features for the User

  • Automatic Detection: The script is smart enough to recognize "Mini" accounts and adjust the naming conventions automatically based on the symbols provided.
  • Signal Highlighting: It identifies specific crossover points where the fast and slow calculations interact, providing a visual cue for potential momentum shifts.
  • Customizable Inputs: Users can define their own pairs, adjust the look-back periods (Fast and Slow seeds), and choose whether they want the data normalized (equalized) or displayed at its raw scale.

In summary, this tool transforms complex multi-currency trend analysis into a simplified, side-by-side visual dashboard, allowing for a quick "at-a-glance" comparison of market momentum across different assets.

Price Data Components
Series array that contains close prices for each bar
Indicators Used
Moving average indicator
13 Views
0 Downloads
0 Favorites
Multi pair CoeffOfLine
//+------------------------------------------------------------------+
//|                                       Multi pair CoeffOfLine.mq4 |
//|                                                           mladen |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color1  Yellow
#property  indicator_color2  Red
#property  indicator_color3  DimGray
#property  indicator_color4  DimGray
#property  indicator_style3  STYLE_DOT
#property  indicator_style4  STYLE_DOT

//
//
//
//
//

extern int       FastSeed       =  5;
extern int       SlowSeed       = 20;
extern int       barsPerPair    = 70;
extern string    pairs          = "EURUSD;GBPUSD;USDCAD";
extern bool      equalize       = false;
extern string    text           = "color";
extern color     textColor      = Silver;
extern color     backColor      = C'48,48,48';
extern int       separatorWidth = 6;

//
//
//
//
//

double   ind_buffer1[];
double   ind_buffer2[];
double   ind_buffer3[];
double   ind_buffer4[];
double   ind_buffer5[];
double   ind_buffer6[];

//
//
//
//
//

double   minValue;
double   maxValue;

//
//
//
//
//

double   maxValues[];
string   aPairs[];
string   shortName;
int      window;  



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   IndicatorBuffers(6);
   SetIndexBuffer(0,ind_buffer1);
   SetIndexBuffer(1,ind_buffer2);
   SetIndexBuffer(2,ind_buffer3);
   SetIndexBuffer(3,ind_buffer4);
   SetIndexBuffer(4,ind_buffer5);
   SetIndexBuffer(5,ind_buffer6);
      SetIndexLabel(0,"Fast");
      SetIndexLabel(1,"Slow");
      SetIndexLabel(2,NULL);
      SetIndexLabel(3,NULL);
      

   //
   //
   //
   //
   //

      pairs = StringUpperCase(StringTrimLeft(StringTrimRight(pairs)));
      if (StringSubstr(pairs,StringLen(pairs),1) != ";")
                       pairs = StringConcatenate(pairs,";");

         //
         //
         //
         //
         //                                   
            
         int s =  0;
         int i =  StringFind(pairs,";",s);
         string current;
         string temp;
            while (i > 0)
            {
               if (IsMini())
                     current = StringSubstr(pairs,s,i-s)+"m";
               else  current = StringSubstr(pairs,s,i-s);
               if (iClose(current,0,0) > 0)
                  {
                     ArrayResize(aPairs,ArraySize(aPairs)+1);
                                 aPairs[ArraySize(aPairs)-1] = current;
                                 if (current == Symbol())
                                 {
                                       temp      = aPairs[0];
                                       aPairs[0] = current;
                                       aPairs[ArraySize(aPairs)-1] = temp;
                                 }                                       
                  }
                  s = i + 1;
                  i = StringFind(pairs,";",s);
            }
      ArrayResize(maxValues,ArraySize(aPairs));

   //
   //
   //
   //
   //
 
      separatorWidth = MathMax(separatorWidth,4);
      shortName = MakeUniqueName("Multi CoeffOfLine "," ("+FastSeed+","+SlowSeed+")");
      IndicatorShortName(shortName);
 
   //
   //
   //
   //
   //
   
   return(0);
}

int deinit()
{
   for (int i = 0; i < ArraySize(aPairs); i++) { 
         ObjectDelete(shortName+i);
         ObjectDelete(shortName+i+i);
      }         
   return(0);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
{
   int    limit = ArraySize(aPairs);
   int    i,k;
   double max;
   
   //
   //
   //
   //
   //

   window = WindowFind(shortName);  
   ArrayInitialize(maxValues,0);
         minValue = 0;
         maxValue = 0;
                for(i=0,k=0; i<limit; i++) calculateCoeffOfLine(aPairs[i],barsPerPair,k,i);
                for(i=0;     i<limit; i++) if (max < maxValues[i]) max = maxValues[i];
                for(i=0,k=0; i<limit; i++) plotGraph(aPairs[i],barsPerPair,k,i,max);

   //
   //
   //
   //
   //

   for (i=0;i<indicator_buffers;i++) SetIndexDrawBegin(i,Bars-k);
   return(0);
}


//+------------------------------------------------------------------+
//+                                                                  +
//+------------------------------------------------------------------+
//
//
//
//
//

void plotGraph(string symbol,int limit, int& shift,int element, double max)
{
   double koef = 1;
      if (equalize) koef = max/maxValues[element];

   //
   //
   //
   //
   //

   for(int i=0; i<limit; i++) {   
      ind_buffer1[i+shift] = ind_buffer5[i+shift]*koef;
      ind_buffer2[i+shift] = ind_buffer6[i+shift]*koef;
      ind_buffer3[i+shift] =  0.4;
      ind_buffer4[i+shift] = -0.4;
   }

   //
   //
   //
   //
   //

   createLabel(symbol,element,shift+limit+separatorWidth-2,max,isSignalCrossing(shift));
   
   //
   //
   //
   //
   //
   
   shift += (limit+separatorWidth-1);
}

//
//
//
//
//

bool isSignalCrossing(int shift)
{
   double res = (ind_buffer5[shift]   - ind_buffer6[shift])*
                (ind_buffer5[shift+1] - ind_buffer6[shift+1]); 
   return(res<=0);
}

//+------------------------------------------------------------------+
//+                                                                  +
//+------------------------------------------------------------------+
//
//
//
//

void calculateCoeffOfLine(string symbol,int limit,int& shift,int element)
{
   double max;
   int    i;

   //
   //
   //
   //
   //

   for(i=0; i<limit; i++) {
      ind_buffer5[i+shift]=iCoeffOfLine(symbol,0,FastSeed,i);
      ind_buffer6[i+shift]=iCoeffOfLine(symbol,0,SlowSeed,i);
      
      //
      //
      //
      //
      //

      max = MathMax(MathAbs(ind_buffer5[i+shift]),
                    MathAbs(ind_buffer6[i+shift]));
                    if (maxValues[element] < max)
                        maxValues[element] = max;

      //
      //
      //
      //
      //
                              
      max = MathMax(ind_buffer5[i+shift],ind_buffer6[i+shift]);
         if (maxValue < max) maxValue = max;
      max = MathMin(ind_buffer5[i+shift],ind_buffer6[i+shift]);
         if (minValue > max) minValue = max;
   }            

   //
   //
   //
   //
   //

   for (i=0;i<separatorWidth;i++) {
         ind_buffer1[shift+limit+i] = EMPTY_VALUE;
         ind_buffer2[shift+limit+i] = EMPTY_VALUE;
         ind_buffer3[shift+limit+i] = EMPTY_VALUE;
         ind_buffer4[shift+limit+i] = EMPTY_VALUE;
         ind_buffer5[shift+limit+i] = EMPTY_VALUE;
         ind_buffer6[shift+limit+i] = EMPTY_VALUE;
      }         
   shift += (limit+separatorWidth-1);
   return;
}



//+------------------------------------------------------------------+
//+                                                                  +
//+------------------------------------------------------------------+
//
//
//
//
//

void createLabel(string symbol,int element, int shift, double max, bool signalCrossing)
{
   string name = shortName+element;
   double price1;
   double price2;
   
 
 
   //
   //
   //
   //
   //
   
   if (equalize) {
         price1 = MathMax(MathAbs(minValue),MathAbs(maxValue));
         price2 = -price1;
      }
   else {
         price1 = maxValue;
         price2 = minValue;
      }         
   
   //
   //
   //
   //
   //
   
   if (ObjectFind(name) == -1)
      {
         ObjectCreate(name,OBJ_TEXT,window,0,0);
         ObjectSet(name,OBJPROP_ANGLE,90);
         ObjectSetText(name,symbol);
      }
      ObjectSet(name,OBJPROP_TIME1 ,Time[shift]);
      ObjectSet(name,OBJPROP_PRICE1,(price1+price2)/2);
      if (signalCrossing)
           ObjectSet(name,OBJPROP_COLOR,Gold);
      else ObjectSet(name,OBJPROP_COLOR,textColor);

   //
   //
   //
   //
   //

 
   name = shortName+element+element;
   if (ObjectFind(name) == -1)
      {
         ObjectCreate(name,OBJ_RECTANGLE,window,0,0,0,0);
         ObjectSet(name,OBJPROP_COLOR,backColor);
      }         
      ObjectSet(name,OBJPROP_TIME1,Time[shift]);
      ObjectSet(name,OBJPROP_PRICE1,price1);
      ObjectSet(name,OBJPROP_TIME2,Time[shift-(separatorWidth-2)]);
      ObjectSet(name,OBJPROP_PRICE2,price2);
}

//+------------------------------------------------------------------+
//+                                                                  +
//+------------------------------------------------------------------+

double iCoeffOfLine(string symbol,int timeFrame,int period,int shift)
{
	double TIndicatorVar=0;
	double ZIndicatorVar=0;
   double AIndicator;
   double TYVar=0;
	double ZYVar=0;
   double AY;
   double tmp;


   if (symbol == "0") symbol = Symbol();
      for (int i=period; i>0; i--) {
         tmp = iMA(symbol,timeFrame,1,0,MODE_SMA,PRICE_MEDIAN,shift+i-1);
               ZYVar+=tmp*(6-i);
               TYVar+=tmp;
         tmp = iMA(symbol,timeFrame,5,3,MODE_SMMA,PRICE_MEDIAN,shift+i-1);
               ZIndicatorVar+=tmp*(6-i);
               TIndicatorVar+=tmp;
      }
   
   //
   //
   //
   //   
   //
   
         AY=(TYVar+(55-2*ZYVar)*5/15)/15;
         AIndicator=(TIndicatorVar+(55-2*ZIndicatorVar)*5/15)/15;
   return((-1000)*MathLog(AY/AIndicator));	
}


//+------------------------------------------------------------------+
//+                                                                  +
//+------------------------------------------------------------------+
//
//
//
//
//

string StringUpperCase(string str)
{
   string   s = str;
   int      lenght = StringLen(str) - 1;
   int      char;
   
   while(lenght >= 0)
      {
         char = StringGetChar(s, lenght);
         
         //
         //
         //
         //
         //
         
         if((char > 96 && char < 123) || (char > 223 && char < 256))
                  s = StringSetChar(s, lenght, char - 32);
          else 
              if(char > -33 && char < 0)
                  s = StringSetChar(s, lenght, char + 224);
                  
         //
         //
         //
         //
         //
                                 
         lenght--;
   }
   
   //
   //
   //
   //
   //
   
   return(s);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

string MakeUniqueName(string first, string rest)
{
   string result = first+(MathRand()%1001)+rest;

   while (WindowFind(result)> 0)
          result = first+(MathRand()%1001)+rest;
   return(result);
}
bool IsMini()
{
   if (StringFind(Symbol(),"m") > -1)
         return(true);
   else  return(false);    
}

Comments