Download MetaTrader 5

Indicator for two currency

To add comments, please log in or register
roley
35
roley  

Hi!


I would like to create an indicator which can show two line of two different currency pair in the same time. I've created the two timeseries, adjusted them togehter, but the indicator show only one of them. What can be the problem?



#property copyright "Copyright 2017, Roland Szarka."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
 
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Silver
#property indicator_color1 Red
//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+
  
extern string y = "EURUSD";
extern string x = "GBPUSD";
 
int i;

MqlRates mqlrates_array_y[];
MqlRates mqlrates_array_x[];
datetime date;
int BarShift;
double X_time_series[];
double Y_time_series[];
datetime Time_time_series[];
int arraysize_y;
int arraysize_x;
extern int period=240;


void init()

  {

                  SetIndexStyle(0,DRAW_LINE);
                  SetIndexBuffer(0,X_time_series);
                  SetIndexLabel(0,x);  
                  SetIndexStyle(0,DRAW_LINE);
                  SetIndexBuffer(0,Y_time_series);
                  SetIndexLabel(0,y);  
  }

int start()

  {

//---

   //------- Adjust the two timeseries -------//

  

         arraysize_y=ArrayCopyRates(mqlrates_array_y,y,period);
         arraysize_x=ArrayCopyRates(mqlrates_array_x,x,period);
                  
         ArrayResize(X_time_series,MathMin(arraysize_y, arraysize_x)+1);
         ArrayResize(Y_time_series,MathMin(arraysize_y, arraysize_x)+1);
         ArrayResize(Time_time_series,MathMin(arraysize_y, arraysize_x)+1);           

         //Print(y,"   ",arraysize_y,"   ",x,"  ",arraysize_x);
   

         for(i=MathMin(arraysize_y, arraysize_x)-1; i >= 0; i--)
         {
         date=iTime(y,period,i);
         BarShift=iBarShift(x,period,date);
         X_time_series[i] = mqlrates_array_x[BarShift].close;
         Y_time_series[i] = mqlrates_array_y[i].close;
         Time_time_series[i] = mqlrates_array_y[i].time;   
        
         }
       
   return(0);  
   
   }   
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is developing along with you. Creating EA from custom indicator Hi...
whroeder1
17125
whroeder1  
roley: I've created the two timeseries, adjusted them togehter, but the indicator show only one of them. What can be the problem?

You have?

                  SetIndexStyle(0,DRAW_LINE);
                  SetIndexBuffer(0,X_time_series);
                  SetIndexLabel(0,x);  
                  SetIndexStyle(0,DRAW_LINE);
                  SetIndexBuffer(0,Y_time_series);
                  SetIndexLabel(0,y);  
roley
35
roley  
whroeder1:

You have?

I've changed the code, but still only one of the two line is coming to the chart



#property copyright "Copyright 2017, Roland Szarka."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
 
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Silver
#property indicator_color2 Blue
//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+
  
extern string y = "EURUSD";
extern string x = "GBPUSD";
 
int i;

MqlRates mqlrates_array_y[];
MqlRates mqlrates_array_x[];
datetime date;
int BarShift;
double X_time_series[];
double Y_time_series[];
datetime Time_time_series[];
int arraysize_y;
int arraysize_x;
extern int period=240;


void init()

  {

                  SetIndexStyle(1,DRAW_LINE);
                  SetIndexBuffer(1,X_time_series);
                  SetIndexLabel(1,x);  
                  SetIndexStyle(2,DRAW_LINE);
                  SetIndexBuffer(2,Y_time_series);
                  SetIndexLabel(2,y);  
  }

int start()

  {

//---

   //------- Adjust the two timeseries -------//

  

         arraysize_y=ArrayCopyRates(mqlrates_array_y,y,period);
         arraysize_x=ArrayCopyRates(mqlrates_array_x,x,period);
                  
         ArrayResize(X_time_series,MathMin(arraysize_y, arraysize_x)+1);
         ArrayResize(Y_time_series,MathMin(arraysize_y, arraysize_x)+1);
         ArrayResize(Time_time_series,MathMin(arraysize_y, arraysize_x)+1);           

         //Print(y,"   ",arraysize_y,"   ",x,"  ",arraysize_x);
   

         for(i=MathMin(arraysize_y, arraysize_x)-1; i >= 0; i--)
         {
         date=iTime(y,period,i);
         BarShift=iBarShift(x,period,date);
         X_time_series[i] = mqlrates_array_x[BarShift].close;
         Y_time_series[i] = mqlrates_array_y[i].close;
         Time_time_series[i] = mqlrates_array_y[i].time;   
        
         }
       
   return(0);  
   
   }   
whroeder1
17125
whroeder1  
roley: I've changed the code, but still only one of the two line is coming to the chart
#property indicator_buffers 2

                  SetIndexStyle(1,DRAW_LINE);
                  SetIndexBuffer(1,X_time_series);
                  SetIndexLabel(1,x);  
                  SetIndexStyle(2,DRAW_LINE);...
You didn't check your return codes so you don't see the problem. You declared the indicator has two buffers, therefor they are numbered 0 and 1.
To add comments, please log in or register