Sentiment_Cpair_v2

Download script
Author: OnTheRoad
Sentiment_Cpair_v2

Overview of Logic

This script is designed to help traders visualize market "sentiment" by analyzing the underlying strength and relationship between different currencies and assets (such as Gold) in a single, easy-to-read window. Instead of looking at dozens of separate charts to see which currencies are leading the market, this tool consolidates that information into a comparative view.

How it Works

1. Currency Identification & Mapping The script contains a built-in library of major and minor currency pairs (e.g., EURUSD, USDJPY, GBPCHF) as well as Gold. When you apply this to a specific chart, the script automatically identifies which two "base" components make up that pair. For example, if you are viewing a EURUSD chart, it recognizes the individual sentiment values for both the Euro and the US Dollar.

2. Sentiment Data Extraction The core logic relies on pulling data from a secondary analysis tool (a specialized sentiment indicator). It calculates a specific "sentiment score" for each individual currency involved in the pair. It treats every currency as an independent entity, determining whether it is currently gaining or losing strength relative to the broader market.

3. Comparative Analysis (The Delta) The script performs three main visual calculations:

  • Component A: Displays the sentiment strength of the first currency in the pair (e.g., the Euro).
  • Component B: Displays the sentiment strength of the second currency in the pair (e.g., the US Dollar).
  • The Delta (Difference): The script calculates the mathematical difference between these two scores. This "Delta" represents the net momentum of the specific trading pair, showing you the gap between how the two currencies are performing against each other.

4. Visual Representation Rather than just giving you raw numbers, the script provides a clear visual interface:

  • Color-Coded Lines: Each currency is assigned a unique color, making it easy to distinguish between different assets at a glance.
  • Dynamic Labeling: It automatically places text labels on your screen to identify which line belongs to which currency (e.g., showing "EUR" and "USD" clearly next to their respective lines).
  • Baseline Reference: It uses a zero-line as a midpoint, allowing you to quickly see if the sentiment for a currency is currently positive (above the line) or negative (below the line).

Summary for the Trader

Essentially, this script acts as a "X-ray" for currency pairs. Instead of just seeing that EURUSD is going up, it shows you why—it reveals whether the Euro is getting stronger, the Dollar is getting weaker, or both are moving in tandem. It simplifies complex market movements into a clean, comparative sentiment map.

Miscellaneous
Implements a curve of type %1
5 Views
0 Downloads
0 Favorites
Sentiment_Cpair_v2
//+------------------------------------------------------------------+
//|                        Sentiment_Cpair_alp_x_Flt_GJEJ_DeltaV.mq4 |
//+------------------------------------------------------------------+

#property copyright "OnTheRoad"
#property link      "ontheroad7069@yahoo.com"



#define  MAX_CPAIRS  29
#define  MAX_SPAIRS  9

#define  EUR   0
#define  USD   1
#define  JPY   2
#define  GBP   3
#define  CAD   4
#define  CHF   5
#define  AUD   6
#define  NZD   7

#define  GOLD  8

#property indicator_separate_window
#property indicator_buffers 3

#property indicator_color1 DimGray
#property indicator_color2 SteelBlue
#property indicator_color3 Gainsboro

#property indicator_level1 0
#property indicator_levelcolor   Silver
#property indicator_levelwidth   1
#property indicator_levelstyle   STYLE_DOT

static    color   CNcolor[]={
         Red,
         DarkViolet,
         Chocolate,
         Green,
         DodgerBlue,
         Aqua,
         Chartreuse,
         Gold
         } ;

static    color   colort = Gainsboro;

static   string   CName[]={
         "EUR",
         "USD",
         "JPY",
         "GBP",
         "CAD",
         "CHF",
         "AUD",
         "NZD",
         "GOLD"};
         
//---- input parameters

extern int       MA_Per=12;
extern int       Flt_Per=3;
extern int       Candle_Back=1;
extern int       History=144;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

static int    Pairsel1 , Pairsel2;

static string CPair , sname ;

