All avereges_v2.5 within the shell code EA

Post Reply
User avatar
Carioca
Trader
Posts: 49
Joined: Sat Jun 09, 2012 12:12 am

All avereges_v2.5 within the shell code EA

Post by Carioca »

Sorry for the english

As I would put the code of the indicator AllAverages_v2.5, in a shell EA code, without having to to use iCustom as slope.

I tried more without success so far

thanks
You do not have the required permissions to view the files attached to this post.
User avatar
Carioca
Trader
Posts: 49
Joined: Sat Jun 09, 2012 12:12 am

Re: All avereges_v2.5 within the shell code EA

Post by Carioca »

someone help

I think it would be something like this in the EA code.

More logical example that does not work.

Code: Select all

// MA_Method=8: HMA - Hull Moving Average by Alan Hull
double HMA(double array[],int per,int bar)
{
   double tmp[];
   int len =  MathSqrt(per);
   ArrayResize(tmp,len);
   
   if(bar == per) double hma = array[bar]; 
   else
   if(bar > per)
   {
   for(int i = 0; i < len;i++) tmp[len-i-1] = 2*LWMA(array,per/2,bar-i) - LWMA(array,per,bar-i);  
   hma = LWMA(tmp,len,len-1); 
   }  
 
   return(hma);
}

HMA = HMA (????, 14, 1);
HMAPREV = HMA (????, 14, 2);

if (HMA> HMAPREV) SendLong = false;

if (HMA <HMAPREV) SendShort = false;
User avatar
Carioca
Trader
Posts: 49
Joined: Sat Jun 09, 2012 12:12 am

Re: All avereges_v2.5 within the shell code EA

Post by Carioca »

Does there exist one, very generous programmer that can help me?
garyfritz

Re: All avereges_v2.5 within the shell code EA

Post by garyfritz »

Carioca, it looks like you just pass it the array that you want to smooth. So for example say you copy the last 100 bars' Close value to myClose[]: (this is untested but it should be close)

Code: Select all

for (idx = 0; idx < 100; idx++) {
  bar = 100 - idx - 1;
  myClose[idx] = Close[bar];
  myHMA[idx] = HMA(myClose, 14, idx);
}
Then the HMA for bar N is myHMA[100-bar-1]. HMA for the current bar (bar 0) is myHMA[99], HMA for bar 99 (100 bars ago) is myHMA[0].

Notice that myClose[] and myHMT[] are REVERSED from the "normal" Close/etc order -- myClose[0] is 100 bars ago, myClose[99] is the newest (current) bar. The AllAverages functions don't operate on "normal" (0 is the current bar) array orders.

That's confusing if you're used to thinking of "0 is the current bar" logic. But that's the way arrays usually work. It has the advantage that the index for a particular candle never changes. With "normal" Empty4 behavior, 0 is the newest, and when a new candle arrives the candle that used to be 0 is now 1, etc. But with the "reversed" array order, myClose[99] still refers to the same candle. You just have to ArrayResize() myClose[] and myHMA[] when a new candle arrives, so you've got a spot to stick the new candle's data.

Gary
User avatar
Carioca
Trader
Posts: 49
Joined: Sat Jun 09, 2012 12:12 am

Re: All avereges_v2.5 within the shell code EA

Post by Carioca »

Thanks Gary by answering me.

I tried the more I'm a lousy also coder, what I did wrong he returned the value 0.

Code: Select all

void DisplayUserFeedback()
{
   SM("SMA "  + myHMA[idx]  + NL);

...

// MA_Method=0: SMA - Simple Moving Average
double SMA(double array[],int per,int bar)
{
   double Sum = 0;
   for(int i = 0;i < per;i++) Sum += array[bar-i];
   
   return(Sum/per);
}         

void ReadIndicatorValues()
{	

for (idx = 0; idx < 100; idx++) {
  bar = 100 - idx - 1;
  myClose[idx] = Close[bar];
  myHMA[idx] = SMA(myClose, 14, idx);
}

...
You do not have the required permissions to view the files attached to this post.
Last edited by Carioca on Thu Nov 29, 2012 3:31 am, edited 1 time in total.
garyfritz

Re: All avereges_v2.5 within the shell code EA

Post by garyfritz »

Silly question, but: did you ever call ReadIndicatorValues() ??

I don't know what value of idx you used in your display message, so I don't know why it returned 0. I dropped your code into an indicator and it worked fine:

Code: Select all

int start()
{
   string com;
   
   ReadIndicatorValues();
   for (int i=90; i<100; i++) {
      int bar = 100 - i - 1;
      com = com + "i = " + i + ", bar = " + bar + ", Close[bar] = " + Close[bar] + ", myClose[i] = " + myClose[i] + ", myHMA[i] = " + myHMA[i] + "\n";
   }
   
   Comment(com);
   
   return(0);
}
carioca.gif
You do not have the required permissions to view the files attached to this post.
User avatar
Carioca
Trader
Posts: 49
Joined: Sat Jun 09, 2012 12:12 am

Re: All avereges_v2.5 within the shell code EA

Post by Carioca »

I know, Newbie question well it works perfectly.

More for some reason returns value 0.

thanks gary
Post Reply

Return to “Coders Hangout”