Download MetaTrader 5

Indi Average

To add comments, please log in or register
xanderhinds
108
xanderhinds  

Hi, I'm trying to code part of an EA that return an indicators average reading.. I've one primitive attempt which works and another which does not, can anyone point me in the right direction to get the broken code into some semblance of sense..

 

  
   double MACDAVERAGEPOSITIVE, MACDAVERAGENEGATIVE;
   double MACD1AA,MACD2AA,MACD3AA,MACD4AA,MACD5AA,MACD6AA,MACD1S,MACD2S;
   double MACDA1P,MACDA1N,
          MACDA2P,MACDA2N,
          MACDA3P,MACDA3N,
          MACDA4P,MACDA4N,
          MACDA5P,MACDA5N,
          MACDA6P,MACDA6N;  
          
   MACD1AA = iMACD(NULL,Period(),12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   MACD2AA = iMACD(NULL,Period(),12,26,9,PRICE_CLOSE,MODE_MAIN,2);
   MACD3AA = iMACD(NULL,Period(),12,26,9,PRICE_CLOSE,MODE_MAIN,3);
   MACD4AA = iMACD(NULL,Period(),12,26,9,PRICE_CLOSE,MODE_MAIN,4);
   MACD5AA = iMACD(NULL,Period(),12,26,9,PRICE_CLOSE,MODE_MAIN,5);
   MACD6AA = iMACD(NULL,Period(),12,26,9,PRICE_CLOSE,MODE_MAIN,6);
  
  
      /------------------------------------------------------------------------------------------------------------------------

  
     if (MACD1AA > 0.0)
       {
       (MACDA1P = MACD1AA)
       }
   else
       {
       (MACDA1N = MACD1AA)
       }
    if (MACD2AA > 0.0)
       {
       (MACDA2P = MACD2AA)
       }
   else
       {
       (MACDA2N = MACD2AA)
       }
    if (MACD3AA > 0.0)
       {
       (MACDA3P = MACD3AA)
       }
   else
       {
       (MACDA3N = MACD3AA)
       }
    if (MACD4AA > 0.0)
       {
       (MACDA4P = MACD4AA)
       }
   else
       {
       (MACDA4N = MACD4AA)
       }    
    if (MACD5AA > 0.0)
       {
       (MACDA5P = MACD5AA)
       }
   else
       {
       (MACDA5N = MACD5AA)
       }  
    if (MACD6AA > 0.0)
       {
       (MACDA6P = MACD6AA)
       }
   else
       {
       (MACDA6N = MACD6AA)
       }    
  
          
   MACDAVERAGEPOSITIVE = ((MACDA1P+MACDA2P+MACDA3P+MACDA4P+MACDA5P+MACDA6P)/6)
   MACDAVERAGENEGATIVE = ((MACDA1N+MACDA2N+MACDA3N+MACDA4N+MACDA5N+MACDA6N)/6)

 Obviously very primitive but works..

 

whereas

 

double AO, AOD, AOA[], AOPositiveAverage, AOPA, AONA;
int p,h;

int init();
{
return(0);
}
int deinit()
  {
   return(0);
  }
//----------------------------------------
int start();
{
   AO = iAO(NULL,Period(),1);
AOD = iAO(NULL,Period(),2);
AOA[p] = iAO(NULL,Period(),p);


for(int p = 0; p < 1000; p++)
{
AOA[p] = iAO(NULL,Period(),p);
if(AOA[p] > 0.0)
   {
    for(h=0; h < 1000; h++)
    {
     AOPA[h] = AOA[p];
     return(AOPA[]);
    }
   }
else if (AOA[p] < 0.0)
  {
   for(h=0; h < 1000; h++)
    {
     AONA[h] = AOA[p];
     return(AONA[]);
    }
  }
}

return(0);
}


 is better but I don't know whether an array within an array works, and if so, how?

 

Thanks in advance for any responses! 

honest_knave
Moderator
2342
honest_knave  
double avgPositive=0,
       avgNegative=0;
for(int i=1; i<7; i++)
  {
   double value=iMACD(NULL,Period(),12,26,9,PRICE_CLOSE,MODE_MAIN,i);
   if(value>0) avgPositive+=value;
   else        avgNegative+=value;
  }
avgPositive/=6;
avgNegative/=6;
Uncompiled / untested
xanderhinds
108
xanderhinds  
honest_knave:
double avgPositive=0,
       avgNegative=0;
for(int i=1; i<7; i++)
  {
   double value=iMACD(NULL,Period(),12,26,9,PRICE_CLOSE,MODE_MAIN,i);
   if(value>0) avgPositive+=value;
   else        avgNegative+=value;
  }
avgPositive/=6;
avgNegative/=6;
Uncompiled / untested
Thanks again Honest Knave!
To add comments, please log in or register