Вы находитесь на странице: 1из 15

Amibroker AFL

Amibroker AFL Trend Quality Indicator

Amibroker AFL Trend Quality Indicator David Sepiashvili presented the Trend
Quality Indicator as an indicator to filter out noise from the trend.

The trend-quality indicator (or Q-indicator) is a trend determination indicator that


uses two-step filtering technique. At first, it measures cumulative price changes over
term-oriented semi cycles. Then, it relates the cumulative price changes to noise.
This method helps revealing congestion and trending periods of the price
movement and helps traders focus on the most important trends. It directly enables
trader to evaluate the strength of trend in the process. The indicator is presented in a
centered oscillator and banded oscillator format.

How to Use the Amibroker AFL Trend Quality Indicator

Q-indicator mostly plots values between -5 to +5. However, in extreme period of


trends, values do cross these levels on either side. According to David, if the Q-
indicator level is above +1 (but below 2) or below -1 (but above -2), then trend is
weak to semi strong. Whereas anything above 2 or below -2 is very strong trend.
Any reading which is between 0 and 1 or between 0 and -1 indicates very weak trend
and should be avoided. Author also states that whenever the Q-indicator reading
goes above +2 or -2, trader is advised to get on the trend and ride it till signs of
reversals emerge. Though this technique is useful, it must be noted that by the time
+2 or -2 level is crossed, trends reversals begin to happen few days later. It is only in
sustaining trending move that such method is extremely profitable.

Better way to use this indicator according to me is to get the bias of trend once +2 or
-2 is breached. Once that happens, traders can shift to hourly or 30 minute time
frame and adopt the buy on dip or hit and run strategy to enter and exit quickly with
profit. Since the trader would be entering in the direction of trend, odds of taking big
loss is small.
Amibroker AFL Trend Quality Indicator

// 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", IIf(Qindicator > 2 OR Qindicator < -
2,colorGreen,colorRed),styleHistogram);

PlotGrid( -1 );
PlotGrid( 1 );
PlotGrid( 2 );
PlotGrid( -2 );
PlotGrid( 5 );
PlotGrid( 5);
Amibroker AFL ATR Channel Breakout System

Amibroker AFL ATR Channel Breakout I had explained this system in this post.
Just refer to the post to know what this AFL is all about. Basically this is a system
which takes into account market volatility. The results of this system have also been
posted and you can find them here. All one has to do is load this Amibroker AFL
directly on to the chart. The entire system will be visible. If you want, then go ahead
and add the Buy/Sell commands. In case you do not know how to do that, then let
me know. I will update the AFL then.

Here are the steps to use this AFL,

1. In the Amibroker Software, go to Analysis and then click Formula Editor.

2. Paste the contents of the AFL

3. Then, go to the Apply indicator tab in formula editor region.

4. Click on Insert Indicator.

5. Once you do the above, you will get a chart which is similar to what I have posted
below.

I will advise you to go through the rules of the system to have a better idea on how to
use it. In highly volatile times, this is a good system which makes you enter small
when volatility is high and enter big when volatility is low.

Plot( C, "Close", colorBlack, styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

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

Plot( EMA(Close,50) + (2*ATR(20)), "Long Entry Threshold", colorGreen, styleLine|styleThick );


Plot( EMA(Close,50) - (2*ATR(20)), "Short Entry Threshold", colorRed, styleLine|styleThick );

Plot( EMA(Close,50) + (ATR(20)), "Short Stop Loss", colorViolet, styleLine|styleDashed );


Plot( EMA(Close,50) - (ATR(20)), "Long Stop Loss", colorBrown, styleLine|styleDashed );
Trading Strategies ATR Channel Breakout

In this article, I will explain the basics of this Trading strategy. In the next article, I will
test this strategy on Nifty. I will then share the results and analyze it.

ATR channel breakout strategy is foundation of many similar breakout systems


which account for volatility. Market fluctuates between low volatility and high
volatility. Therefore any system which a trader uses, should account for market
volatility. In this system, volatility is measured based on Average True Range (ATR).
The center of the channel is Exponential Moving Average (EMA) defined by the
number of days as selected by the trader. Whereas, top and bottom of the channel
are defined by using multiple of ATR from the moving average. Broadly, there are
three parameters used.

Closing Days Determines the number of days across which EMA is


calculated
Entry Threshold ATR Multiple from EMA which forms outer extremes of
channel
Exit Threshold ATR Multiple from EMA where stop loss gets triggered

Entry & Exit Rules

Buy Entry is taken on Open next day, if on previous day, price closed above the
Entry threshold. That is, above the top of the channel. For Short selling, rules are
exactly the opposite. Trade is kept open, till the price does not close below the Exit
threshold. Exit threshold is a Stop loss/Profit Trail mechanism.

Since this Trading strategy buys strength and shorts weakness, it is absolutely
necessary that pyramiding techniques be used. Positions must be added on winning
trades and losses must be taken on small positions. As a position sizing technique,
averaging should never be adopted for this Trading strategy.

Testing Parameters

Testing Parameters used in this Trading Strategy will depend on nature of system
designed. I am giving the parameters for a short term ATR Channel Breakout
strategy. Readers can set the parameters according to their trading style.

Closing Days 50 Days Exponential Moving Average

ATR Average True Range over 20 Days

Entry Threshold 2 Times ATR

Exit Threshold 1 Time ATR

I am including an image so that Strategy is clear to all. In the next article, I will share
the results for this strategy.
Trading Strategies ATR Channel Breakout Trending Market

Trading Strategies ATR Channel Breakout Non Trending Market

Trading Strategies ATR Channel Breakout

In this article, I will explain the basics of this Trading strategy. In the next article, I will
test this strategy on Nifty. I will then share the results and analyze it.

ATR channel breakout strategy is foundation of many similar breakout systems


which account for volatility. Market fluctuates between low volatility and high
volatility. Therefore any system which a trader uses, should account for market
volatility. In this system, volatility is measured based on Average True Range (ATR).
The center of the channel is Exponential Moving Average (EMA) defined by the
number of days as selected by the trader. Whereas, top and bottom of the channel
are defined by using multiple of ATR from the moving average. Broadly, there are
three parameters used.
Closing Days Determines the number of days across which EMA is
calculated
Entry Threshold ATR Multiple from EMA which forms outer extremes of
channel
Exit Threshold ATR Multiple from EMA where stop loss gets triggered

Entry & Exit Rules

Buy Entry is taken on Open next day, if on previous day, price closed above the
Entry threshold. That is, above the top of the channel. For Short selling, rules are
exactly the opposite. Trade is kept open, till the price does not close below the Exit
threshold. Exit threshold is a Stop loss/Profit Trail mechanism.

Since this Trading strategy buys strength and shorts weakness, it is absolutely
necessary that pyramiding techniques be used. Positions must be added on winning
trades and losses must be taken on small positions. As a position sizing technique,
averaging should never be adopted for this Trading strategy.

Testing Parameters

Testing Parameters used in this Trading Strategy will depend on nature of system
designed. I am giving the parameters for a short term ATR Channel Breakout
strategy. Readers can set the parameters according to their trading style.

Closing Days 50 Days Exponential Moving Average

ATR Average True Range over 20 Days

Entry Threshold 2 Times ATR

Exit Threshold 1 Time ATR

I am including an image so that Strategy is clear to all. In the next article, I will share
the results for this strategy.

Trading Strategies ATR Channel Breakout Trending Market


Trading Strategies ATR Channel Breakout Non Trending Market

Stop Loss in Terms of ATR

Another popular way to keep a Stop Loss which takes into account stocks volatility
is with the help of ATR. ATR is the Average True Range of the stock over a period of
days decided by the Trader. The way to set a Stop Loss is to take the ATR(n) value
and multiply it by a factor of 2 or 3. The most popular multiplier is 3 and the most
popular ATR setting is ATR (20). That is, Average True Range over a period of 20
days. ATR is available in most Technical Analysis Softwares and therefore once you
have the value of ATR, you can simply multiply it with the factor of 3 and subtract it
from your entry price (in case of Buy trade). Look at the chart below for better
understanding.

What Is Stop Loss ATR Method


Which Stop Loss method to choose is something we leave it for you to decide. At our
Trading desk, Historical Volatility based Stop Loss is used. But as per users liking,
even ATR based stop loss can be used. Make sure that you account for changing
market conditions. A Stop Loss which does not incorporate volatility exposes a trader
to unnecessary losses and drawdowns.

Amibroker AFL Historical Volatility

Amibroker AFL Historical Volatility We discussed about how to set Initial Stop Loss
using Historical Volatility yesterday. Attached with this post is the AFL for plotting
Historical Volatility in a chart. The concept of using Historical Volatility in trading was
explained very well by Larry Connors and Linda Bradford Raschke. This AFL has
been programmed according to the calculations explained by them in their book,
Street Smarts. Its better if you read this book as there are many concepts related to
volatility which are worth reading.

The main use of this AFL is to identify historical volatility levels. VIX is only available
since 2008 and ATR based volatility is not entirely accurate in representing the true
picture of volatility. Therefore, by using this AFL, historical volatility levels can be
easily computed and strategies related to volatility and price can be devised and
backtested. One common way to use this indicator is to plot short term Historical
Volatility and long term Historical Volatility together and see if the market is going to
be more volatile or less volatile in the future. Based on the findings, appropriate
strategies can be used. We will cover some of those strategies in our future posts.
Larry Connors and Linda Bradford Raschke recommend setting of 20 and 100 for
short term and long term volatility.
Amibroker AFL Historical Volatility

_N(Title = StrFormat(Name()+ " {{DATE}} - Open %g, Hi %g, Lo %g, Close %g (%.1f%%)
{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

HV = StDev(ln(Close/Ref(Close,-1)), 20)*100*sqrt(252); //1 Month Volatility

Plot(HV, "HV 20", colorRed, styleLine);

Stop Loss in Terms of Historical Volatility

Market is changing all the time. Therefore, it is better to have a technique to set stop
loss which takes into account the changing dynamics of the market. When the
market is volatile, stop loss should be wide and when the market is less volatile, stop
loss can be relatively less wide. One problem faced by traders is getting frequently
stopped out of their positions. The main reason for this is that they dont take into
account the market volatility aspect. In order to calculate stop loss based on
volatility, one needs to calculate the Historical Volatility of the stock. The formula for
calculating Historical Volatility is,

HV = StandardDeviation(Ln(close/yesterdaysclose), days) *100*Sqrt(number of trading days


in year)

where, Days = Length of days (10,20,30,40 . )


Ln = Natural Logarithm

For e.g A 50 Day HV with 252 trading days in an year would be calculated like this,

HV(50) = Stdev(Ln(Close/Yesterdays close), 50)*100*Sqrt(252)

Once you have the Historical Volatility of the stock, you can simply subtract it from
your entry price and you would get your stop loss. In the chart below, we have
selected two stocks of the same price range and yet they have different volatility
parameters. Therefore, stop loss for same price range stock is different. This is the
right way to set stop loss as it takes into account the volatility of the stock.

What Is Stop Loss L&T Historical Volatility Method

What Is Stop Loss ICICI Bank Historical Volatility Method


Amibroker AFL Volume Flow Indicator

Amibroker AFL Volume Flow Indicator This is an indicator developed by Markos


Katsanos as a variant of On Balance Volume (OBV), but it is far better than that. I
had come across this indicator and had found it to be extremely useful in Volume
analysis.

As improvements over OBV, Volume Flow Indicator has attempted to overcome all
the shortcomings of the OBV. Firstly, VFI uses stocks typical price in its calculations
(High + Low + Close)/3. This represents the true average of trading activity in terms
of price and volume. Secondly, there is a minimum cutoff % change in price after
which the calculation is done. Unlike in OBV, where even a slight change in price in
% terms would lead to distorted calculations. And Finally, VFI nullifies the impact of
extreme volume bars which usually distort any volume indicator if present on the
chart. VFI does this by cutting off any excess volume above a certain limit, which is
expressed as a multiple of the volume moving average.

How to Use the Volume Flow Indicator

This is how Markos Katsanos has advised to use this Indicator.

The Zero Level and direction of VFI If the value of the VFI is above zero, it is
considered bullish and indicates accumulation. If the Value of VFI is below zero, it
indicates distribution. When VFI crosses the zero line, it indicates that the
intermediate balance of power is changing from the bulls to the bears and vice versa.
Direction of VFI is also important. When VFI is rising, price will move higher. When
VFI will fall, price will eventually fall.

The Divergence Divergence is a classic method of detecting potential reversal


when price makes a higher high or lower low that is not confirmed by the indicator. In
context of this indicator, when Volume Flow Indicator fails to confirm higher highs or
lower lows with the price, then divergence occurs. This is potentially a reversal
signal.

Amibroker AFL Volume Flow Indicator VFI & Trend


Amibroker AFL Volume Flow Indicator Divergence

Period = Param("VFI Period", 26, 26, 1300, 1 );


Coef = 0.2;
VCoef = Param("Max. vol. cutoff", 2.5, 2.5, 50, 1 );
inter = log( Avg ) - log( Ref( Avg, -1 ) );
Vinter = StDev(inter, 30 );
Cutoff = Coef * Vinter * Close;
Vave = Ref( MA( V, Period ), -1 );
Vmax = Vave * Vcoef;
Vc = Min( V, VMax );
MF = Avg - Ref( Avg, -1 );
VCP = IIf( MF > Cutoff, VC, IIf ( MF < -Cutoff, -VC, 0 ) );
VFI = Sum( VCP , Period )/Vave;
VFI = EMA( VFI, 3 );
Plot( VFI, "VFI", colorBlack, styleThick );
Plot( EMA( VFI, 7 ), "EMA7 of VFI", colorBrown );
Plot( 0, "", colorSeaGreen, styleNoLabel );
Plot( V, "Volume", IIf( VCP > 0, colorGreen,
IIf( VCP < 0, colorRed, colorBlue ) ),
styleHistogram | styleOwnScale | styleNoLabel );
Amibroker AFL Finite Volume Element

Amibroker AFL Finite Volume Element (FVE) Finite Volume Element indicator was
introduced by Markos Katsanos. The Finite Volume Element Indicator is a money
flow indicator but it is different from On Balance Volume (OBV) and Chakins Money
flow (CMF) indicator. The main difference in these indicators is that the OBV and
CMF, add or subtract volume even if stock barely manages to close above or below
previous close. FVE on the other hand, uses a threshold to filter out directional
movement instead of random noise. The threshold used is 0.3% of Close.

Calculating FVE

FVE is calculated by adding +V or subtracting -V from a running total of volume for


the finite time element chosen (days, bars, weeks, and so on) according to whether:
C ((H + L)/2) + Typical Typical-1 > 0.3%C or < 0.3%C

where:
C= Todays closing price
H= Todays high

L= Todays low
Typical = (H+L+C)/3
Typical-1= Yesterdays typical price.

Default period used by authors is 22 days

How to Use FVE

The values of FVE fluctuate between -100 to +100.

Broadly there are two ways to FVE. The first is to look at the slope. If the Slope is
heading higher, then this is a sign of accumulation and bulls being in control. On the
other hand, if the slope is down, then this is a sign of distribution with bears being in
control. Another way to use FVE is to see where it is with respect to zero line. A
FVE value higher than zero indicates accumulation; the opposite is true for negative
values. A logical buy signal would be for FVE to diverge from price, make a series
of higher highs and/or higher lows, and then cross (or be about to cross) the zero
line.

Do not forget to experiment on higher time frames for long term trends. This indicator
is very useful in determining long term trends.
Amibroker AFL Finite Volume Element Nifty Daily

Amibroker AFL Finite Volume Element Nifty Weekly

Credit for the AFL goes to the Author Markos


Period = 22;

MF = C - (H+L)/2 + Avg - Ref( Avg, -1 );


Vc = IIf( MF > 0.003 * C, V,
IIf( MF < -0.003 * C, -V, 0 ) );
FVE = Sum( Vc, Period )/MA( V, Period )/Period * 100;
Plot( FVE, "FVE", colorRed );
GraphXSpace = 3;
Buy = Cross( FVE, -5 ) AND
LinRegSlope( FVE, 35 ) > 0 AND
LinRegSlope( Close, 35 ) < 0;
Sell = LinRegSlope( FVE, 25 ) < 0 OR Ref( Buy, -50 );

Вам также может понравиться