[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Please help to understand REF(ARRAY,N).



PureBytes Links

Trading Reference Links

Help file say +N is future and -N is the past.  I wrote a short AFL to
experiment this and it seems that N is opposite to what help file
says.  Please help to explain the reason.

Please change "delay" in parameter window to change N.


AFL codes starts:

SetBarsRequired(200, 0);

// Ehlers ITrend
// from Ehlers, John F. Cybernetic Analysis for Stocks and Futures.
Wiley. 2004. 
// Chapter 3, p. 21. Code on p. 24.
#include "c:/program files/Amibroker/formulas/Include/EhlersInclude.afl"
#include "c:/program files/Amibroker/formulas/Include/CommonInclude.afl"

function ITrend(array, alpha)
{
  // initialize early array values and declare as array
  //it = array;

  //it = (array[2] - 2*array[1] + array[0])/4; This initialization
takes a long time to converge.
  
  for ( i=0; i < 7; i++ ) {
    if ( i < 2 )
      it[i] = 0;
    else
      it = (array[i] + 2*array[i-1] + array[i-2])/4;
  }

  for(i = 7; i < BarCount; i++) { 
    it[i] = (alpha - alpha*alpha/4)*array[i]
            + .5*alpha*alpha*array[i-1] - (alpha -
.75*alpha*alpha)*array[i-2]
            + 2*(1 - alpha)*it[i-1] - (1 - alpha)*(1 - alpha)*it[i-2];
  }
  return it;
}

function ITrendTrigger(array)
{
  trigger = 2*array - Ref(array, -2);
  return trigger;
}


delay = Param ("delay", 0, -5, 5, 1);
Med = (H+L)/2;

// Instantaneous Trend
Plot(Med, "", colorBlack, styleLine);
trend = ITrend(Med, .07);
trendTrig = ITrendTrigger(trend);

Buy  = Cross(trendTrig,trend);
Sell = Cross(trend,trendTrig);
Buy1  = Cross(trendTrig,trend);
Sell1 = Cross(trend,trendTrig);
BS_location = trendTrig;

Plot(trend, "Ehlers ITrend", colorBlue, styleLine + styleThick);
Plot(trendTrig, "Ehlers Trigger", colorRed, styleLine);
PlotShapes( shapeUpArrow * Buy + shapeDownArrow * Sell, IIf( Buy,
colorGreen, colorRed ), 0);
PlotShapes( shapeUpArrow * Ref(Buy1,delay) + shapeDownArrow *
Ref(Sell1,delay), IIf( Ref(Buy1,delay), colorBrown, colorBlue ), 0); 




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/