Standard indicators override?! - page 2

 
Roche(s) is right. I just wanted to write about it, but he beat me to it (as always). But. My indicator has nothing to do with it, it has another problem. It is drawn differently on different currency pairs (and the data is always taken from USDCHF and always at the beginning of the bar, at 00 minutes), in real time. The bar number is always 1. So, there is a bug. Yes, there is. And until it is fixed, you cannot test and use such things without risk.

In fact, my indicator can be further simplified. We simply create in a separate window Open[0] for USDCHF and connect this indicator to EURUSD and AUDUSD. After some time (on the hourly chart - a few hours) divergence will start to appear.
 
Roche(s) is right. I just wanted to write about it, but he beat me to it (as always). But. My indicator has nothing to do with it, it has another problem. It is drawn differently on different currency pairs (and the data is always taken from USDCHF and always at the beginning of the bar, at 00 minutes), in real time. The bar number is always 1. So, there is a bug. Yes, there is. And until it is fixed, we cannot test and use such things without risk. <br / translate="no">.
In fact, my indicator can be further simplified. We simply create in a separate window Open[0] for USDCHF and connect this indicator to EURUSD and AUDUSD. After some time (on the hourly chart - a few hours) divergences will start to appear.


Just looking at your creation :) Your style has not changed, you write clearly... for yourself :)
 
Quark's version, reworked:
//+------------------------------------------------------------------+
//|                                                     QuarkBug.mq4 |
//|                                                            Quark |
//|                             http://www.metaquotes.ru/forum/7790/ |
//+------------------------------------------------------------------+
#property copyright "Quark"
#property link      "http://www.metaquotes.ru/forum/7790/"


#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Aqua
#property indicator_color3 Red


// indicator parameters
extern int nPeriod = 6;

double arrOpen[];
double arrMa[];
double arrMyMa[];

int nExtCountedBars = 0;

double dUsdChf, dUsdChfPrev;

////////////////////////
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
	string strIndicatorShortName = "Test(" + Symbol() + " " + nPeriod + ")";  
	IndicatorShortName(strIndicatorShortName);

	// drawing settings
	SetIndexStyle(0, DRAW_LINE);
	SetIndexBuffer(0,arrOpen);
	SetIndexLabel(0,"arrOpen");

	SetIndexStyle(1, DRAW_LINE);
	SetIndexBuffer(1,arrMa);
	SetIndexLabel(1,"arrMa");

	SetIndexStyle(2, DRAW_LINE);
	SetIndexBuffer(2,arrMyMa);
	SetIndexLabel(2, "arrMyMa");

	IndicatorDigits(MarketInfo("USDCHF",MODE_DIGITS));		
	// indicator buffers mapping
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
	if(Bars <= nPeriod) 
		return(0);
		
	nExtCountedBars = IndicatorCounted();
	if(nExtCountedBars < 0)		return(-1);

	int nPos = Bars - nExtCountedBars - 1;
	double dPr = 2.0 / (nPeriod + 1.0);
	
	while(nPos > 0)
      {
		dUsdChf = iMA("USDCHF", 0, nPeriod, 0, MODE_EMA, PRICE_OPEN, nPos - 1);
		dUsdChfPrev = iMA("USDCHF", 0, nPeriod, 0, MODE_EMA, PRICE_OPEN, nPos);

		arrOpen[nPos - 1] = iOpen("USDCHF", 0, nPos - 1);
		arrMa[nPos - 1] = dUsdChf;

		arrMyMa[nPos - 1] = arrOpen[nPos - 1] * dPr + 
				arrMyMa[nPos] * (1 - dPr);

		nPos--;
		if (nPos<2) Print("nPos=",nPos);
   	}

   
//----
   return(0);
  }
//+------------------------------------------------------------------+


 
There's a little bit more to it than that :)
I have two pairs - GBPUSD M5 and GBPJPY M5. Then I realized - Quark, as an experienced user, has hidden the error deeper :) I checked equation of the exponential moving average - it is correct. BUT... the code assumes, that if a new bar opens on GBPJPY (where the indicator is hovering), then a new bar will open on USDCHF (where Open[] is read from).
Is it really so? That's why the error appears gradually, in several days, because the differences need time to accumulate. I think I have explained everything clearly ?
 
And here is the visual result

 
The version with three graphs is even clearer

 
Rosh, my hat is off to you. And, as promised, I apologise. Especially to the developers.
As the saying goes: "I got angry, I was wrong, I take it all back". ;о)
Really blame the "holes" in the story. It is interesting, by the way, that I have only one "hole" from your example - 25.12.2001. But 14.03.2005 all bars are present.
I am still guessing, where 8 hours of quotes have disappeared, but that`s another story.
In any case, thanks a lot for the help. :о)
 
The problem is a little bit different here :)<br / translate="no"> I have two pairs - GBPUSD M5 and GBPJPY M5. Then I realized - Quark, as an experienced user, has hidden the error deeper :) I checked equation of the exponential moving average - it is correct. BUT... the code assumes, that if a new bar opens on GBPJPY (where the indicator is hovering), then a new bar will open on USDCHF (where Open[] is read from).
Is it really so? That's why the error appears gradually, in several days, because the differences need time to accumulate. I think I have explained everything clearly ?


My style is... I don't know. I wanted to do better. What's wrong with it? Criticism accepted. Constructive :)
Here is a new variant, without MA at all. It draws iOpen(USDCHF) and iClose.

Now about the error accumulation due to different bar open time. Formally, Open[0] is the same no matter what (it is formed at hh:00). But in practice, what if a bar on our chart has already arrived (first tick, that is), and the USDCHF (indicator currency) has not yet? Um... One would think that a properly constructed code would ask the server, but if that's not done, then yes, either the value of the previous (hour ago) Open (very wrong!!!) or the last tick value will be used (which is also not good). So maybe Roche is right.

However, there will be no error accumulation with this (it's not like we're building MAs, we're just drawing open prices).

To investigate the issue, I've put a new indicator on two charts that also draws iClose.

Let me note that even in this case, there may be divergences. For example, if last tick in one of currencies is VERY delayed, and Open on the chart comes earlier than Close on indicator's currency.

To investigate this issue, I have added a third buffer to the indicator drawing the Open of the previous bar. I think everyone will agree that these data will ALWAYS be synchronized on the watch. It's hard to imagine that one currency has Open[0], and the other hasn't Open[1] yet.

#property copyright "Copyright Quark"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Aqua

// indicator parameters
extern int nPeriod = 6;

double arrOpen[];
double arrClose1[];
double arrOpen1[];

int nExtCountedBars = 0;

////////////////////////
int init()
{
	string strIndicatorShortName = "Test(" + Symbol() + " " + nPeriod + ")";  
	IndicatorShortName(strIndicatorShortName);

	// drawing settings
	SetIndexStyle(0, DRAW_LINE);
	SetIndexShift(0, 0);

	SetIndexStyle(1, DRAW_LINE);
	SetIndexShift(1, 0);

	SetIndexStyle(2, DRAW_LINE);
	SetIndexShift(2, 0);

	IndicatorDigits(4);
		
	// indicator buffers mapping
	SetIndexBuffer(0, arrOpen);
	SetIndexBuffer(1, arrClose1);
	SetIndexBuffer(2, arrOpen1);	
		
	return(0);
}
///////////////////////////
int start()
{
	if(Bars <= nPeriod) 
		return(0);
		
	nExtCountedBars = IndicatorCounted();
	if(nExtCountedBars < 0) 
		return(-1);

	int nPos = Bars - nExtCountedBars - 1;

	while(nPos > 0)
	{
		arrOpen[nPos - 1] = iOpen("USDCHF", 0, nPos - 1);
		arrClose1[nPos - 1] = iClose("USDCHF", 0, nPos);
		arrOpen1[nPos - 1] = iOpen("USDCHF", 0, nPos);		

		nPos--;
	}

	return(0);
}



If the reasoning above is correct, then it turns out that we should be very careful when using data from another currency. It would be good if the developers would write (in a helper, or wherever) some kind of recommendation.

I'll post in about 12 hours what came out of the test.

 
Quark, you didn't hear me.
 
<br / translate="no"> Quark, you didn't hear me.


I don't get it, explain.
Reason: