stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

All avereges_v2.5 within the shell code EA
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1101
Page 1 of 1
Author:  Carioca [ Mon Nov 19, 2012 8:14 pm ]
Post subject:  All avereges_v2.5 within the shell code EA

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
Author:  Carioca [ Fri Nov 23, 2012 4:10 pm ]
Post subject:  Re: All avereges_v2.5 within the shell code EA

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;
Author:  Carioca [ Tue Nov 27, 2012 2:10 pm ]
Post subject:  Re: All avereges_v2.5 within the shell code EA

Does there exist one, very generous programmer that can help me?
Author:  garyfritz [ Thu Nov 29, 2012 12:35 am ]
Post subject:  Re: All avereges_v2.5 within the shell code EA

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
Author:  Carioca [ Thu Nov 29, 2012 2:01 am ]
Post subject:  Re: All avereges_v2.5 within the shell code EA

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);
}

...
Author:  garyfritz [ Thu Nov 29, 2012 2:27 am ]
Post subject:  Re: All avereges_v2.5 within the shell code EA

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
Author:  Carioca [ Thu Nov 29, 2012 3:11 am ]
Post subject:  Re: All avereges_v2.5 within the shell code EA

I know, Newbie question well it works perfectly.

More for some reason returns value 0.

thanks gary
All times are UTC Page 1 of 1