CandleDifference

Download script
Author: Copyright © 2016, Il Anokhin

This script is a custom technical indicator designed for the MetaTrader 5 platform. Its primary purpose is to monitor and display the price movement percentage of multiple currency pairs simultaneously on a single chart window.

Instead of focusing on just one asset, this tool allows you to track several different instruments at once (such as EURUSD, GBPUSD, AUDUSD, etc.) and see how they are performing relative to their opening prices.

Key Functionalities

  • Multi-Pair Monitoring: You can configure the script to watch up to 8 different currency pairs at once. It automatically gathers data for each pair specified in the settings.
  • Percentage Change Calculation: For every currency pair being tracked, the script calculates the percentage difference between the current price and the "Opening Price" of a specific candle (which you can choose via the Signal Bar setting). This allows you to quickly see how much an asset has gained or lost during a specific period.
  • Dynamic Visual Updates: The results are displayed as a text comment directly on your trading chart. As new price data arrives, the script refreshes these values in real-time, providing a live "dashboard" of market movements.
  • Customizable Timeframes: The tool is designed to work across different timeframes. You can choose the specific timeframe (e.g., H1, H4, Daily) that the script should use to determine the opening prices for its calculations.
  • Flexible Labeling: The script includes a built-in system to manage on-screen information. It is designed to handle visual elements like labels intelligently—checking if a piece of information already exists on the screen before creating it, and updating the text or position of existing items to keep the chart clean and organized.

How it works for the user

When you apply this indicator to your chart, it scans the history of all your selected currency pairs. It identifies the price at which those pairs opened on your chosen timeframe and then calculates the "distance" the price has traveled from that point. It presents this data in a simple list format, showing each pair name followed by its current percentage performance (e.g., EURUSD: 0.50%). This makes it an excellent tool for traders who need to keep an eye on a diverse portfolio without having to flip between multiple different windows.

Price Data Components
5 Views
0 Downloads
0 Favorites
CandleDifference
ÿþ//+------------------------------------------------------------------+

//|                                             CandleDifference.mq5 |

//|                                       Copyright 2016, Il Anokhin |

//|                           http://www.mql5.com/en/users/ilanokhin |

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

#property copyright "Copyright © 2016, Il Anokhin"

#property link "http://www.mql5.com/en/users/ilanokhin"

#property description ""

//---- =><5@ 25@A88 8=48:0B>@0

#property version   "1.60"

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

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0                |

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

//---- >B@8A>2:0 8=48:0B>@0 2 3;02=>< >:=5

#property indicator_chart_window 

#property indicator_buffers 0

#property indicator_plots   0

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

//|  1JO2;5=85 :>=AB0=B                           |

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

#define SIZE                8                   // >;8G5AB2> 20;NB=KE ?0@

#define RESET               0                   // >=AB0=B0 4;O 2>72@0B0 B5@<8=0;C :><0=4K =0 ?5@5AG5B 8=48:0B>@0

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

//|  E>4=K5 ?0@0<5B@K 8=48:0B>@0                  |

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

input ENUM_TIMEFRAMES Timeframe=PERIOD_H6;             // "09<D@59< 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0

input string P1 = "EURUSD";                  //Pair 1

input string P2 = "GBPUSD";                  //Pair 2

input string P3 = "AUDUSD";                  //Pair 3

input string P4 = "GBPJPY";                  //Pair 4

input string P5 = "USDCHF";                  //Pair 5

input string P6 = "USDCAD";                  //Pair 6

input string P7 = "USDJPY";                  //Pair 7

input string P8 = "EURJPY";                  //Pair 8

//---- =0AB@>9:8 287C0;L=>3> >B>1@065=8O 8=48:0B>@0

input uint SignalBar=0;                                // ><5@ 10@0 4;O ?>;CG5=8O A83=0;0 (0 - B5:CI89 10@)

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

//---- >1JO2;5=85 F5;>G8A;5==KE ?5@5<5==KE =0G0;0 >BAG5B0 40==KE

int min_rates_total;

//---- >1JO2;5=85 ?5@5<5==KE

double d[SIZE];

string pair[SIZE];

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

//|  >;CG5=85 B09<D@59<0 2 2845 AB@>:8                              |

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

string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)

  {

//----

   return(StringSubstr(EnumToString(timeframe),7,-1));

//----

  }

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

//|  !>740=85 B5:AB>2>9 <5B:8                                        |

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

