January 28, 2016
How does risk-mode trailing stop work?
In addition to regular percent or point based stops, AmiBroker allows to define stop size as risk (stopModeRisk), which means that we allow only to give up certain percent of profit gained in given trade. The picture presented below visualizes a risk-mode trailing stop using 35% risk size. Since at the very beginning of the trade profits may be very low (and potentially triggering unwanted exits), this type of stop is best to use with validFrom argument, which allows to delay stop activation by certain number of bars.
The blue line on top represents highest high since entry, while red line shows the stop level calculation, yellow area shows the bars, where our stop has become active:
The above levels were calculated with the following code:
Buy = DateNum() == 1140425; // custom entry on a fixed date
Sell = 0;
BuyPrice = SellPrice = close;
riskSize = 35;
daysDelay = 50;
ApplyStop( stopTypeTrailing, stopModeRisk, riskSize, 1, False, 0, daysDelay );
Equity( 1 );
priceAtBuy = ValueWhen( Buy, BuyPrice );
highsinceBuy = HighestSince( Buy, High);
stoplevel = priceAtBuy + ( highsinceBuy - priceAtBuy) * (100-riskSize)/100;
Plot( Close, "Close", colorDefault, styleBar );
Plot( stoplevel, "stop", colorRed, styleDashed );
Plot( highsinceBuy, "highsinceBuy", colorBlue, styleDashed );
Plot( priceAtBuy, "priceAtBuy", colorBlue, styleDashed );
Plot( BarsSince( Buy ) > daysDelay, "", ColorBlend( colorYellow, colorWhite,0.9), styleArea|styleOwnScale,0,1,0,-1);
PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low);
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone), colorRed, 0, High)
Filed by Tomasz Janeczko at 6:45 am under Stops
Comments Off on How does risk-mode trailing stop work?