some of the formulas I use on a regular basis

#1
MACD ============================

_SECTION_BEGIN("MACD");
ml = MACD(4,16);
sl = Signal(4,16,16);
dynamic_color = IIf ( ml > 0, colorGreen, colorRed );
dynamic_color2 = IIf ( ml-sl > 0, colorGreen, colorRed );
Plot ( ml, "MACD (4,16)", dynamic_color, styleThick );
Plot ( sl, "SIGNAL (16)", colorGold, styleDashed );
Plot ( ml-sl, "MACD Histogram", dynamic_color2, styleHistogram );
_SECTION_END();

=================================

TRIPLE %R =======================

_SECTION_BEGIN("Williams %R");
function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C )/( HHV( H, periods ) - LLV( L, periods ) );
}

Plot( PercentR(16), "%R (16) Short Term", colorGold, styleLine );
Plot( PercentR(32), "%R (32) Medium Term", colorOrange, styleLine );
Plot( PercentR(128), "%R (128) Long Term", colorPink, styleLine );
_SECTION_END();

=================================

IFT RSI =========================

_SECTION_BEGIN("IFT RSI");
// Inverse Fisher Transfor RSI
function InvFisherTfm( array )
{
e2y = exp( 2 * array );
return ( e2y - 1 )/( e2y + 1 );
}

Value1 = 0.1 * ( RSI( 5 ) - 50 );
Value2 = WMA( Value1, 9 );

Plot( InvFisherTfm( Value2 ), "IFT-RSI", colorRed );
PlotGrid( 0.5 );
PlotGrid(-0.5 );
_SECTION_END();

=================================

HMA =============================

_SECTION_BEGIN("Hull Moving Average");
// Hull Moving Average
P = ParamField("Price field",-1);
period = Param("Periodo",16,0,512);
sqrtperiod = sqrt(period);
Hull = WMA(2*WMA(P,period/2)-WMA(P,period),LastValue(sqrtperiod));
Colore = IIf(Hull >= Ref(Hull,-1),ParamColor("Colore Up",colorWhite),ParamColor("Colore Down",colorViolet));
Plot(Hull,"Hull",Colore,ParamStyle("Style")+styleNoTitle);
_SECTION_END();

=================================

SLOW STOCHASTIC =================

_SECTION_BEGIN("Slow Stochastic");
periods = Param( "Periods", 8, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 4, 1, 200, 1 );
Plot( StochK( periods , Ksmooth ), "", colorPink, styleLine );
Plot( StochD( periods , Ksmooth, DSmooth ), _DEFAULT_NAME(), colorRed, styleDashed );

PlotGrid( 80 );
PlotGrid( 20 );
_SECTION_END();

=================================

LONG/SHORT TERM MOMENTUM ========

_SECTION_BEGIN("Momentum");
function Momentum( array, period )
{
return array - Ref( array, -period );
}

Plot( Momentum( C, 8 ), "Momentum (8)", colorWhite );
Plot( Momentum( C, 32 ), "Momentum (32)", colorOrange );

PlotGrid( 0 );
_SECTION_END();

=================================

CCI + EMA =======================

_SECTION_BEGIN("CCI");
periods = Param( "Periods", 14, 2, 200, 1 );
Plot( CCI( periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

PlotGrid(0);

=================================

DRAW VERTICAL ===================

_SECTION_BEGIN("DRAW_VERTICAL LINE");
MA1 = MA(C, 32);
MA2 = MA(C, 16);

trig = Cross(MA2, MA1);
vLINE = Ref(trig, 16);

LLBars= LLVBars(L, 16 + 5);
pd = ValueWhen(trig,LLBars,0);
vLINELow = Ref(trig, pd);


//Plot(MA1, "MA1", colorYellow, styleLine);
//Plot(MA2, "MA1", colorBlue, styleLine);

Plot(vLINElow, "", colorGrey50 , styleArea|styleOwnScale);
_SECTION_END();

=================================
Hi, I wanted to share some of the forumlas I usually use in AmiBroker. I am sorry some are really poor written and have fixed parameters. You might want to adjust them in order to have them suit you better :lol:

Enjoy.

I still have a long way to go with AmiBroker's AFL :(
 
#2
Forgot the CyberCycle:

//SetBarsRequired( 200, 0 );

// Ehlers CyberCycle
// Cybernetic Analysis for Stocks and Futures
// Chapter 4, p. 33. Code on p. 38.
// Original code is at:
//
// http://www.traders.com/Documentatio...052004/TradersTips/TradersTips.html#amibroker

function Fisher(array)
// Figure 1.7 on p. 7
{
F = array;
F = .25 * log((1+ array)/(1 - array)) + .5 * Ref(F, -1);
return F;
};

function CyberCycle( array, alpha )
{
smooth = ( array + 2 * Ref( array, -1 ) +
2 * Ref( array, -2 ) + Ref( array, -3 ) ) / 6;
// init value
Cycle = ( array[ 2 ] - 2 * array[ 1 ] + array[ 0 ] )/4;
for( i = 6; i < BarCount; i++ )
{
Cycle[ i ] = ( ( 1 - 0.5 * alpha) ^ 2 ) *
( smooth[ i ] - 2 * smooth[ i - 1 ] + smooth[ i - 2] ) +
2 * ( 1 - alpha ) * Cycle[ i - 1 ] -
( ( 1 - alpha) ^ 2 ) * Cycle[ i - 2 ];
}

MaxCycle = HHV(Cycle, 14);
MinCycle = LLV(Cycle, 14);
for (i = 0; i < BarCount; i++) {
if (MaxCycle != MinCycle) {
Value1 = (Cycle-MinCycle)/(MaxCycle - MinCycle);
Value2 = (4*Value1 + 3*Value1[i-1] + 2*Value1[i-2] + Value1[i-3])/10;
Value2 = 2*(Value2 -.5);
};
}
return Value2;
}

// get log price
logprice = ln(Close);
OA1 = (logprice - Ref(logprice, -1))/sqrt(1);

// get change in bar and multiply it by the change in square root of time between yesterday AND today
n = 0;
totalprice[0]= 0;
for (i = BarCount-1; i>=1; i--){
n = n + 1;
deltaPrice = OA1*(sqrt(n) - sqrt(n-1));
totalprice = totalprice + OA1*(sqrt(n));
};

// get NMR
natCoef = Sum(deltaPrice, 40)/Sum(totalprice, 40);


Cycle = CyberCycle( (H+L)/2, .07);
Plot( Cycle, "Stoc CyberCycle", colorBlue );
Plot( Ref(Cycle, -1), "Trigger", colorRed );


By the way, here are the formula in my two charts. I trade only daily time frame...
 
Last edited:

Similar threads