How to plot simple trailing stoploss of fixed points

#21
| Chandelier (I do not know what that means) and
.........


My guess is that Chandelier is a person's name. Generally very fancy lighting (with lotsa bulbs or candles) in centre of big rooms is also called chandelier, but there seems to be no connection between this stop loss idea and lighting, so name is more likely to be true.

:D you actually got it right,but funny that you don't believe its true, its the lights . . . . :lol:




the connection . . .


As these fancy lights hang from the ceiling, at a fixed distance . . .

The Chandelier Exits are designed to get you out of the trades at a fixed distance from ceiling (HHV or LLV)

The logic being, its not worth to be in the trade after a certain point of price retrace, assuming the trend is now broken. . .

Cheers
 

jahan

Well-Known Member
#22
:D you actually got it right,but funny that you don't believe its true, its the lights . . . . :lol:




the connection . . .


As these fancy lights hang from the ceiling, at a fixed distance . . .

The Chandelier Exits are designed to get you out of the trades at a fixed distance from ceiling (HHV or LLV)

The logic being, its not worth to be in the trade after a certain point of price retrace, assuming the trend is now broken. . .

Cheers
Hello,

Ur Absolutely right its the Indicator name .....not the devoloper's name...the chandelier exit is developed by Charles Le Beau.

Regards,
 

manojborle

Well-Known Member
#23
Okay. Here is working code. I have used Short /Cover for cross of trailing Stop.
Buy/ Sell can be your preferred logic. Four type of stops can be used and set in Parameters. Buy/Sell Price and Stop Price also can be plotted.
Though I have not checked the prices being displayed.

//Stopeloss Code

StopMode = ParamList("Stop Mode", "FixPoints|FixedPercent|Chandelier|Modified ATR" );
StopLevel = Param("Fixed perc %", 1, 0.1, 5, 0.1)/100;
FixedSL = Param("FixSL", 40,1,1,100);
StopATRFactor = k;
StopATRPeriod = Per;


// calculate support and resistance levels
if( StopMode == "FixedPercent" ) // fixed percent trailing stop
{
sup = C * (1- StopLevel);
res = C * (1+ StopLevel);
}
else // Chandelier ATR-based stop
if( StopMode == "Chandelier" )
{
sup = C - StopATRFactor * ATR( StopATRPeriod );
res = C + StopATRFactor * ATR( StopATRPeriod );
}
else
if ( StopMode == "Modified ATR" )
{
HL = H - L;
MAHL = 1.5 * MA( HL, StopATRPeriod );
HiLo = IIf( HL < MAHL, HL, MAHL );
H1 = Ref( H, -1 );
L1 = Ref( L, -1 );
C1 = Ref( C, -1 );
Href = IIf( L <= H1, H - C1, ( H - C1 ) - ( L - H1 ) / 2 );
Lref = IIf( H >= L1, C1 - L, ( C1 - L ) - ( L1 - H ) / 2 );

diff1 = Max( HiLo, HRef );
diff2 = Max( diff1, LRef );

ATRmod = Wilders( diff2, StopATRPeriod );

sup = C - StopATRFactor * ATRmod ;
res = C + StopATRFactor * ATRmod ;
}

else
if ( StopMode == "FixPoints" )
{
ApplyStop( stopTypeTrailing, mode = 1, amount = FixedSL, exitatstop = 1, volatile = True, ReEntryDelay = 0 ) ;
sup = H - FixedSL;
res = L + FixedSL ;
}

Equity( 1, 0 ); // evaluate stops, all quotes
// calculate trailing stop line
trailARRAY = Null;
trailstop = 0;
for( i = 1; i < BarCount; i++ )
{
//if( Started[ i ] == 0 ) continue;

if( C[ i ] > trailstop AND C[ i - 1 ] > trailstop )
trailstop = Max( trailstop, sup[ i ] );
else
if( C[ i ] < trailstop AND C[ i - 1 ] < trailstop )
trailstop = Min( trailstop, res[ i ] );
else
trailstop = IIf( C[ i ] > trailstop, sup[ i ], res[ i ] );

trailARRAY[ i ] = trailstop;
}

