Multi Currency Indicator issue

 

Hi everyone

A few days ago I added a topic to understand why my indicator repaints . William Roeder said that my main loop is wrong, so I followed his method but still the indicator was repainting.

The reason why I added a new topic was I think now the question is totally different.

So, I removed the codes and started from the scratch to go step by step and see where the problem starts from.

In the indicator I use 2 Symbols, and in the main loop I call the function below to fill an array called PRatio[].

double Price_Ratio(int bar, string _sym_1, string _sym_2)
  {
   double symb_1_NC, symb_2_NC;
   //---
   double symb_1_Curr = iClose(_sym_1, TF, bar);
   double symb_2_Curr = iClose(_sym_2, TF, bar);
   double symb_1_Prev = iClose(_sym_1, TF, bar + 1);
   double symb_2_Prev = iClose(_sym_2, TF, bar + 1);
//---
   symb_1_NC = symb_1_Curr - symb_1_Prev;
   symb_2_NC = symb_2_Curr - symb_2_Prev;
//---
   return symb_1_NC - symb_2_NC; 
  }

I noticed that if I ignore sym_2 and just return symb_1_NC(while the indicator is running on the sym_1 chart), the indicator does not repaint.

I started to compare both symbols charts and figured out that when I call Price_Ratio () and give it an " i " coming from the loop, however it gives me the "i"th bar in both symbols but those bars can have different Times (both in the same time frame"M1"  and of course the same account).

In the live market I saw EURUSD was making M1 bars but GBPUSD didn't make any for 5-6 minutes and then simply added just 1 new bar with the current M1 openTime, means right after a bar on 00:35 made a bar for 00:41



   

I thought about how to solve this problem but couldn't find any comprehensive solution.

My idea was to make an 2D array and collect all the close prices of both symbols but in a correct order in which every dimension has the close price of one of the symbols and both dimensions are belonging to the same time and if any candle is missing in one of the symbols I can put zero or preferably the latest close price, and then  call this array in the main loop.

But, this can not be a good idea because what we will see on the chart plotted by indicator under each bar, does not necessarily belong to the same bar !

This all was problem number 1.

//-----------

//-----------

The other problem is the current bar.

Of course the forming bar should update itself until a new bar appears.

But if symbol_1 bar closes while symbol_2 didn't receive a tick and didn't draw a new bar yet ( and vice versa) indicator buffer will receive a value for bar number one which is not the final value it should have, then I have to also recalculate bar number 1 with each tick and accept one bar repainting, if not the indicator shows a major repainting with each new initialization.






I hope gurus can guide me with some good ideas. 


Regards

Reason: