Problem in EA using CCFp

 

While experimenting with various versions of the “CCFp” indicator, by Semen Semenich, I tried to incorporate such an indicator in an EA. The problem is that the MT4 strategy tester seems to be using different values than those I see on the chart.  My last attempts were made with “CCFp mtf & alerts 2.03 nmc” (version by Mladen). In my tests both the indicator and the tester use Open prices.
Until now what I have read in similar threads have not solved my problem.
A screenshot demonstrating the differences and the relevant pieces of my code are shown below.
Any ideas?


-----------------------------

Code pieces:

// ...........
// -- Global vars -------
string pair = Symbol();

// the current and previous bar's values of currency1 and currency2
double CURcur1, CURcur2, CURprev1, CURprev2; // CURcur1 represents current value of CURrency1, CURprev2 represents previous value of CURrency2, etc.
// ...........
int start()
  {  
   CurrenciesFromPair();
   Print(Time[0], ", EUR (CURcur1) is ", DoubleToStr(NormalizeDouble(CURcur1,6),6), ", USD (CURcur2)is ", DoubleToStr(NormalizeDouble(CURcur2,6),6));
  // ........
    return(0);
  } 
// ...........
void CurrenciesFromPair()
   {
   string _pair = pair;                               // the name of the pair on chart (i.e. "EURUSD")
   string sub1 = StringSubstr(_pair,0,3);             // the first 3 characters (i.e. "EUR")
   string sub2 = StringSubstr(_pair,3,3);             // the last 3 characters (i.e. "USD")
   
// Use the named indicator below to get the current bar's value of all the pairs
        double USDcur=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",0,0),6);
        double EURcur=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",1,0),6);
        double GBPcur=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",2,0),6);
        double CHFcur=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",3,0),6);
        double JPYcur=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",4,0),6);
        double AUDcur=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",5,0),6);
        double CADcur=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",6,0),6);
        double NZDcur=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",7,0),6);
// Use the named indicator to get the previous bar's value of all the pairs
        double USDprev=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",0,1),6);
        double EURprev=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",1,1),6);
        double GBPprev=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",2,1),6);
        double CHFprev=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",3,1),6);
        double JPYprev=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",4,1),6);
        double AUDprev=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",5,1),6);
        double CADprev=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",6,1),6);
        double NZDprev=NormalizeDouble(iCustom(NULL,0,"CCFp mtf & alerts 2.03 nmc",7,1),6);
                
// Depending on the name of each currency assign to the global variables CURcur1, CURcur2, CURprev1 and CURprev2 the respective values retrieved from above
   if (sub1 == "EUR"){CURcur1 = EURcur; CURprev1 = EURprev;}
   if (sub2 == "EUR"){CURcur2 = EURcur; CURprev2 = EURprev;} 
   if (sub1 == "USD"){CURcur1 = USDcur; CURprev1 = USDprev;}
   if (sub2 == "USD"){CURcur2 = USDcur; CURprev2 = USDprev;}  
   if (sub1 == "GBP"){CURcur1 = GBPcur; CURprev1 = GBPprev;}
   if (sub2 == "GBP"){CURcur2 = GBPcur; CURprev2 = GBPprev;}  
   if (sub1 == "CHF"){CURcur1 = CHFcur; CURprev1 = CHFprev;}
   if (sub2 == "CHF"){CURcur2 = CHFcur; CURprev2 = CHFprev;}  
   if (sub1 == "JPY"){CURcur1 = JPYcur; CURprev1 = JPYprev;}
   if (sub2 == "JPY"){CURcur2 = JPYcur; CURprev2 = JPYprev;}
   if (sub1 == "AUD"){CURcur1 = AUDcur; CURprev1 = AUDprev;}
   if (sub2 == "AUD"){CURcur2 = AUDcur; CURprev2 = AUDprev;}
   if (sub1 == "CAD"){CURcur1 = CADcur; CURprev1 = CADprev;}
   if (sub2 == "CAD"){CURcur2 = CADcur; CURprev2 = CADprev;}
   if (sub1 == "NZD"){CURcur1 = NZDcur; CURprev1 = NZDprev;}
   if (sub2 == "NZD"){CURcur2 = NZDcur; CURprev2 = NZDprev;}
  
   return;
}
 
BBad:

While experimenting with various versions of the “CCFp” indicator, by Semen Semenich, I tried to incorporate such an indicator in an EA. The problem is that the MT4 strategy tester seems to be using different values than those I see on the chart.  My last attempts were made with “CCFp mtf & alerts 2.03 nmc” (version by Mladen). In my tests both the indicator and the tester use Open prices.
Until now what I have read in similar threads have not solved my problem.
A screenshot demonstrating the differences and the relevant pieces of my code are shown below.
Any ideas?


-----------------------------

Code pieces:

Because what you see on chart is value on closed candles, while what you printed and saw in your log is value at open candle (iCustom with shift 0).

 

Alain, thanks for the response.

