Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

AFL Library

This is read-only version of AFL library entry. Ability to add user formulas and comment is only available from members-only area.

Details:

Formula name: Chandelier Exit
Author/Uploader: RAC - (email hidden)
Date/Time added: 2008-12-13 18:31:07
Origin:
Keywords: chandelier exit
Level: basic
Flags: indicator

DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
Description:

An improved and easier to understand version of Chuck Lebeau\'s chandelier exit.

Formula:

/* Chandelier exit based on Chuck Lebeau's work back in the 90's.
 * Strengths: volatility-based.
 * Weaknesses: lag and since volatility increases at the end of a trend,
traders exits early.
 * Algorithm: Lebeau recommends that an exits hangs from the HHV (long) or LLV
(short)
 * since the trade was triggered. Some traders use the highest close as the
base for
 * hanging the exit.
 * Indicator author: RAC
 * Description: Indicator is used to keep track of a trade. Indicator shows a
circle
 * where the exit would have taken place. Once a stop is hit, it waits for the
next
 * entry signal (short or long). Use on DAILY values only.
 * Observations: If you are an EOD trader, your entry should take place at the
open
 * of the next day. Indicator shows the entry on the day of the signal.
 * Observations: Exits should take place only if the close is above the exit;
 * indicator forces an exit when the stop gets hit (using the day' low or
high). For backtesting
 * we'd need to modify the code to reflect that rule.
*/

_SECTION_BEGIN("Chandelier Exit");
SetBarsRequired(50,50);
Multiple = Param("Multiple (1=0.5):", 5, 1, 10, 1)/2; //How many ATR’s to be
allowed below the highest high since latest "buy" bar
ATRPeriods = Param("ATR Periods", 21, 1, 50, 1); //How many periods to use for
the ATR

//This is where you plug in your formula for LONG trades
goingLong = Cross( C, EMA(C,50) );
//This is where you plug in your formula for SHORT trades
goingShort = Cross( EMA(C,50), C);

stopArray = Null;
atrArray = ATR(ATRPeriods);
HHArray = Null;
LLArray = Null;
exitArray = Null;
trendDirection = 0;
for ( i=0; i < BarCount; i++ )
{
	if( goingShort[i] )
		{//we just triggered a short trade. Set up starting values
		stopArray[i] = Low[i] + (Multiple * atrArray[i]);
		LLArray[i] = Low[i]; //initialize the lowest low array
		trendDirection = 0-1; //going short. Base bar.
		}

	if( goingLong[i] )
		{//we just triggered a long trade. Set up starting values
		stopArray[i] = High[i] - (Multiple * atrArray[i]);
		HHArray[i] = High[i]; //initialize the highest high array
		trendDirection = 1;//going long. Base bar flag is now set.
		}

	exitArray[i] = 0;
	if( trendDirection > 0 )
		{//keep track of the highest high, highest close, highest low, etc..
		if( trendDirection > 1 )
			{//We are in the trade (2nd day or later)
			if( Low[i] < stopArray[i-1] )
				{//stop got hit. Reset the trade.
				trendDirection = 0; //OK. wait until we trigger another trade.
				exitArray[i] = 1;
				}
			else
				{//keep track of the HHV since trade was entered.
				if( High[i] > HHArray[i-1] )
					HHArray[i] = High[i];
				else
					HHArray[i] = HHArray[i-1];

				//Compute the stop based on the HHV.
				stopArray[i] = HHArray[i] - (Multiple * atrArray[i]);
				}
			}
		trendDirection = trendDirection+1;
		}

	if( trendDirection < 0 )
		{//keep track of the highest high, highest close, highest low, etc..
		if( trendDirection < 0-1 )
			{//We are in the trade (2nd day or later)
			if( High[i] > stopArray[i-1] )
				{//our stop got hit. Reset the trade.
				trendDirection = 0;
				exitArray[i] = 0-1;
				}
			else
				{//keep track of the LLV since trade was entered.
				if( Low[i] < LLArray[i-1] )
					LLArray[i] = Low[i];
				else
					LLArray[i] = LLArray[i-1];

				//Compute the stop based on the LLV.
				stopArray[i] = LLArray[i] + (Multiple * atrArray[i]);
				}
			}

		trendDirection = trendDirection-1;
		}

	if( trendDirection == 0 )
		{
		stopArray[i] = 0;
		LLArray[i] = 0;
		HHArray[i] = 0;
		}
}

PlotShapes( goingLong*shapeUpArrow, colorGreen, 0, Low );
PlotShapes( goingShort*shapeDownArrow, colorRed, 0, High );
PlotShapes( Abs(exitArray)*shapeHollowCircle, colorYellow, 0,
ValueWhen(stopArray, stopArray,1), 0 );
Plot( stopArray, "Chand", ParamColor( "Chand Color:", colorYellow ),
ParamStyle("Chand Style", styleDashed)  );
//_N(Title = "LLArray: " + LLArray + ", HHArray:" + HHArray +",
stopArray"+stopArray);
_SECTION_END();

Comments:

Dan
hidden [at] Hotmail.com
2009-06-07 04:07:06
Great work! very useful thanks.


About | Privacy | Terms of Use | Contact information
Copyright © 2001 AMIBROKER.COM