another_symbol_ad

Download script
Author: Scriptong
another_symbol_ad

This script is designed for traders who need to monitor a secondary financial instrument (such as a specific currency pair, commodity, or stock) simultaneously while viewing their primary chart. Instead of requiring the user to flip between different tabs or windows, this tool projects the price data of a chosen external symbol directly onto a sub-window of the current chart.

Core Functionality

The script acts as a bridge that fetches real-time pricing from a secondary market and visualizes it as a continuous line. By allowing you to define specific parameters, it creates a multi-instrument viewing experience within a single workspace.

Key Features & Logic:

  • Customizable Symbol Selection: You can specify exactly which asset you want to track (e.g., tracking "EURUSD" while trading "GBPUSD"). If the platform cannot locate the symbol you entered, the script includes an automated safety check that alerts the user and disables itself to prevent errors.
  • Timeframe Independence: The tool allows you to choose a specific timeframe for the secondary symbol. This means you can view high-level trends of a different asset on a daily chart while focusing on the minute-by-minute movements of your primary trade.
  • Price Point Customization: You can decide which price type the indicator should follow (such as the "Close" price) to ensure the visual data aligns with your specific analysis style.
  • Performance Management: To keep the platform running smoothly, the script includes a "Bar Count" limit. This prevents the tool from trying to load an infinite amount of historical data, allowing you to set a maximum range (e.g., the last 10,000 bars) for the display.
  • Smart Recalculation: The logic is optimized to only update when necessary. It identifies new price movements and recalculates the line position dynamically, ensuring that the visual representation stays synchronized with live market ticks without unnecessary processing strain.
  • Multi-Language Support: The script features a built-in communication system that detects your platform's language settings, providing error messages in either English or Russian to ensure the user remains informed if something goes wrong (such as a connection issue or an invalid symbol name).

User Experience

When applied to a chart, the tool creates a separate dedicated window. In this window, a smooth line appears representing the price movement of your chosen secondary asset. It provides a clean, professional way to observe correlations between different markets at a single glance.

Indicators Used
Moving average indicator
Miscellaneous
It issuies visual alerts to the screenImplements a curve of type %1
8 Views
0 Downloads
0 Favorites
another_symbol_ad
//+------------------------------------------------------------------+
//|                                            another_symbol_ad.mq4 |
//|                                        Copyright 2015, Scriptong |
//|                                          http://advancetools.net |
//+------------------------------------------------------------------+
#property copyright "Scriptong"
#property link      "http://advancetools.net"
#property description   "English: Displays the quotes of another symbol/timeframe in subwindow of current chart.\nRussian: Îòîáðàæåíèå êîòèðîâîê äðóãîãî ñèìâîëà/òàéìôðåéìà â ïîäîêíå òåêóùåãî ãðàôèêà."
#property strict

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 clrBlue

#property indicator_width1 1

input    string               i_symbol                   = "EURUSD";                               // Symbol / Ñèìâîë
input    ENUM_TIMEFRAMES      i_tf                       = PERIOD_CURRENT;                         // Timeframe / Ïåðèîä ãðàôèêà
input    ENUM_APPLIED_PRICE   i_priceType                = PRICE_CLOSE;                            // Price / Öåíà
input    int                  i_indBarsCount             = 10000;                                  // Number of bars to display / Êîë-âî áàðîâ îòîáðàæåíèÿ

bool g_activate;

double   g_point,
         g_delta;

#define ERROR_UNKNOWN_SYMBOL                       4301
#define ERROR_SYMBOL_NOT_SELECT                    4302
#define ERROR_SYMBOL_PARAMETER                     4303
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
enum ENUM_MESSAGE_CODE
  {
   MESSAGE_CODE_WRONG_SYMBOL,
   MESSAGE_CODE_TERMINAL_FATAL_ERROR1,
   MESSAGE_CODE_BIND_ERROR
  };

// Ìàññèâû áóôåðîâ íäèêàòîðà
double g_buffer[];
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Custom indicator initialization function                                                                                                                                                          |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
int OnInit()
  {
   g_activate=false;

   if(!TuningParameters())
      return INIT_FAILED;

   if(!BuffersBind())
      return INIT_FAILED;

   g_activate=true;

   return INIT_SUCCEEDED;
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Checking the correctness of values of tuning parameters                                                                                                                                           |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
bool TuningParameters()
  {
   string name=WindowExpertName();

   SymbolInfoDouble(i_symbol,SYMBOL_BID);
   int error = GetLastError();
   if(error >= ERROR_UNKNOWN_SYMBOL && error <= ERROR_SYMBOL_PARAMETER)
     {
      Alert(name,GetStringByMessageCode(MESSAGE_CODE_WRONG_SYMBOL));
      return false;
     }

   g_point = Point;
   g_delta = -g_point / 10;
   if(g_point==0)
     {
      Alert(name,GetStringByMessageCode(MESSAGE_CODE_TERMINAL_FATAL_ERROR1));
      return false;
     }

   return true;
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Custom indicator deinitialization function                                                                                                                                                        |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Binding of array and the indicator buffers                                                                                                                                                        |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
bool BuffersBind()
  {
   string name=WindowExpertName();

// Ñâÿçûâàíèå áóôåðîâ èíäèêàòîðà ñ ìàññèâàìè
   if(!SetIndexBuffer(0,g_buffer))
     {
      Alert(name,GetStringByMessageCode(MESSAGE_CODE_BIND_ERROR),GetLastError());
      return false;
     }

// Çàäàíèå ãðàôè÷åñêîãî òèïà áóôåðîâ
   SetIndexStyle(0,DRAW_LINE);

   SetIndexLabel(0,i_symbol+" price");

   return true;
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Initialize of all indicator buffers                                                                                                                                                               |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void BuffersInitializeAll()
  {
   ArrayInitialize(g_buffer,EMPTY_VALUE);
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Determination of bar index which needed to recalculate                                                                                                                                            |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
int GetRecalcIndex(int &total,const int ratesTotal,const int prevCalculated)
  {
   total=ratesTotal-2;

   if(i_indBarsCount>0 && i_indBarsCount<total)
      total=MathMin(i_indBarsCount,total);

   if(prevCalculated<ratesTotal-1)
     {
      BuffersInitializeAll();
      return total;
     }

   return (MathMin(ratesTotal - prevCalculated, total));
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Calculation of indicators values                                                                                                                                                                  |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void CalcIndicatorData(int limit,int total)
  {
   for(int i=limit; i>=0; i--)
      g_buffer[i]=iMA(i_symbol,i_tf,1,0,MODE_SMA,i_priceType,i);
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Custom indicator iteration function                                                                                                                                                               |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                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[])
  {
   iTime(i_symbol,i_tf,1);
   if(GetLastError()!=ERR_NO_ERROR)
      return prev_calculated;

   int total;
   int limit=GetRecalcIndex(total,rates_total,prev_calculated);

   CalcIndicatorData(limit,total);

   return rates_total;
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Getting string by code of message and terminal language                                                                                                                                           |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
string GetStringByMessageCode(ENUM_MESSAGE_CODE messageCode)
  {
   string language=TerminalInfoString(TERMINAL_LANGUAGE);
   if(language=="Russian")
      return GetRussianMessage(messageCode);

   return GetEnglishMessage(messageCode);
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Getting string by code of message for russian language                                                                                                                                            |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
string GetRussianMessage(ENUM_MESSAGE_CODE messageCode)
  {
   switch(messageCode)
     {
      case MESSAGE_CODE_WRONG_SYMBOL:                      return ": íå óäàåòñÿ íàéòè äàííûå äëÿ óêàçàííîãî ñèìâîëà. Èíäèêàòîð îòêëþ÷åí.";
      case MESSAGE_CODE_TERMINAL_FATAL_ERROR1:             return ": ôàòàëüíàÿ îøèáêà òåðìèíàëà - ïóíêò ðàâåí íóëþ. Èíäèêàòîð îòêëþ÷åí.";
      case MESSAGE_CODE_BIND_ERROR:                        return ": îøèáêà ñâÿçûâàíèÿ ìàññèâîâ ñ áóôåðàìè èíäèêàòîðà. Îøèáêà ¹";
     }

   return "";
  }
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Getting string by code of message for english language                                                                                                                                            |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
string GetEnglishMessage(ENUM_MESSAGE_CODE messageCode)
  {
   switch(messageCode)
     {
      case MESSAGE_CODE_WRONG_SYMBOL:                      return ": unable to find data for specified symbol. The indicator is turned off.";
      case MESSAGE_CODE_TERMINAL_FATAL_ERROR1:             return ": terminal fatal error - point equals to zero. The indicator is turned off.";
      case MESSAGE_CODE_BIND_ERROR:                        return ": error of binding of the arrays and the indicator buffers. Error N";
     }

   return "";
  }
//+------------------------------------------------------------------+

Comments