void CreateTLabel(long   chart_id,         // 845=B8D8:0B>@ 3@0D8:0

                  string name,             // 8<O >1J5:B0

                  int    nwin,             // 8=45:A >:=0

                  ENUM_BASE_CORNER corner, // ?>;>65=85 C3;0 ?@82O7:8

                  ENUM_ANCHOR_POINT point, // ?>;>65=85 B>G:8 ?@82O7:8

                  int    X,                // 48AB0=F8O 2 ?8:A5;OE ?> >A8 X >B C3;0 ?@82O7:8

                  int    Y,                // 48AB0=F8O 2 ?8:A5;OE ?> >A8 Y >B C3;0 ?@82O7:8

                  string text,             // B5:AB

                  string textTT,           // B5:AB 2A?;K20NI59 ?>4A:07:8

                  color  Color,            // F25B B5:AB0

                  string Font,             // H@8DB B5:AB0

                  int    Size)             // @07<5@ H@8DB0

  {

//----

   ObjectCreate(chart_id,name,OBJ_LABEL,0,0,0);

   ObjectSetInteger(chart_id,name,OBJPROP_CORNER,corner);

   ObjectSetInteger(chart_id,name,OBJPROP_ANCHOR,point);

   ObjectSetInteger(chart_id,name,OBJPROP_XDISTANCE,X);

   ObjectSetInteger(chart_id,name,OBJPROP_YDISTANCE,Y);

   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetString(chart_id,name,OBJPROP_FONT,Font);

   ObjectSetInteger(chart_id,name,OBJPROP_FONTSIZE,Size);

   ObjectSetString(chart_id,name,OBJPROP_TOOLTIP,textTT);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,true); //>1J5:B =0 704=5< ?;0=5

//----

  }

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

//|  5@5CAB0=>2:0 B5:AB>2>9 <5B:8                                   |

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

void SetTLabel(long   chart_id,         // 845=B8D8:0B>@ 3@0D8:0

               string name,             // 8<O >1J5:B0

               int    nwin,             // 8=45:A >:=0

               ENUM_BASE_CORNER corner, // ?>;>65=85 C3;0 ?@82O7:8

               ENUM_ANCHOR_POINT point, // ?>;>65=85 B>G:8 ?@82O7:8

               int    X,                // 48AB0=F8O 2 ?8:A5;OE ?> >A8 X >B C3;0 ?@82O7:8

               int    Y,                // 48AB0=F8O 2 ?8:A5;OE ?> >A8 Y >B C3;0 ?@82O7:8

               string text,             // B5:AB

               string textTT,           // B5:AB 2A?;K20NI59 ?>4A:07:8

               color  Color,            // F25B B5:AB0

               string Font,             // H@8DB B5:AB0

               int    Size)             // @07<5@ H@8DB0

  {

//----

   if(ObjectFind(chart_id,name)==-1)

     {

      CreateTLabel(chart_id,name,nwin,corner,point,X,Y,text,textTT,Color,Font,Size);

     }

   else

     {

      ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

      ObjectSetInteger(chart_id,name,OBJPROP_XDISTANCE,X);

      ObjectSetInteger(chart_id,name,OBJPROP_YDISTANCE,Y);

      ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

      ObjectSetInteger(chart_id,name,OBJPROP_FONTSIZE,Size);

     }

//----

  }

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

//| Custom indicator initialization function                         | 

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

void OnInit()

  {

//---- 8=8F80;870F8O ?5@5<5==KE =0G0;0 >BAG5B0 40==KE

   min_rates_total=1+int(SignalBar);



//---- 8=8F80;870F8O ?5@5<5==KE

   pair[0]=P1;

   pair[1]=P2;

   pair[2]=P3;

   pair[3]=P4;

   pair[4]=P5;

   pair[5]=P6;

   pair[6]=P7;

   pair[7]=P8;



//--- A>740=85 8<5=8 4;O >B>1@065=8O 2 >B45;L=>< ?>4>:=5 8 2> 2A?;K20NI59 ?>4A:07:5

   IndicatorSetString(INDICATOR_SHORTNAME,"CandleDifference");

//--- >?@545;5=85 B>G=>AB8 >B>1@065=8O 7=0G5=89 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//---- 7025@H5=85 8=8F80;870F88

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//----

   Comment("");

//----

  }

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

//| Custom indicator iteration function                              | 

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

int OnCalculate(const int rates_total,    // :>;8G5AB2> 8AB>@88 2 10@0E =0 B5:CI5< B8:5

                const int prev_calculated,// :>;8G5AB2> 8AB>@88 2 10@0E =0 ?@54K4CI5< B8:5

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AG5B0

   for(int numb=0; numb<SIZE; numb++) if(Bars(pair[numb],Timeframe)<min_rates_total) return(prev_calculated);

//---- 

   double iOpen[1],iClose[1];

//--- :>?8@C5< 2=>2L ?>O282H85AO 40==K5 2 <0AA82K

   for(int numb=0; numb<SIZE; numb++)

     {

      if(CopyOpen(pair[numb],Timeframe,int(SignalBar),1,iOpen)<=0) return(prev_calculated);

      if(CopyClose(pair[numb],Timeframe,int(SignalBar),1,iClose)<=0) return(prev_calculated);

      d[numb]=(100*iClose[0]/iOpen[0])-100;

     }

//----     

   string data="";

   for(int numb=0; numb<SIZE; numb++) if(pair[numb]!="") data=data+pair[numb]+": "+DoubleToString(d[numb],2)+"%\n";

   Comment(data);

//----     

   return(rates_total);

  }

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

Comments