static string indic_name = "Sentiment_all_v2";

static string symbols[MAX_CPAIRS]={

   "EURUSD",
   "USDJPY",
   "GBPUSD",
   "USDCAD",
   "USDCHF",
   "AUDUSD",
   "NZDUSD",
   
   "EURJPY",
   "EURGBP",
   "EURCAD",
   "EURCHF",
   "EURAUD",
   "EURNZD",
   
   "GBPJPY",
   "CADJPY",
   "CHFJPY",
   "AUDJPY",
   "NZDJPY",
   
   "GBPCAD",
   "GBPCHF",
   "GBPAUD",
   "GBPNZD",
   
   "CADCHF",
   "AUDCAD",
   "NZDCAD",
   
   "AUDCHF",
   "NZDCHF",
   
   "AUDNZD" 

   "GOLD",

   };

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

   for( int i=0 ; i<MAX_CPAIRS ; i++ )
      {
      if ( Symbol() == symbols[i] )
       {
       switch (i)
         {
         case  0:       //EURUSD
            Pairsel1 = EUR;
            Pairsel2 = USD;
            break;

         case  1:       //USDJPY
            Pairsel1 = USD;
            Pairsel2 = JPY;
            break;

         case  2:       //GBPUSD
            Pairsel1 = GBP;
            Pairsel2 = USD;
            break;

         case  3:       //USDCAD
            Pairsel1 = USD;
            Pairsel2 = CAD;
            break;

         case  4:       //USDCHF
            Pairsel1 = USD;
            Pairsel2 = CHF;
            break;

         case  5:       //AUDUSD
            Pairsel1 = AUD;
            Pairsel2 = USD;
            break;

         case  6:       //NZDUSD
            Pairsel1 = NZD;
            Pairsel2 = USD;
            break;

         case  7:       //EURJPY
            Pairsel1 = EUR;
            Pairsel2 = JPY;
            break;

         case  8:       //EURGBP
            Pairsel1 = EUR;
            Pairsel2 = GBP;
            break;

         case  9:       //EURCAD
            Pairsel1 = EUR;
            Pairsel2 = CAD;
            break;

         case  10:       //EURCHF
            Pairsel1 = EUR;
            Pairsel2 = CHF;
            break;

         case  11:       //EURAUD
            Pairsel1 = EUR;
            Pairsel2 = AUD;
            break;

         case  12:       //EURNZD
            Pairsel1 = EUR;
            Pairsel2 = NZD;
            break;

         case  13:       //GBPJPY
            Pairsel1 = GBP;
            Pairsel2 = JPY;
            break;

         case  14:       //CADJPY
            Pairsel1 = CAD;
            Pairsel2 = JPY;
            break;

         case  15:       //CHFJPY
            Pairsel1 = CHF;
            Pairsel2 = JPY;
            break;

         case  16:       //AUDJPY
            Pairsel1 = AUD;
            Pairsel2 = JPY;
            break;

         case  17:       //NZDJPY
            Pairsel1 = NZD;
            Pairsel2 = JPY;
            break;

         case  18:       //GBPCAD
            Pairsel1 = GBP;
            Pairsel2 = CAD;
            break;

         case  19:       //GBPCHF
            Pairsel1 = GBP;
            Pairsel2 = CHF;
            break;

         case  20:       //GBPAUD
            Pairsel1 = GBP;
            Pairsel2 = AUD;
            break;

         case  21:       //GBPNZD
            Pairsel1 = GBP;
            Pairsel2 = NZD;
            break;

         case  22:       //CADCHF
            Pairsel1 = CAD;
            Pairsel2 = CHF;
            break;

         case  23:       //AUDCAD
            Pairsel1 = AUD;
            Pairsel2 = CAD;
            break;

         case  24:       //NZDCAD
            Pairsel1 = NZD;
            Pairsel2 = CAD;
            break;

         case  25:       //AUDCHF
            Pairsel1 = AUD;
            Pairsel2 = CHF;
            break;

         case  26:       //NZDCHF
            Pairsel1 = NZD;
            Pairsel2 = CHF;
            break;

         case  27:       //AUDNZD
            Pairsel1 = AUD;
            Pairsel2 = NZD;
            break;

         case  28:       //GOLD
            Pairsel1 = GOLD;
            Pairsel2 = USD;
            break;

         }
       CPair = symbols[i] ;
       sname = "SA_CPair_V2_"+symbols[i] ;
       }
     }

   sname = sname + "_" + MA_Per + "_" + Flt_Per + "_" + Candle_Back;

