Download MetaTrader 5

2 symbols in 1 chart

To add comments, please log in or register
nun63
7
nun63 2011.01.25 11:41 

Hi everybody,


I have been trying to write an indi to show 2nd symbol drawing (close prices) in an original window. Could you please take a look what I am doing wrong that the drawing (Symb2DrawBuffer) does not appear?

I wrote several codes in mql4 but it is my first indi in mql5.

Thank you,


#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots   1

//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  DarkOrange
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

//--- input parameters
enum PairSymbols
  {
   USDCHF,
   EURUSD,  
   GBPUSD
  };
 
input PairSymbols SymbName;

//--- indicator buffers
double Symb2DrawBuffer[];  //2nd symbol buffer to be drawn
double Symb2CloseBuffer[]; //added 2nd symbol buffer - close prices
double Symb1CloseBuffer[]; //original symbol buffer - close prices

string Symb;

int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Symb2DrawBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,Symb2CloseBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,Symb1CloseBuffer,INDICATOR_CALCULATIONS);   
  
    // Set beginning of buffer drawing
   PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 1);
  
switch(SymbName)
  {
   case USDCHF:
      Symb = "USDCHF"; break;
   case EURUSD:
      Symb = "EURUSD"; break;
   case GBPUSD:
      Symb = "GBPUSD"; break;      
  }

   // Set indicator name
   IndicatorSetString(INDICATOR_SHORTNAME, Symb + " - " + Symbol());  
  
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int OnCalculate (const int rates_total,      // size of the price[] array
                 const int prev_calculated,  // bars handled on a previous call
                 const int begin,            // where the significant data start from
                 const double& price[]       // array to calculate
   )  
{  
int MaxBars = 500;  

   int copied2 = CopyClose(Symb, 0, 0, MaxBars, Symb2CloseBuffer);
   ArraySetAsSeries(Symb2CloseBuffer, true);

   int copied1 = CopyClose(Symbol(), 0, 0, MaxBars, Symb1CloseBuffer);
   ArraySetAsSeries(Symb1CloseBuffer, true);
 
   int    i, Bar;
   double High_1, Low_1, High_2, Low_2, scale;
     
   Bar = ArrayMaximum(Symb1CloseBuffer, 0, MaxBars);  
   High_1 = Symb1CloseBuffer[Bar];  
   Bar = ArrayMinimum(Symb1CloseBuffer, 0, MaxBars);  
   Low_1 = Symb1CloseBuffer[Bar];  
   Bar = ArrayMaximum(Symb2CloseBuffer, 0, MaxBars);
   High_2 = Symb2CloseBuffer[Bar];  
   Bar = ArrayMinimum(Symb2CloseBuffer, 0, MaxBars);
   Low_2 = Symb2CloseBuffer[Bar];   
  
   scale = (High_1-Low_1)/(High_2-Low_2);
 
   i = MaxBars - 1;
   while(i >= 0)
   {
      Symb2DrawBuffer[i] = (Symb2CloseBuffer[i]  - Low_2) * scale + Low_1;                    
      i--;                         
     }
 
//--- return value of prev_calculated for next call
   return(rates_total);


Files:
Jin
1539
Jin 2011.01.29 08:58  
nun63:

Hi everybody,

I have been trying to write an indi to show 2nd symbol drawing (close prices) in an original window. Could you please take a look what I am doing wrong that the drawing (Symb2DrawBuffer) does not appear?

I wrote several codes in mql4 but it is my first indi in mql5.

Thank you,

 

You have forgotten to put these 3 lines in your code:

int OnInit()
  {
 
  ArraySetAsSeries(Symb2DrawBuffer, true);
  ArraySetAsSeries(Symb2CloseBuffer, true);
  ArraySetAsSeries(Symb1CloseBuffer, true);
 
//--- indicator buffers mapping

 

It should work now. 

 

nun63
7
nun63 2011.01.30 15:19  
Jin:

 

You have forgotten to put these 3 lines in your code:

int OnInit()
  {
 
  ArraySetAsSeries(Symb2DrawBuffer, true);
  ArraySetAsSeries(Symb2CloseBuffer, true);
  ArraySetAsSeries(Symb1CloseBuffer, true);
 
//--- indicator buffers mapping

 

It should work now. 

 

Thanks Jin. It works now!
To add comments, please log in or register