// generate buy/sell signals based on crossover with trail stop line
Cover = Cross( C, trailArray );
Short = Cross( trailArray, C );

PlotShapes(Cover*shapeUpArrow,colorYellow,0,trailarray);
PlotShapes(Short*shapeDownArrow,colorYellow,0,trailarray);

//Plot( Close,"Price",colorBlack,styleBar);
//SetBarFillColor( colorYellow );

TRAILCOLOR =IIf(C>trailARRAY,colorAqua,colorYellow);
Plot( trailARRAY,"trailing stop level", TRAILCOLOR, styleStaircase );

//New Code End

Buy = Your Buy Logic ;
Sell = Your Sell Logic;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
BuyPrice = C; // Substitute your own prices
SellPrice = C; // Substitute your own prices

//dist = 1.5*ATR(15);
for( i = 0; i < BarCount; i++ )
{
if( Cover ) PlotText( "Cover@" + C[ i ], i, Halow-31, colorSkyblue );
AlertIf(Buy, "SOUND H:\\AMIBROKER\\Sound\\ding.WAV", "Audio Alert", 1);
if( Short ) PlotText( "Short@" +C[ i ], i, Hahigh+31, colorRose );
AlertIf(Sell, "SOUND H:\\AMIBROKER\\Sound\\tada.WAV", "Sell", 3);
//if( Sell ) PlotText( "Sell@" +H[ i ], i-4, H[ i ]+Trend+50, colorRed, colorRose );
if( Buy ) PlotText("\n Buy\n "+NumToStr(BuyPrice,1.2),i,BuyPrice-10,colorAqua);
if( Sell ) PlotText("\n Sell\n "+NumToStr(SellPrice,1.2),i,SellPrice+30,colorYellow);

}

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,Halow,-30);
PlotShapes(IIf(Sell, shapeHollowDownTriangle, shapeNone),colorWhite, 0,Hahigh,-15);
PlotShapes(IIf(Cover, shapeHollowUpTriangle, shapeNone),colorWhite, 0,Halow,-15);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,Hahigh,-30);
PlotShapes( IIf(Buy, shapeSmallCircle, shapeNone),colorRed, 0, BuyPrice, 0 );
PlotShapes( IIf( Sell, shapeSmallCircle, shapeNone),colorBrightGreen, 0 ,SellPrice, 0 );
PlotShapes(Buy*shapeUpArrow,colorYellow,0,trailarray);
PlotShapes(Sell*shapeDownArrow,colorYellow,0,trailarray);

// Plot the Trade Lines
Sig = Buy OR Sell;
y0 = 0;
y1 = C[0];
FirstVisibleBar = Status( "FirstVisibleBar" );
Lastvisiblebar = Status( "LastVisibleBar" );
CombinedColor = colorWhite;
CombinedLine = Null;

for ( b = Firstvisiblebar; b <= Lastvisiblebar AND b < BarCount; b++ )
{

if ( Buy )
{
Co = colorRed;
TPrice = BuyPrice;
}
else if ( Sell )
{
Co = colorBrightGreen;
TPrice = SellPrice;
}

if ( Sig )

{

x0 = y0;

x1 = y1;

y0 = b;

y1 = TPrice;

La = LineArray( x0, x1, y0, y1 );

CombinedLine = IIf( IsNull( la ), CombinedLine, la );
CombinedColor = IIf( IsNull( La ), CombinedColor, Co );
}
}

Plot( CombinedLine, "", CombinedColor );


Here k and per are not defined earlier so it is showing error
 
#24
I was trying to include Fixed point Stop in below code to get options for Stoploss mode. Below code is not complete. It has bugs in it. Mastermind may be able to complete it faster.

//Stopeloss Code

StopMode = ParamList("Stop Mode", "Points|Fixed|Chandelier|Modified ATR" );
StopLevel = Param("Fixed perc %", 1, 0.1, 5, 0.1)/100;
StopATRFactor = k;
StopATRPeriod = Per;


