CiAC howto use

 

here is my code. it doesn't work.

 

//+------------------------------------------------------------------+
//|                                                         test.mq5 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+


int OnInit()
  {
//---
   
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
if(isNewbBar())
   {  
      CiAC* iac = new CiAC();
      iac.Create(Symbol(),PERIOD_M1);
     // iac.Refresh(10);
     iac.Refresh(0);
      double a = iac.Main(0);
      Print(a);
      delete(iac);
      }
   
  }
//+------------------------------------------------------------------+
bool isNewbBar()
{
   static datetime t;
   datetime time[1];
   CopyTime(Symbol(),PERIOD_M1,1,1,time);
   if(time[0]>t)
   {
      t = time[0];
      return true;
   }
   else
   {
      return false;
   }
}
 
flourishing:

here is my code. it doesn't work.

 

 

Use dynamic array for the time variable.Next you need to use zero for the start_pos;Then useing not equal operator is better than the greater operator.Also I use ArrayFree(time) at the end of fuctions.

datetime time[]; 
CopyTime(Symbol(),PERIOD_M1,0,1,time);
if(time[0]!=t)
   {
      t = time[0];
      return true;
   }
   else
   {
      return false;
   }
 
Documentation on MQL5: Array Functions / ArrayFree
Documentation on MQL5: Array Functions / ArrayFree
  • www.mql5.com
Array Functions / ArrayFree - Documentation on MQL5
 
brazandeh:

Use dynamic array for the time variable.Next you need to use zero for the start_pos;Then useing not equal operator is better than the greater operator.Also I use ArrayFree(time) at the end of fuctions.

the problem is not the function   isNewbar.

 the problem is how to use  the Class  CiAC.  it prints the values like these:

 

 

see , every miniutes it prints a iac value , but the value is wrong. 

 

 
flourishing:

the problem is not the function   isNewbar.

 the problem is how to use  the Class  CiAC.  it prints the values like these:

 

 

see , every miniutes it prints a iac value , but the value is wrong. 

 

I am pretty sure the problematic part of your code is isNewbBar .the function doesn't work properly ,so the indicator value seems to show the same value constantly.Do change the function as I've constructed.If it didn't work,we would work on the indicator side.
 
brazandeh:
I am pretty sure the problematic part of your code is isNewbBar .the function doesn't work properly ,so the indicator value seems to show the same value constantly.Do change the function as I've constructed.If it didn't work,we would work on the indicator side.

No. it's not the function problem.

in mql5 reference.

the documentation about copytime  says:

When copying the yet unknown amount of data, it is recommended to use dynamic array as a target array, because if the requested data count is less (or more) than the length of the target array, function tries to reallocate the memory so that the requested data fit entirely.

If you know the amount of data you need to copy, it should better be done to a statically allocated buffer, in order to prevent the allocation of excessive memory.

 

so my function is not the problem.

plus, i have tried replaced the code with yours. doesn't work too.  i believe that the problem is  how to use class  CiAC.

 Thanks anyway. 

Reason: