Synchronize two charts

 

Hello community!


I have a problem i don't know how to resolve. I'm writing an indicator to display a price chart over an other price chart. So far this was easy i do it this way:


for(int i=0; i<Bars; i++)
   
   {  
 
   PairB = iClose("BRN",PERIOD_H4,i);
   
   
   ExtMapBuffer1[i]=PairB;
 
   }


This is how the chart looks like. The black line is the close price of the regular chart. The red one is the close price of the second chart i plot on the chart.



But here comes my problem. The two charts i wan't to look at are traded on different times. So the first chart is Crude Oil and the second one is Brent Oil. While Brent Oil is not traded between 23:00 and 02:00 Crude Oil is. So when ploting the chart of Brent Oil over the Crude Oil the Brent price is shifted because of this interval from 23:00 to 02:00.

What i would need is a solution to plot the second chart on the first chart only when the hours of both charts coincide. I tried many ways to do this but without result.


Thank you very much for your help.


Regards

 

Step through the CL chart starting with the oldest bar.

Get the time for the bar.

find the Brent bar index for the bar on the Brent chart with the matching time --- use iBarShift()

Use the Brent bar index to request the close price of the Brent bar -- use iClose()

Plot the value

repeat

 

Thank you phy!


Your solution sounds very tricky. ;-) I´ll try it.


Thanks

 
Phy i just finished the indicator. Many thanks for your help!
Reason: