iMAOnArray limitations?

 

Hi,

I have 2 moving averages on an ocillator and i need to get the values (a sort of MA cross of ocillator rather than price) but seem to have a small problem.

Here is the code:


  double AO[];
  ArrayResize(AO, Bars);
  ArraySetAsSeries(AO,true);

  for(int i=Bars; i>=0; i--)
  {
    AO[i]=iAO(NULL, 0, 0);
  }
  double fastma = iMAOnArray(AO,0,1,0,MODE_EMA,0);

  double slowma = iMAOnArray(AO,0,3,0,MODE_EMA,0);


The problem i am seeinf is that both the slowma and fastma values are the same but obviously they are not if i look at the indicators on the chart. if i comment out the fastma then the slowma will report the correct values. Is it not possible to run iMAOnArray twice? I have even doubled the code to run each against its own array but no different.

 
MataNui:

Hi,

I have 2 moving averages on an ocillator and i need to get the values (a sort of MA cross of ocillator rather than price) but seem to have a small problem.

Here is the code:

<SNIP>


The problem i am seeinf is that both the slowma and fastma values are the same but obviously they are not if i look at the indicators on the chart. if i comment out the fastma then the slowma will report the correct values. Is it not possible to run iMAOnArray twice? I have even doubled the code to run each against its own array but no different.

Please edit your post . . . 


Please use this to post code . . . it makes it easier to read.

 

Here this seems to work.

void start(){
  double AO[];
  ArrayResize(AO, Bars);
  ArraySetAsSeries(AO,true);

  for(int i=Bars; i>=0; i--){
    AO[i]=iAO(Symbol(), 0, i);
  }
  double fastma = iMAOnArray(AO,0,1,0,MODE_EMA,0);
  double slowma = iMAOnArray(AO,0,3,0,MODE_EMA,0);
  Print("fastma="+fastma+"___slowma="+slowma);
}
07:58:08 Helping: loaded successfully
07:58:14 Helping test started
07:58:14 2012.01.02 06:01 Helping EURUSD,M1: fastma=-0.00042853___slowma=-0.00042853
07:58:55 Helping EURUSD,M1: loaded successfully
07:58:55 Helping test started
07:58:55 2012.01.02 06:01 Helping EURUSD,M1: fastma=-0.00042853___slowma=-0.00035827
07:59:57 Helping EURUSD,M1: removed
 
ubzen:

Here this seems to work.

07:58:08 Helping: loaded successfully
07:58:14 Helping test started
07:58:14 2012.01.02 06:01 Helping EURUSD,M1: fastma=-0.00042853___slowma=-0.00042853
07:58:55 Helping EURUSD,M1: loaded successfully
07:58:55 Helping test started
07:58:55 2012.01.02 06:01 Helping EURUSD,M1: fastma=-0.00042853___slowma=-0.00035827
07:59:57 Helping EURUSD,M1: removed

 

Thanks. That does seem to have worked. Any idea why in this case Symbol() is needed rather than NULL?
 
  1. Symbol/Null is irrelevant. Yours didn't work because you set all elements of the array to the same value.
    Your code
    His
    for(int i=Bars; i>=0; i--)
      {
        AO[i]=iAO(NULL, 0, 0);
     for(int i=Bars; i>=0; i--){
        AO[i]=iAO(Symbol(), 0, i);

  2. Both loops are wrong. AO only has Bars elements, 0 to Bars-1.  AO[Bars] does not exist.
Reason: