price overlay

 

I want to share a tips which displays price overlay of two instruments.

-----------------------------------------------------------------------------------------

Let's say we want to study USDCAD & WTI correlations.

Here is double_chart.mq4 indicator which displays WTI

//+------------------------------------------------------------------+
//|                                                 double_chart.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

//#property indicator_separate_window
#property indicator_chart_window


#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
extern string actif = "WTI";
double         Label1Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
  
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---

   for(int i = 0; i < rates_total; i++){
      Label1Buffer[i] = iClose(actif, NULL, i);
   }
      //--- return value of prev_calculated for next call
   return(rates_total);
  }
  
//+------------------------------------------------------------------+

If we play with these two global scop #property :

#property indicator_separate_window

#property indicator_chart_window

we can have WTI built-in USDCAD chart

-----

Procedure :

 1)Compile double_chart.mq4 in MQL editor with #property like this :

//#property indicator_separate_window
#property indicator_chart_window

2)Then open USDCAD chart and double_chart.mq4 indicator.


3)Return to MQL editor and this time set #proprty  like this :

#property indicator_separate_window
//#property indicator_chart_window

4)Compile it again : we can see  USDCAD and WTI  in the same chart( auto-sized )

priceOverlay

----------------------------------------

How to program  remarks signs (//)  before #property - according to an external varaible

something like "extern bool choice "

if choice = true  indicator will display  in <price overlay> mode.

if choice = false it will display  in <separate window> mode

Thanks

 
How to program  remarks signs (//)  before #property - according to an external varaible

something like "extern bool choice "

if choice = true  indicator will display  in <price overlay> mode.

if choice = false it will display  in <separate window> mode

This is a preprocessor compiler directive. You cannot put a run-time conditional on compiler directives.

You could create (compile) two separate indicators . . . .
 
Anthony Garot:


You could create (compile) two separate indicators . . . .


can u explain

 
paulselvan:


can u explain

Create two different indicators:

1. indicator will display  in <price overlay> mode

2. it will display  in <separate window> mode