Issue in getting data from iCCI in MQL5 vs MQL4

 

Dears,


first of all let me tell you i'm not new to programming and i wrote many indicators and Experts in MQL4.

but i'm new to MQL5 and i've got some issue in using iCCI or similar basic functions based on written instructions.

i had one script/indicator in MQL4 and i tried to translate it to MQL5 and below you may see some part of it in MQL4 :

   for (i=5;i<=100;i+=5)
   {
     for (j=CandleCount-1;j>=1;j--)
     {
       if (CCICheck)
        {
         ct=iCCI(Symbol(),0,i,PRICE_CLOSE,j);
         cb=iCCI(Symbol(),0,i,PRICE_CLOSE,j+1);

         // some calculations
       }
    }
  }


as you may see i'm using different values as period of CCI

i converted this code like below but it returns some strange values as CCI

   for (i=5;i<=100;i+=5)
   {
     ArrayFree(CCI);
     _cci=iCCI(Symbol(),0,i,PRICE_CLOSE); if (_cci== INVALID_HANDLE) Return (0);
     ArraySetAsSeries(CCI,true);
     CopyBuffer(_cci,0,-10,100,CCI);

     for (j=100;j>=1;j--)
     {
       if (CCICheck)
        {
         ct=CCI[j];
         cb=CCI[j+1];

         // some calculations
       }
    }
  }