// calculate support and resistance levels
if( StopMode == "Fixed" ) // fixed percent trailing stop
ApplyStop( stopTypeLoss, mode = 1, amount = stoplevel, exitatstop = 1, volatile = False, ReEntryDelay = 0 ) ;
else // Chandelier ATR-based stop
if( StopMode == "Chandelier" )
{
sup = C - StopATRFactor * ATR( StopATRPeriod );
res = C + StopATRFactor * ATR( StopATRPeriod );
}
else
if ( StopMode == "Modified ATR" )
{
HL = H - L;
MAHL = 1.5 * MA( HL, StopATRPeriod );
HiLo = IIf( HL < MAHL, HL, MAHL );
H1 = Ref( H, -1 );
L1 = Ref( L, -1 );
C1 = Ref( C, -1 );
Href = IIf( L <= H1, H - C1, ( H - C1 ) - ( L - H1 ) / 2 );
Lref = IIf( H >= L1, C1 - L, ( C1 - L ) - ( L1 - H ) / 2 );

diff1 = Max( HiLo, HRef );
diff2 = Max( diff1, LRef );

ATRmod = Wilders( diff2, StopATRPeriod );

sup = C - StopATRFactor * ATRmod ;
res = C + StopATRFactor * ATRmod ;
}

else
if ( StopMode == "Points" )
{
ApplyStop( stopTypeTrailing, mode = 1, amount = 40, exitatstop = 1, volatile = True, ReEntryDelay = 0 ) ;
sup = H - 40;
res = L + 40 ;
}

Equity( 1, 0 ); // evaluate stops, all quotes
// calculate trailing stop line
trailARRAY = Null;
trailstop = 0;
for( i = 1; i < BarCount; i++ )
{
//if( Started[ i ] == 0 ) continue;

if( C[ i ] > trailstop AND C[ i - 1 ] > trailstop )
trailstop = Max( trailstop, sup[ i ] );
else
if( C[ i ] < trailstop AND C[ i - 1 ] < trailstop )
trailstop = Min( trailstop, res[ i ] );
else
trailstop = IIf( C[ i ] > trailstop, sup[ i ], res[ i ] );

trailARRAY[ i ] = trailstop;
}

// generate buy/sell signals based on crossover with trail stop line
Cover = Cross( C, trailArray );
Short = Cross( trailArray, C );

PlotShapes(Cover*shapeUpArrow,colorYellow,0,trailarray);
PlotShapes(Short*shapeDownArrow,colorYellow,0,trailarray);

//Plot( Close,"Price",colorBlack,styleBar);
//SetBarFillColor( colorYellow );

TRAILCOLOR =IIf(C>trailARRAY,colorAqua,colorYellow);
Plot( trailARRAY,"trailing stop level", TRAILCOLOR, styleStaircase );

//New Code End


Lots of error in your code Josh
 

mastermind007

Well-Known Member
#25
:D you actually got it right,but funny that you don't believe its true, its the lights . . . . :lol:

the connection . . .

As these fancy lights hang from the ceiling, at a fixed distance . . .

The Chandelier Exits are designed to get you out of the trades at a fixed distance from ceiling (HHV or LLV)

The logic being, its not worth to be in the trade after a certain point of price retrace, assuming the trend is now broken. . .

Cheers
:clap::clapping::clap::clapping:

http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:chandelier_exit

People's imaginations!!!
 
Last edited:

mastermind007

Well-Known Member
#26
josh

Check this out ....

For rest of you who are just waiting for code .... This is not complete!!!

Code:
	StopMode = ParamList("Stop Mode", "Points|Fixed|Chandelier|Modified ATR" );
	StopLevel = Param("Fixed perc %", 2, 0.1, 50, 0.1)/100; 
[COLOR="Yellow"][B]	StopATRFactor = Param("Chandelier ATR multiple", 4, 0.5, 10, 0.1 ); 
	StopATRPeriod = Param("Chandelier ATR period", 14, 3, 50 ); 
