{"id":1244,"date":"2016-01-28T06:45:04","date_gmt":"2016-01-28T11:45:04","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=1244"},"modified":"2016-01-28T06:45:04","modified_gmt":"2016-01-28T11:45:04","slug":"how-does-risk-mode-trailing-stop-work","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2016\/01\/28\/how-does-risk-mode-trailing-stop-work\/","title":{"rendered":"How does risk-mode trailing stop work?"},"content":{"rendered":"

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<\/strong> argument, which allows to delay stop activation by certain number of bars.<\/p>

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:<\/p>

\"Risk-mode<\/p>

The above levels were calculated with the following code:<\/p>Buy <\/span>= <\/span>DateNum<\/span>() == <\/span>1140425<\/span>; <\/span>\/\/ custom entry on a fixed date
<\/span>Sell <\/span>= <\/span>0<\/span>;
<\/span>BuyPrice <\/span>= <\/span>SellPrice <\/span>= <\/span>close<\/span>;

<\/span>riskSize <\/span>= <\/span>35<\/span>;
<\/span>daysDelay <\/span>= <\/span>50<\/span>;

<\/span>ApplyStop<\/span>( <\/span>stopTypeTrailing<\/span>, <\/span>stopModeRisk<\/span>, <\/span>riskSize<\/span>, <\/span>1<\/span>, <\/span>False<\/span>, <\/span>0<\/span>, <\/span>daysDelay <\/span>);
<\/span>Equity<\/span>( <\/span>1 <\/span>);

<\/span>priceAtBuy <\/span>= <\/span>ValueWhen<\/span>( <\/span>Buy<\/span>, <\/span>BuyPrice <\/span>);
<\/span>highsinceBuy <\/span>= <\/span>HighestSince<\/span>( <\/span>Buy<\/span>, <\/span>High<\/span>);
<\/span>stoplevel <\/span>= <\/span>priceAtBuy <\/span>+ ( <\/span>highsinceBuy <\/span>- <\/span>priceAtBuy<\/span>) * (<\/span>100<\/span>-<\/span>riskSize<\/span>)\/<\/span>100<\/span>;

<\/span>Plot<\/span>( <\/span>Close<\/span>, <\/span>"Close"<\/span>, <\/span>colorDefault<\/span>, <\/span>styleBar <\/span>);
<\/span>Plot<\/span>( <\/span>stoplevel<\/span>, <\/span>"stop"<\/span>, <\/span>colorRed<\/span>, <\/span>styleDashed <\/span>);
<\/span>Plot<\/span>( <\/span>highsinceBuy<\/span>, <\/span>"highsinceBuy"<\/span>, <\/span>colorBlue<\/span>, <\/span>styleDashed <\/span>);
<\/span>Plot<\/span>( <\/span>priceAtBuy<\/span>, <\/span>"priceAtBuy"<\/span>, <\/span>colorBlue<\/span>, <\/span>styleDashed <\/span>);
<\/span>Plot<\/span>( <\/span>BarsSince<\/span>( <\/span>Buy <\/span>) > <\/span>daysDelay<\/span>, <\/span>""<\/span>, <\/span>ColorBlend<\/span>( <\/span>colorYellow<\/span>, <\/span>colorWhite<\/span>,<\/span>0.9<\/span>), <\/span>styleArea<\/span>|<\/span>styleOwnScale<\/span>,<\/span>0<\/span>,<\/span>1<\/span>,<\/span>0<\/span>,-<\/span>1<\/span>);

<\/span>PlotShapes<\/span>(<\/span>Buy<\/span>*<\/span>shapeUpArrow<\/span>, <\/span>colorGreen<\/span>, <\/span>0<\/span>, <\/span>Low<\/span>);
<\/span>PlotShapes<\/span>( <\/span>IIf<\/span>( <\/span>Sell<\/span>, <\/span>shapeDownArrow<\/span>, <\/span>shapeNone<\/span>), <\/span>colorRed<\/span>, <\/span>0<\/span>, <\/span>High<\/span>)<\/code>","protected":false},"excerpt":{"rendered":"

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 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[40],"tags":[15,77,78],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1244"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=1244"}],"version-history":[{"count":1,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1244\/revisions"}],"predecessor-version":[{"id":1246,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1244\/revisions\/1246"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=1244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=1244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=1244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}