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

ADX Trading System for Amibroker (AFL)

Rating:
2 / 5 (Votes 3)
Tags:
oscillator, trading system, amibroker

Trend Following System using ADX as trigger with scaling out

Indicator / Formula

Copy & Paste Friendly
	SetOption("InitialEquity", 1000000);
	SetOption("MinShares", 100);
	RoundLotSize = 100;	
	SetOption("CommissionMode", 1);
	SetOption("CommissionAmount", 0.16);
	SetTradeDelays( 0, 0, 0, 0);
	BuyPrice = SellPrice = Close;

	oMA1 = 10; //Optimize( "oMA1", 9, 1, 15, 3);
	oMA2 = 30; //Optimize ( "oMA2", 24, 10, 50, 5);
	MA1 = EMA( C, oMA1);
	MA2 = EMA( C, oMA2);
	Bullish = MA1 > MA2;
	Bearish = MA2 <= MA1;

	ADXperiod = 42; 
	ADXline = ADX(ADXperiod); 
	maADX = MA( ADXline, 10);

	
	buyCon1 = Bullish;
	buyCon2 = Cross( ADXline, maADX);
	

	sellCon1 = Cross(maADX, ADXline); 
	sellCon2 = MACD() < 0;
	
	Buy = buyCon1 AND buyCon2; 
	Sell = sellCon1 OR sellCon2 ;
	Buy = ExRem(Buy, Sell);
	Sell = ExRem(Sell, Buy);
	Short = Cover = 0;	

	MaxOpenPositions = 10;
	PercentPerPosition = 100/MaxOpenPositions;
	SetOption("MaxOpenPositions", MaxOpenPositions);
	SetPositionSize( PercentPerPosition, spsPercentOfEquity);
	PositionScore =  C*V/MA(C*V, 10);

	//Money Management Scaling Out
	FirstProfitTarget = 45; //Optimize("1TP", 40, 5, 50, 5); 		// profit 
	SecondProfitTarget = 60; //Optimize("2TP", 50, 5, 50, 5); 		// in percent 
	TrailingStop = 40; //Optimize("Trail", 40, 25, 45, 5) ; 		// also in percent 
	Stoplevel = 15; //Optimize( "Stop", 10, 5, 15, 1);
	ScaleOut = 30; //sell 50% of original position
	
	priceatbuy=0; 
	highsincebuy = 0; 
	exit = 0; 
	for( i = 0; i < BarCount; i++ ) 
	{ 
	   if( priceatbuy == 0 AND Buy[ i ] ) 
		 { 
		   priceatbuy = BuyPrice[ i ]; 
		 } 
	   if( priceatbuy > 0 ) 
		 { 
		   highsincebuy = Max( High[ i ], highsincebuy ); 
		  if( exit == 0 AND 
			  High[ i ] >= ( 1 + FirstProfitTarget * 0.01 ) * priceatbuy ) 
		   { 
			 // first profit target hit - scale-out 
			 exit = 1; 
			 Buy[ i ] = sigScaleOut; 
		   } 
		  if( exit == 1 AND 
			  High[ i ] >= ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy ) 
		   { 
			 // second profit target hit - exit 
			 exit = 2; 
			 SellPrice[ i ] = Max( Open[ i ], ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy ); 
		   } 
		  if( Low[ i ] <= ( 1 - TrailingStop * 0.01 ) * highsincebuy ) 
		   { 
			 // trailing stop hit - exit 
			 exit = 3;     
			 SellPrice[ i ] = Min( Open[ i ], ( 1 - TrailingStop * 0.01 ) * highsincebuy ); 
		   } 
		  if( exit >= 2 ) 
		   { 
			 Buy[ i ] = 0; 
			 Sell[ i ] = exit + 1; // mark appropriate exit code 
			 exit = 0; 
			 priceatbuy = 0; // reset price 
			 highsincebuy = 0; 
		   } 
		 } 
	} 
	
	ApplyStop( stopTypeLoss, stopModePercent, stoplevel);
	SetPositionSize( 10, spsPercentOfEquity ); 
	SetPositionSize( ScaleOut, spsPercentOfPosition * ( Buy == sigScaleOut ) ); 

2 comments

1. hohoyu

not work. use for daily chart?

2. shriprakashsingh

not working

Leave Comment

Please login here to leave a comment.

Back