[/B]
[/COLOR]	// calculate support and resistance levels 
	if( StopMode == "Fixed" ) // fixed percent trailing stop 
	{
[COLOR="yellow"][B]		ApplyStop( stopTypeLoss, stopModePercent, StopLevel, 1, False, 0 ) ;
[/B][/COLOR]		sup = C * ( 1 - stoplevel ); 
		res = C * ( 1 + stoplevel ); 
	} else // Chandelier ATR-based stop
	if( StopMode == "Chandelier" )
	{
[COLOR="yellow"][B]		ApplyStop( stopTypeTrailing, stopModePoint, 
			StopATRFactor*ATR(StopATRPeriod), True, True  ) ;
		sup = C - StopATRFactor * ATR( StopATRPeriod );
		res = C + StopATRFactor * ATR( StopATRPeriod );
[/B][/COLOR]	} else
	if ( StopMode == "Modified ATR" )
	{
               [COLOR="yellow"] /// Needs to be tested.... [/COLOR]
		HL = H - L;
		MAHL = 1.5 * MA( HL, StopATRPeriod );
		HiLo = IIf( HL < MAHL, HL, MAHL );
		H1 = Ref( H, -1 );
		L1 = Ref( L, -1 );
		C1 = Ref( C, -1 );
		Href = IIf( L <= H1, H - C1, ( H - C1 ) - ( L - H1 ) / 2 );
		Lref = IIf( H >= L1, C1 - L, ( C1 - L ) - ( L1 - H ) / 2 );

		diff1 = Max( HiLo, HRef );
		diff2 = Max( diff1, LRef );

		ATRmod = Wilders( diff2, StopATRPeriod );

		sup = C - StopATRFactor * ATRmod ;
		res = C + StopATRFactor * ATRmod ;

[COLOR="yellow"][B]		ApplyStop( stopTypeTrailing, stopModePoint, 
			StopATRFactor*ATRmod, True, True  ) ;
[/B][/COLOR]	} else
	if ( StopMode == "Points" )
	{
[B]		ApplyStop( stopTypeTrailing, stopModePoint, 40, 1, True, 0 ) ;
[/B]		sup = H - 40;
		res = L + 40 ;
	}
 

josh1

Well-Known Member
#28
Here k and per are not defined earlier so it is showing error
Lots of error in your code Josh
Sorry guys,

You can use this given by Mastermind.

StopATRFactor = Param("Chandelier ATR multiple", 4, 0.5, 10, 0.1 );
StopATRPeriod = Param("Chandelier ATR period", 14, 3, 50 );

Or .............you can insert these definition of k and Per in the beginning -
k = Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);
Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);

Or ........ use Combination of above
StopATRFactor = Optimize("StopATRFactor",Param("StopATRFactor",1.75,1,5,0.25),1,5,0.25);
StopATRPeriod= Optimize("StopATRPeriod",Param("StopATRPeriod",10,3,30,1),3,30,1);

I have not fully understood what "Optimize" does.
 

manojborle

Well-Known Member
#29
Sorry guys,

You can use this given by Mastermind.

StopATRFactor = Param("Chandelier ATR multiple", 4, 0.5, 10, 0.1 );
StopATRPeriod = Param("Chandelier ATR period", 14, 3, 50 );

Or .............you can insert these definition of k and Per in the beginning -
k = Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);
Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);

Or ........ use Combination of above
StopATRFactor = Optimize("StopATRFactor",Param("StopATRFactor",1.75,1,5,0.25),1,5,0.25);
StopATRPeriod= Optimize("StopATRPeriod",Param("StopATRPeriod",10,3,30,1),3,30,1);

I have not fully understood what "Optimize" does.
Optimize function will find out the value from your given range where you will have maximum profit
 

josh1

Well-Known Member
#30
Backtesting is however, giving funny results. Now there are different points at which Buy/Sell/Cover/Short will signal. Backtester gives only Long and Short. Is it possible to add a column in Backtester to reveal which signal is initiating which trade?
 

Similar threads