//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,CNcolor[Pairsel1]);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,CNcolor[Pairsel2]);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2,colort);
   SetIndexBuffer(2,ExtMapBuffer3);
   
   SetLevelValue( 0, 0 ) ;
   SetLevelStyle( STYLE_DOT , 1 , Silver ) ;
   
//----

   IndicatorShortName(sname);
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i , j , limit , counted_bars ;

   
   counted_bars = IndicatorCounted() ;

   if(counted_bars<0) return(-1);
   
   if(counted_bars>0) counted_bars--;


   limit = Bars-counted_bars;
   if ( limit > History ) limit = History;
   
   //return;
   
   if ( limit <= 0 ) return(0);
   
   Comment ( " RefreshRates( )...." );
   RefreshRates( );

   if ( MA_Per < 1 ) MA_Per = 1 ;
   if ( Flt_Per < 1 ) Flt_Per = 0 ; 
   if ( Candle_Back < 1 ) Candle_Back = 0;


   for ( i = limit ; i >= 0 ; i -- ) 
      {
      ExtMapBuffer1[i]=0;
      ExtMapBuffer2[i]=0;
      ExtMapBuffer3[i]=0;
      }


   for ( i = limit ; i >= 0 ; i -- ) 
      {
      ExtMapBuffer1[i]= iCustom(NULL,0,indic_name,MA_Per,Flt_Per,Candle_Back,History,Pairsel1,i);
      ExtMapBuffer2[i]= iCustom(NULL,0,indic_name,MA_Per,Flt_Per,Candle_Back,History,Pairsel2,i);
      ExtMapBuffer3[i]=ExtMapBuffer1[i]-ExtMapBuffer2[i];
      }
   

        ObjectCreate( CPair , OBJ_LABEL, WindowFind(sname), 0, 0);
        ObjectSetText(CPair,CPair,12, "Arial Bold");
        ObjectSet(CPair, OBJPROP_COLOR, colort);
        ObjectSet(CPair, OBJPROP_CORNER, 0);
        ObjectSet(CPair, OBJPROP_XDISTANCE, 270);
        ObjectSet(CPair, OBJPROP_YDISTANCE, 3);
        
        ObjectCreate(CName[Pairsel1], OBJ_LABEL, WindowFind(sname), 0, 0);
        ObjectSetText(CName[Pairsel1],CName[Pairsel1],12, "Arial Bold");
        ObjectSet(CName[Pairsel1], OBJPROP_COLOR, CNcolor[Pairsel1]);
        ObjectSet(CName[Pairsel1], OBJPROP_CORNER, 0);
        ObjectSet(CName[Pairsel1], OBJPROP_XDISTANCE, 350);
        ObjectSet(CName[Pairsel1], OBJPROP_YDISTANCE, 3);

        ObjectCreate(CName[Pairsel2], OBJ_LABEL, WindowFind(sname), 0, 0);
        ObjectSetText(CName[Pairsel2],CName[Pairsel2],12, "Arial Bold");
        ObjectSet(CName[Pairsel2], OBJPROP_COLOR, CNcolor[Pairsel2]);
        ObjectSet(CName[Pairsel2], OBJPROP_CORNER, 0);
        ObjectSet(CName[Pairsel2], OBJPROP_XDISTANCE, 390);
        ObjectSet(CName[Pairsel2], OBJPROP_YDISTANCE, 3);
        
   
//----
   return(0);
  }
//+------------------------------------------------------------------+


Comments