Multisymbol Indicator problem with syncronization, could you guys please help?

 

Hi friends, I am doing a multisymbol indicator that is already working OK for two symbols that have the SAME market hours. My problem is for multi symbols with different market hours. At first I want just to plot the close price of the second symbol in a separated screen, but later on I want to develop other ideas based on the behavior of the second symbol.

My question is how to make sure that the second symbol close price stays aligned witht the close prices of the main symbol? for example: MAIN symbol starts market hours: 01:00 to 18:00 .. second symbol market hours: 03:00 to 18:00... during the 2 hours that the second symbol does not have prices I would like it to show zero at the separated chart, but I am not able to do it.. would anyone kindly suggest a approach/solution?

//+------------------------------------------------------------------+
//|                                               WDO_na_Tela_v2.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
//#property indicator_maximum 5400
//#property indicator_minimum 5200
#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
double         Label1Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
   
   string papel="WDO$";
   int c=CopyClose(papel,_Period,0,10000,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[])
  {
//---
if ( IsStopped() ) return ( 0 ); //     Must respect the stop flag
//if ( CopyBuffer( SlowHandle, 0, 0, copyBars, BufferSlow ) <= 0 ) return ( 0 );
string papel="BOVA11";


if (CopyClose(papel,_Period,0,rates_total,Label1Buffer) <=0 )  return ( 0 );

//-----------------
   
   
   
//--- return value of prev_calculated for next call
   return(rates_total-1);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
 
I suggest applying iBarShift with true flag to make sure a specific bar exists in history. If not present set it to zero.
 

Hi

You can try and show us your attempt of doing this in your code and we can try to show you where might be a problem. But here I think there might be no easy solution and you just must get the market hours for each symbol and setup the total summary market hours (for all symbols together). Then compare time from each candle with those market hours and if the time is not within the range set the value to 0. If the times within the time range, just make the calculations normally.

You can get trading hour by this function: https://www.mql5.com/en/docs/marketinformation/symbolinfosessiontrade 

Best Regards

Documentation on MQL5: Market Info / SymbolInfoSessionTrade
Documentation on MQL5: Market Info / SymbolInfoSessionTrade
  • www.mql5.com
Allows receiving time of beginning and end of the specified trading sessions for a specified symbol and day of week. Parameters name [in]  ...
 
learn about CopySeries, copy the rates (bars) into a double array and the times into a datetime array
Apply some conditions to check if current data can be retrieved or not