Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Another Trail for Amibroker (AFL)

Rating:
3 / 5 (Votes 4)
Tags:
amibroker, trend

I adjusted code from a recent posting by Gopal titled: “NMA v 3.6 a optimiser” which is written by M.Karthik.

My adjustment code displays the trail using colors and allows the bull and bear parameter to be set separately. Further I use similar code and in my other trail postings. Also I removed the signals. This code simply shows the trend.

Screenshots

Similar Indicators / Formulas

Super Trend
Submitted by Arjun over 14 years ago
Trend Following Indicator
Submitted by trek over 14 years ago
PROFIT TRADING SYSTEM
Submitted by Muralikrishna over 11 years ago
Seasionality
Submitted by saiflingkon over 13 years ago
Vertical Horizontal Filter
Submitted by mahesh.aranake over 14 years ago
TrendChart v2.0 by rmike
Submitted by rmike over 14 years ago

Indicator / Formula

Copy & Paste Friendly
function trail_func(jj,trBull,trBear)
{
	trailArray[ 0 ] = jj[ 0 ]; // initialize
	for( i = 1; i < BarCount; i++ )
	{
		prev = trailArray[ i - 1 ];
 
		if (jj[ i ] > prev AND jj[ i - 1 ] > prev)
		{
			trailArray[ i ] = Max(prev,jj[ i ] - trBull[ i ]);
		}
		else if (jj[ i ] < prev AND jj[ i - 1 ] < prev)
		{
			trailArray[ i ] = Min(prev,jj[ i ] + trBear[ i ]);
		}
		else if (jj[ i ] > prev)
		{
			trailArray[ i ] = jj[ i ] - trBull[ i ];
		}
		else
		{
			trailArray[ i ] = jj[ i ] + trBear[ i ];	
		}
	}
	return trailArray;
}

// code by E.M.Pottasch
// adjusted from M.Kartnik 
// following: http://wisestocktrader.com/indicators/1710-nma-v-3-6-a-optimiser

k_bull = Param("mult bull",1.25,1,4,0.05); 
k_bear = Param("mult bear",1.25,1,4,0.05); 
Per= Param("period",10,5,50,1); 
 
HaClose=(O+H+L+C)/4; 
HaOpen = AMA(Ref(HaClose,-1),0.5); 
HaHigh = Max(H,Max( HaClose,HaOpen)); 
HaLow = Min(L,Min(HaClose,HaOpen));

ms=ParamList("ST0P/REV",List="Reg|Smoothed",0);
if(ms=="Reg")
{
	nm =(H-L);
	j=(O+H+L+C)/4;
}
else
{
	nm=(HaHigh-HaLow);
	j=(HaOpen+HaHigh+HaLow+HaClose)/4;
}
 
rfsctor = WMA(nm,PER); 
revers_bull=k_bull*rfsctor; 
revers_bear=k_bear*rfsctor;

nw = trail_func(j,revers_bull,revers_bear);

GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
Plot( Close, "\nPrice", colorWhite, styleCandle ); 
Plot(IIf(NW > j,NW,Null),"\ntrailShort",ParamColor("ColorTrailShort",ColorRGB(255,0,0)),styleStaircase);
Plot(IIf(NW < j,NW,Null),"\ntrailLong",ParamColor("ColorTrailLong",ColorRGB(0,255,0)),styleStaircase);

9 comments

1. mark2001

hi can u put the buy and sell arrows in it thx

2. empottasch

see link in code for the original code. This code contains signals. It all depends how you want to trade, either pullbacks within the trend or at the point the trend changes.

3. Rafamarc

Hi empottasch,
I have a system that gives entries and exits and I want to use this code just as trail and maybe as a trend filter as well. Can you please tell me how to do that?
Thanks,
Rafael

4. Rafamarc

Hi empottasch,
I have a system that gives entries and exits and I want to use this code just as trail and maybe as a trend filter as well. Can you please tell me how to do that?
Thanks,
Rafael

5. empottasch

for your filter question you can use (in case of Long trades) for example:

trendLong = IIf(NW < j,NW,Null);

so if you have your buy signals defined as:

Buy = your buy signal definition;

you add:

Buy = your buy signal definition AND !IsEmpty(trendLong);

to use it as a trail there are many ways to do this. Simple example is e.g. in the Long case:

Buy = your buy signal definition;
Sell = your sell signal definition OR Cross(NW,j);

6. empottasch

I used this code also to define trend channels, see: http://www.youtube.com/watch?v=HWPSqwEkN64

7. sateeshliks

hi empottash,
could you plz suggest me an afl formula with indicators .i actually need it with mano calculation

8. nicky

Sir this afl is not working in an hourly charts. Can u pls suggest if we can use this in hourly charts or not.

9. empottasch

should work in any timeframe. It works for me with hourly charts with no problem.

Leave Comment

Please login here to leave a comment.

Back