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

Chandelier Exit Functions for Amibroker (AFL)
kaiji
almost 15 years ago
Amibroker (AFL)

Rating:
5 / 5 (Votes 1)
Tags:
amibroker, function

These are two functions that can be used to calculate the chandelier exit. This AFL is only the functions and does not plot anything.

By Geoff Mulhall

Similar Indicators / Formulas

Percent Rank
Submitted by genkumag almost 13 years ago
Time Left for each bar
Submitted by novicetraders over 14 years ago
Last Thursday Of The Month
Submitted by sahasra over 13 years ago
Visible Min and Max Value Demo
Submitted by kaiji almost 15 years ago
Adaptive Laguerre Filter from John Ehlers
Submitted by kaiji almost 15 years ago
Averages Functions Include
Submitted by demon about 14 years ago

Indicator / Formula

Copy & Paste Friendly
function ChandelierCl(AtrARRAY, AtrMult) {
	// Skip empty values
	i = 0;
	do {
		result[i] = Null;
		i++;
	} 
	while( i < BarCount AND (IsNull(O[i]) OR IsNull(H[i]) OR IsNull(L[i]) OR IsNull(C[i]) ) ); 
	First = i;

if (i < BarCount - 1) {
	HHC[First]    = C[First];
	LLC[First]    = C[First];

	if (C[First + 1] > HHC[First]) {
		HHC[First + 1] = C[First + 1];
		LLC[First + 1] = LLC[First];
		result[First] = C[First] - AtrMult * AtrARRAY[First];
		iTrade = "LT";
	}
	else {
		if (C[First + 1] < LLC[First]) {
			HHC[First = 1] = HHC[First];
			LLC[First + 1] = LLC[First + 1];
			result[First] = C[First] + AtrMult * AtrARRAY[First];
			iTrade = "ST";
		}
		else {
			HHC[First + 1] = C[First + 1];
			LLC[First + 1] = C[First + 1];
			result[First] = C[First] - AtrMult * AtrARRAY[First];
			iTrade = "LT";
		}
	}

	for( i = First; i < BarCount; i++ ) {
		if (iTrade == "LT") {
			if (C[i] >= result[i-1]) {        // Long Trade is continuing
				if (C[i] > C[i-1]) {
					HHC[i] = C[i];
				}
				else { 
					HHC[i] = HHC[i-1];
				}
				result[i] = HHC[i] - AtrMult * AtrARRAY[i];
				if (result[i] < result[i-1]) {
					result[i] = result[i-1];
				}
			}
			else {                            // Long trade Exit triggered
				iTrade = "ST";
				LLC[i] = C[i];
				result[i] = C[i] + AtrMult * AtrARRAY[i];
			}
		}
		else {                               // Short trade
			if (C[i] <= result[i-1]) {
				if (C[i] <= C[i-1]) {        // Short Trade is continuing
					LLC[i] = C[i];
				}
				else {
					LLC[i] = LLC[i-1];
				}
				result[i] = LLC[i] + AtrMult * AtrARRAY[i];
				if (result[i] > result[i-1]) {
					result[i] = result[i-1];
				}
			}
			else {                           //Short Trade Exit is triggered
				iTrade = "LT";
				HHC[i]  = C[i];
				result[i] = C[i] - AtrMult * AtrARRAY[i];
			}
		}
	}
}
return result;
}

function ChandelierHL(AtrARRAY, AtrMult) {
	// Skip empty values
	i = 0;
	do {
		result[i] = Null;
		i++;
	} 
	while( i < BarCount AND (IsNull(O[i]) OR IsNull(H[i]) OR IsNull(L[i]) OR IsNull(C[i]) ) ); 
	First = i;

if (i < BarCount - 1) {
	HHC[First]    = H[First];
	LLC[First]    = L[First];

	if (H[First + 1] > HHC[First]) {
		HHC[First + 1] = H[First + 1];
		LLC[First + 1] = LLC[First];
		result[First] = H[First] - AtrMult * AtrARRAY[First];
		iTrade = "LT";
	}
	else {
		if (L[First + 1] < LLC[First]) {
			HHC[First = 1] = HHC[First];
			LLC[First + 1] = LLC[First + 1];
			result[First] = L[First] + AtrMult * AtrARRAY[First];
			iTrade = "ST";
		}
		else {
			HHC[First + 1] = C[First + 1];
			LLC[First + 1] = C[First + 1];
			result[First] = H[First] - AtrMult * AtrARRAY[First];
			iTrade = "LT";
		}
	}

	for( i = First; i < BarCount; i++ ) {
		if (iTrade == "LT") {
			if (C[i] >= result[i-1]) {        // Long Trade is continuing
				if (H[i] > H[i-1]) {
					HHC[i] = H[i];
				}
				else { 
					HHC[i] = HHC[i-1];
				}
				result[i] = HHC[i] - AtrMult * AtrARRAY[i];
				if (result[i] < result[i-1]) {
					result[i] = result[i-1];
				}
			}
			else {                            // Long trade Exit triggered
				iTrade = "ST";
				LLC[i] = L[i];
				result[i] = L[i] + AtrMult * AtrARRAY[i];
			}
		}
		else {                               // Short trade
			if (C[i] <= result[i-1]) {
				if (L[i] <= L[i-1]) {        // Short Trade is continuing
					LLC[i] = L[i];
				}
				else {
					LLC[i] = LLC[i-1];
				}
				result[i] = LLC[i] + AtrMult * AtrARRAY[i];
				if (result[i] > result[i-1]) {
					result[i] = result[i-1];
				}
			}
			else {                           //Short Trade Exit is triggered
				iTrade = "LT";
				HHC[i]  = H[i];
				result[i] = H[i] - AtrMult * AtrARRAY[i];
			}
		}
	}
}
return result;
}

0 comments

Leave Comment

Please login here to leave a comment.

Back