A) In the indicator I have set the Open price as the default value (Price = 1), which means that the indicator’s calculations will be based on the Open prices of all the necessary bars. The way I understand this is that no matter when the Open price is accessed (be it at the first tick of the new bar, or at any time during its lifespan) the price should be the same.
B) In the tester, as I showed, I call the indicator without any external input, therefore I expect it to use its default values as set by me, including Price = 1 (Open).
C) The indicator you see in my picture was not added manually. It was added automatically by the tester itself. So, I find it very strange that the tester makes its calculations using a certain indicator “version” and then it displays a different “version” on screen.
D) Since the Open price of any bar is the only price which remains unchanged, I expect any indicator which is based on Open prices to return values consistent with those unchanged Open prices, regardless of the bars’ shift. So why does it matter if we are talking about the last bar which is still open (iCustom with shift 0) or any other (closed) bar? The last bar’s Open -as any other bar’s Open- is always known and steady and I guess that the same should be true for any dependent-on-the-Open indicator’s value, including the last and every “last” one. What am I missing here?

If the tester reads, uses and prints other values, what exactly are those other values and at what time are they accessed in regard to the Open of the bar?

I checked other indicators with the same code (for example moving averages, using iMA) and I didn’t notice any differences between the chart and the log. Does this indicator recalculate? Is there something with my use of iCustom that makes the difference?

In case my assumptions are wrong and the problem lies in the way I call the indicator, which exactly is my mistake and how should it be fixed?

 

It would be great to provide problematic sources. AFAICU, there is no mentioned indicator in the codebase (here on mql5.com), and no one can be sure that some versions found on the internet under "CCFp mtf & alerts 2.03 nmc" are exactly the thing which you use.

The original CCFp has bugs. You chose to use more complicated mtf variant which is most likely inherited the bugs of the original and probably introduced new ones. I'd suggest to try some other fixed and non-complicated CCFp version. In the source code I have found by the given name there is no synchronization of bars of different symbols. Maybe something else is wrong, I did not do thorough code review.

 
BBad:

Alain, thanks for the response.

CCFp is a multi-symbols indicator, but it uses current chart bar index.

When you run your EA, on Open Prices only, it calculates the buffer with index of current chart (EURUSD in your case). But is there already a new bar on other symbols ? maybe yes, maybe no.

The indicator opened after the test automatically, is the same as if it was attached manually at the end, it is calculated on history, so when there is bar on EURUSD, there is also a bar on all other symbols.

There is no synchronization by time. I am not even talking about missing bars.

This is even without knowing about this specific code of the version you used and changed, as noted by Stanislav.

 

Stanislav,

Being interested in the relative strength of currencies I have been trying to test (both visually and via the tester) some of the CCxxx indicators I found. The truth is that until now my visual approaches have not been  particularly fruitful and this is why I decided to have an EA optimize various trading conditions and see if it could come up with something useful. It is then that I discovered the problem I reported. As far as mtf indicators are concerned I had never used any of them before, due to to the redrawing issue. Also true is that I did not dwell on the code of any of the CCxxx indicators. But from a first glance the version I mentioned here seemed more polished than the earlier (and simpler) versions I have. Furthermore, previous bugs had in the meanwhile been reported and I expected that they would have been fixed. That is why I used that one in my last tests and in my report here. Anyway, testing with previous versions resulted in similar problems. Then I suspected that even if there are bugs, they must not be solely responsible for the problem I reported. I think you are right about synchronization. Anyway, if you are really interested in the mtf version I used, I can copy the code here. It just didn't cross my mind that there would exist different versions under the exact same name!

Alain,

yes, I realize that -apart from any possible bugs- the synchronization is the main issue. If I understand well (rephrasing what you said) the chart uses the recorded historical prices (Open or any other) regardless of the exact time they occurred, while the tester gives priority to the time stamps and base the EA's calculations only on those prices that were available at the requested specific time intervals. This being the case, I guess that we will probably face the same problem each time we need to base any calculation, trading decision, etc. on prices from multiple pairs. So, in case someone insists to just use historical Open prices for testing, he/she must find a way to synchronize the requested collected prices, probably with some kind of delay(?) and in some cases even omission of bars with asynchronous prices(?)

 
BBad:

Alain,

yes, I realize that -apart from any possible bugs- the synchronization is the main issue. If I understand well (rephrasing what you said) the chart uses the recorded historical prices (Open or any other) regardless of the exact time they occurred, while the tester gives priority to the time stamps and base the EA's calculations only on those prices that were available at the requested specific time intervals. This being the case, I guess that we will probably face the same problem each time we need to base any calculation, trading decision, etc. on prices from multiple pairs. So, in case someone insists to just use historical Open prices for testing, he/she must find a way to synchronize the requested collected prices, probably with some kind of delay(?) and in some cases even omission of bars with asynchronous prices(?)

Exactly.

To demonstrate the issue, you can run the CCFp indicator itself with the strategy tester, run it on a given period. Then place it on a live chart. And compare the charts. The values are different.

Now change the CCFp settings to keep only the currencies of the chart symbol (so EUR and USD on a EURUSD chart). Do the same as above, the values will match.

 

I did it and of course it confirmed what you said. I had not realized this synchronization issue until now. And I think it is a big one!
Your feedback was very useful. Thanks a lot.