26 October 2011

Range Constriction for Amibroker AFL

This is a complete trading system which can be applied to a chart, backtested or used as an exploration for buy/sell signals.

It has backtested profitably on all markets I have tested it on.

Basically it looks for stocks that are trading in a reduced range compared to the previous period. For stocks that are trading at recent highs it will buy when the stock moves up within this range, it shorts when the stock moves lower within this range. For exits it either sells into increasing strength or if when the price pulls back (opposite for shorts).

When run as an exploration it will produce a -1 for short, 1 for buy, -99 for sell, 99 for cover and 0 for hold.


PosQty = 1000; // You can define here how many open positions you want
SetOption("MaxOpenPositions", PosQty);
//PositionSize = 1000/PosQty; // invest 100% of portfolio equity divided by Max. position count
SetPositionSize( 1, spsShares );


///////////////////////////////////////////////////////////////////////////////
// Range Constriction
// Finds stocks that are trading in a reduced range compared to previous period.
// Buys when in the reduced range at a recent high price, Shorts when in the reducred range at a recent low price.
// Sells when the stock slows or it makes a sharp move up, Covers when the stock rises or makes a sharp move down


H5 = HHV(H,5); L5 = LLV(L,5);
H10 = HHV(H,10); L10 = LLV(L,10);
H20 = HHV(H,20); L20 = LLV(L,20);
H30 = HHV(H,30); L30 = LLV(L,30);

Range1 = H5-L5 < (Ref(H5,-5)-Ref(L5,-5))*0.5; Range2 = H10-L10 < (Ref(H10,-10)-Ref(L10,-10))*0.5; Range3 = H20-L20 < (Ref(H20,-20)-Ref(L20,-20))*0.5; Range4 = H30-L30 < (Ref(H30,-30)-Ref(L30,-30))*0.5; Consolidation = Ref(Range1,-1) OR Ref(range2,-1) OR Ref(range3,-1) OR Ref(range4,-1) ; Top = C == HHV(C,5); Bottom = C == LLV(C,5); Buy = top AND Consolidation AND C>1 AND C*MA(V,30)>10000000 AND V>1000000 AND C>Ref(C,-1)*1.015
AND C>O AND C>MA(C,50) AND C>LLV(C,200)*2 AND Trix(12)>0;

Sell = CMA(C,10)*1.25 AND NOT Buy OR RSI(2)>95 AND NOT Buy;
InLong = Flip(Buy, Sell);

Short = bottom AND Consolidation AND C>5 AND V>1000000 AND C*MA(V,30)>10000000 AND CMA(C,5) AND NOT Short OR C0, 1,(IIf(Short>0, -1,0))))))),"Buy/Sell",1.0);

08 October 2011

DSE BULL TRAY AND EXIMP

http://jaywalkable.wordpress.com/

http://www.entrepreneur.com/article/41846

http://www.entrepreneur.com/article/220374


http://www.foreign-trade.com/reference/impexp.htm


http://spyglasspoint.com/

07 October 2011

VORTEX

Vortex Indicator w/ Histogram for Amibroker (AFL)


// Vortex Indicator
// S&C Traders Tips Jan 2010
period = Param("Period", 14, 2 );

VMP = Sum( abs( H - Ref( L, -1 ) ), period );
VMM = Sum( abs( L - Ref( H, -1 ) ), period );
STR = Sum( ATR( 1 ), period );

VIP = VMP / STR;
VIM = VMM / STR;

//Plot( VIP, "VI"+period+"+", colorBlue);
//Plot( VIM, "VI"+period+"-", colorRed );


Hist = VIP - VIM;
HistPrev = Ref(Hist,-1);

Color = IIf(Hist>HistPrev,colorCustom9,
IIf(hist0,colorCustom11,
IIf(hist<0,colorCustom8,colorWhite)); Plot( Hist, "", color, styleHistogram+styleOwnScale+styleThick ); Vortex Indicator System for Amibroker (AFL) // Vortex Indicator // S&C Traders Tips Jan 2010 period = Param("Period" , 14, 2 ); VMP = Sum( abs( H - Ref( L, -1 ) ), period ); VMM = Sum( abs( L - Ref( H, -1 ) ), period ); STR = Sum( ATR( 1 ), period ); VIP = VMP / STR; VIM = VMM / STR; Plot( VIP, "VI"+period+ "+", colorBlue); Plot( VIM, "VI"+period+ "-", colorRed ); //The system is defined as: //- Go long when the VI (or Dmi) goes from less than zero to greater than //zero. //- Go short when the VI (or Dmi) goes from above zero to less than zero. // - All trades are placed "next day market on open." // That would translate to: SetTradeDelays( 1,1,1,1); // everything delayed 1 day Buy = VIP > 0 AND Ref(VIP,-1) < 0; BuyPrice = Open; Sell = VIP < 0 and Ref(VIP,-1) > 0;
SellPrice = Open;
Short = Sell;
Cover = Buy;



VORTEX OSCILI


_SECTION_BEGIN("Vortex Oscillator");

// Vortex Indicator
// S&C Traders Tips Jan 2010
SetChartBkColor(colorBlack);
SetBarsRequired(sbrAll);
period = Param("Period", 21, 2 );
VMP = Sum( abs( H - Ref( L, -1 ) ), period );
VMM = Sum( abs( L - Ref( H, -1 ) ), period );
STR = Sum( ATR( 10 ), period );

VIP = VMP / STR;
VIM = VMM / STR;
K1=VIP-VIM;
K=TEMA(K1,7);
ifish=EMA(EMA(EMA(EMA(K,3),3),3),3);
Color=IIf(ifish>0,IIf(ifish>Ref(ifish,-1),colorGreen,colorYellow),IIf(ifish>Ref(ifish,-1),colorBlue,colorRed));
Plot(ifish," Vortex Oscillator ",Color,styleHistogram | styleThick, maskHistogram);
Plot(0,"",colorYellow,styleDashed);


_SECTION_END();

04 October 2011

AFL CODE SITE

http://www.aussiestockforums.com/forums/index.php

http://www.imageview.us/amibroker/


http://www.traders.com/index.php/sac-magazine/departments/traders-tips/182-amibroker-spearman-indicator--valcu-article-code

02 October 2011

Trend Quality Indicators for Amibroker (AFL)

Trend Quality Indicators for Amibroker (AFL)


Originally described in Stocks & Commodities April 2004, by David Sepiashvili.
The trend-quality indicator (or Q-indicator) is a trend detection and estimation tool that is based on a two-step filtering technique. It measures cumulative price changes over term-oriented semicycles and relates them to ‘noise.’ The approach reveals congestion and trending periods of the price movement and focuses on the most important trends, evaluating their strength in the process. The indicator is presented in a centered oscillator and banded oscillator format.

Both Q-Indicator (the Trend Quality one) and the B-Indicator (trend-noise Balance Indicator) can be displayed (alternatively).

Different crossover signals can be easily added by just adding the required string in ParamList (the string SHALL follows the convention ?MA m1,m2 where ?MA is the MA type (EMA, SMA or WMA) and m1,m2 are the period ALWAYS in 2 digits (i.e. 5 shall be written as 05)

Q-indicator has 3 levels: 2(+/-) and 5(+/-): 0 to 2 means weak or NO trend; 2 to 5 means moderate trend, >= 5 means strong trend (Up trend if positive, Down trend if negative).

B-Indicator fluctuates between 0 to 100. It is better suited to identifies overbought/oversold levels. It has 2 levels: 65 and 80. 0 to 65 means NO or weak trend, 65 to 80 means moderate trend and >= 80 means strong trend.

I like this indicator since it is quite “agnostic” about the chosen parameters (Obviously the crossover MAs do matter !!).

Here is a screenshot of how the indicator looks:



Trend Quality Indicators for Amibroker (AFL)

In "Trend-Quality Indicator" in this issue, David Sepiashvili presents an innovative trend-detection tool -- the trend-quality indicator -- that attempts to estimate the trend in relation to noise.

Calculations presented in the article can be easily reproduced using AmiBroker Formula Language. The only tricky part is a piecewise exponential moving average that restarts the calculations on every moving average crossover, but we managed to implement it in two lines of code, thanks to AmiBroker's powerful Ama2 function, which allows easy implementation of all kinds of single-order infinite impulse response filters.

Listing 1 shows ready-to-use indicator code to plot the Q-indicator. In AmiBroker, select Indicator Builder from the Analysis menu, click the "Add" button, enter the formula, and then press "Apply." Figure 3 shows a sample chart.


// Piecewise EMA is an EMA that restarts calculations each time
// the 'sincebar' argument is true
function PiecewiseEMA( array, range, sincebar )
{
factor = IIf( sincebar, 1, 2/(range+1) );
return AMA2( array, factor, 1-factor );
}
// parameters
m=4;
n=250;
// generate reversal signals based on EMA crossover rule
Lpf1 = EMA( C, 7 );
Lpf2 = EMA( C, 15 );
CrossPoint = Cross( Lpf1, Lpf2 ) OR Cross( Lpf2, Lpf1 );
Periods = BarsSince( CrossPoint );
// variable bar sum
DC = Close - Ref( Close, -1 );
CPC = Sum( DC, Periods );
// smooth CPC by piecewise 4 bar EMA
Trend = PiecewiseEMA( CPC, 4, CrossPoint );
// noise
DT = CPC - Trend;
Noise = 2 * sqrt( MA( DT^2, n ) );
// alternative 'linear' noise calculation
// Noise = 2 * MA( abs( DT ), n ) );
QIndicator = Trend/Noise;
Plot(sign(Lpf1-Lpf2), "Rev", colorRed );
Plot( Qindicator, "Qindicator", colorGreen, styleHistogram);
PlotGrid( -1 );
PlotGrid( 1 );
PlotGrid( 2 );
PlotGrid( -2 );
PlotGrid( 5 );
PlotGrid( 5);

Trend Quality Indicators for Amibroker (AFL)

Trend Quality Indicators for Amibroker (AFL)


Originally described in Stocks & Commodities April 2004, by David Sepiashvili.
The trend-quality indicator (or Q-indicator) is a trend detection and estimation tool that is based on a two-step filtering technique. It measures cumulative price changes over term-oriented semicycles and relates them to ‘noise.’ The approach reveals congestion and trending periods of the price movement and focuses on the most important trends, evaluating their strength in the process. The indicator is presented in a centered oscillator and banded oscillator format.

Both Q-Indicator (the Trend Quality one) and the B-Indicator (trend-noise Balance Indicator) can be displayed (alternatively).

Different crossover signals can be easily added by just adding the required string in ParamList (the string SHALL follows the convention ?MA m1,m2 where ?MA is the MA type (EMA, SMA or WMA) and m1,m2 are the period ALWAYS in 2 digits (i.e. 5 shall be written as 05)

Q-indicator has 3 levels: 2(+/-) and 5(+/-): 0 to 2 means weak or NO trend; 2 to 5 means moderate trend, >= 5 means strong trend (Up trend if positive, Down trend if negative).

B-Indicator fluctuates between 0 to 100. It is better suited to identifies overbought/oversold levels. It has 2 levels: 65 and 80. 0 to 65 means NO or weak trend, 65 to 80 means moderate trend and >= 80 means strong trend.

I like this indicator since it is quite “agnostic” about the chosen parameters (Obviously the crossover MAs do matter !!).

Here is a screenshot of how the indicator looks:



Trend Quality Indicators for Amibroker (AFL)

In "Trend-Quality Indicator" in this issue, David Sepiashvili presents an innovative trend-detection tool -- the trend-quality indicator -- that attempts to estimate the trend in relation to noise.

Calculations presented in the article can be easily reproduced using AmiBroker Formula Language. The only tricky part is a piecewise exponential moving average that restarts the calculations on every moving average crossover, but we managed to implement it in two lines of code, thanks to AmiBroker's powerful Ama2 function, which allows easy implementation of all kinds of single-order infinite impulse response filters.

Listing 1 shows ready-to-use indicator code to plot the Q-indicator. In AmiBroker, select Indicator Builder from the Analysis menu, click the "Add" button, enter the formula, and then press "Apply." Figure 3 shows a sample chart.


// Piecewise EMA is an EMA that restarts calculations each time
// the 'sincebar' argument is true
function PiecewiseEMA( array, range, sincebar )
{
factor = IIf( sincebar, 1, 2/(range+1) );
return AMA2( array, factor, 1-factor );
}
// parameters
m=4;
n=250;
// generate reversal signals based on EMA crossover rule
Lpf1 = EMA( C, 7 );
Lpf2 = EMA( C, 15 );
CrossPoint = Cross( Lpf1, Lpf2 ) OR Cross( Lpf2, Lpf1 );
Periods = BarsSince( CrossPoint );
// variable bar sum
DC = Close - Ref( Close, -1 );
CPC = Sum( DC, Periods );
// smooth CPC by piecewise 4 bar EMA
Trend = PiecewiseEMA( CPC, 4, CrossPoint );
// noise
DT = CPC - Trend;
Noise = 2 * sqrt( MA( DT^2, n ) );
// alternative 'linear' noise calculation
// Noise = 2 * MA( abs( DT ), n ) );
QIndicator = Trend/Noise;
Plot(sign(Lpf1-Lpf2), "Rev", colorRed );
Plot( Qindicator, "Qindicator", colorGreen, styleHistogram);
PlotGrid( -1 );
PlotGrid( 1 );
PlotGrid( 2 );
PlotGrid( -2 );
PlotGrid( 5 );
PlotGrid( 5);

My Blog List

Total Pageviews

Search This Blog

Followers