in the second code, CCI will return some strange values like 0 and some values with around 20 digits :(

can you please guide me what is the issue in this code?


as the secondary question which is not very important at the moment, how can i let the code understand my code is script in MQL5. it consider the code as Indicator. i used OnCalculate function to have access to Open,Close and ...

 
ArashB:

Dears,


first of all let me tell you i'm not new to programming and i wrote many indicators and Experts in MQL4.

but i'm new to MQL5 and i've got some issue in using iCCI or similar basic functions based on written instructions.

i had one script/indicator in MQL4 and i tried to translate it to MQL5 and below you may see some part of it in MQL4 :


as you may see i'm using different values as period of CCI

i converted this code like below but it returns some strange values as CCI


in the second code, CCI will return some strange values like 0 and some values with around 20 digits :(

can you please guide me what is the issue in this code?


as the secondary question which is not very important at the moment, how can i let the code understand my code is script in MQL5. it consider the code as Indicator. i used OnCalculate function to have access to Open,Close and ...

What is the "-10" part supposed to do in the CopyBuffer() function. No parameter in the copy buffer function can be negative

 

Thanks for your comment.


i changed this parameter and the issue still exist.

Also my expert start on CCI[1] and as this number is related to previous candle it should be fixed.

Still there is an issue exist. my script/indicator export csv file and the export works properly. But when i get 2 exported file, size of file is different which should not.


can you please lead me :

1.what are these huge numbers?

2. if i'm using the iCCI in proper way or it should be different?

3. how this is possible to have different result when run one indicator twice using old data?

 
ArashB:

Thanks for your comment.


i changed this parameter and the issue still exist.

Also my expert start on CCI[1] and as this number is related to previous candle it should be fixed.

Still there is an issue exist. my script/indicator export csv file and the export works properly. But when i get 2 exported file, size of file is different which should not.


can you please lead me :

1.what are these huge numbers?

2. if i'm using the iCCI in proper way or it should be different?

3. how this is possible to have different result when run one indicator twice using old data?

1. Huge number is almost sure EMPTY_VALUE

2. Check here how to use iCCI() https://www.mql5.com/en/docs/indicators/icci


3. That is not an issue of the indicator - it is an issue of your code

Documentation on MQL5: Technical Indicators / iCCI
Documentation on MQL5: Technical Indicators / iCCI
  • www.mql5.com
//|                                                    Demo_iCCI.mq5 | //|                        Copyright 2011, MetaQuotes Software Corp. | //|                                              https://www.mql5.com | "The method of creation of the handle is set through the 'type' parameter (function type...
 

Thanks Again,


1. what might happened which CCI value return EMPTY_VALUE ?

2. i generated this functions based on the same help from MQL5. i can see some correct result and some wrong

3. this is the conversion from MQL4. this means if i had issue the same should happen to MQL4 as well.. but the results are all the same in that language.


if it helps, please let me know to share the whole script with you to check results on your side as well.

finally is there any way to run MQL4 indicator on MT5?

 
ArashB:

Thanks Again,


1. what might happened which CCI value return EMPTY_VALUE ?

2. i generated this functions based on the same help from MQL5. i can see some correct result and some wrong

3. this is the conversion from MQL4. this means if i had issue the same should happen to MQL4 as well.. but the results are all the same in that language.


if it helps, please let me know to share the whole script with you to check results on your side as well.

finally is there any way to run MQL4 indicator on MT5?

3. this is the conversion from MQL4. this means if i had issue the same should happen to MQL4 as well.. but the results are all the same in that language.

Why do you think so?

Please re-read the previous posts - there is no issue with iCCI().

When debugging some code first assumption should always be that the code developed by the coder is the one that is wrong - only when proven beyond the shadow of the doubt that the code is OK, then the stuff like built in functions should be checked. The other way around may seems attractive (as in : "I have found their bug") but happens very rarely, and if that was true, don't you think that somebody else among the thousands and thousands that are using the cci from the code would already have noticed a bug if it was not working on such a basic level?

 

I got you point Mladen and i will start to compare both together again.

As i understand in MQL5, basic functions calculated once and located in memory and but using Copy Buffer we will have them.

the think is as you may see in my code, i'm changing it in a loop and i suspect after recall, i cannot direct it to the right point.


can you please inform me if i used icci in proper way or this is wrong?

 
ArashB:

I got you point Mladen and i will start to compare both together again.

As i understand in MQL5, basic functions calculated once and located in memory and but using Copy Buffer we will have them.

the think is as you may see in my code, i'm changing it in a loop and i suspect after recall, i cannot direct it to the right point.


can you please inform me if i used icci in proper way or this is wrong?

If you use it as described by the help and documentation then all should be OK
 

Last Update :

i compared both files line by line and there is no difference between these except :

1. codes which should be used for CCI in new model

2. some extra lines which i add for debugging purpose

3. one number which i put 2 instead on 1 as close candle.


this indicator run just once and export csv to the files folder. (compile it again to see if file size change)

can you please share the result of running on you computer

Also i attached MQL4 file for comparing if you like

Files:
MQL5.mq5  13 kb
MQL4.mq4  6 kb
 
ArashB:

Last Update :

i compared both files line by line and there is no difference between these except :

1. codes which should be used for CCI in new model

2. some extra lines which i add for debugging purpose

3. one number which i put 2 instead on 1 as close candle.


this indicator run just once and export csv to the files folder. (compile it again to see if file size change)

can you please share the result of running on you computer

Also i attached MQL4 file for comparing if you like

Since I am assuming that the post is meant for me :

The code :

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1

#property indicator_label1  "CCI"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrLimeGreen

input int CCIPeriod = 14;

double _cci[];
int _cciHandle = INVALID_HANDLE; 

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

int OnInit() { SetIndexBuffer(0,_cci  ,INDICATOR_DATA);  return(INIT_SUCCEEDED); }
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 (_cciHandle == INVALID_HANDLE) 
      {_cciHandle = iCCI(_Symbol,0,CCIPeriod,PRICE_CLOSE); if (_cciHandle == INVALID_HANDLE)  return(0); }
                                                   if(BarsCalculated(_cciHandle)<rates_total) return(0); 

   int to_copy; 
      if(prev_calculated>rates_total || prev_calculated<=0) to_copy=rates_total; 
      else 
         { to_copy=rates_total-prev_calculated; to_copy++; } 
   if (CopyBuffer(_cciHandle,0,0,to_copy,_cci)<=0) return(0); 
   return(rates_total); 
}

The result - upper is the executed code from above, lower is the built in cci :


Same built in cci in mt4 :


As I told : there is no issue with iCCI()

 

i know iCCI works as i tried it before.

but did you ever used it in a loop? mostly not.


can you run attached script and let me know the result on your computer please. i need to make sure about result on different pcs. maybe i have issue with my computer or my broker

Reason: