Ilmu Saham | ISX Stock Market Resource Center


Posted in Trading System, Useful Tools by ilmusaham on June 1, 2008

In “The Truth About Volatility,” Jim Berg presents how to use several well-known volatility measures such as average true range (ATR) to calculate entry, trailing stop, and profit-taking levels. Implementing techniques presented in the article is very simple using the AmiBroker Formula Language (Afl), and takes just a few lines of code.

Listing 1 shows the formula that the plots color-coded price chart, trailing stop, and profit-taking lines, as well as a colored ribbon showing volatility-based entry and exit signals. The relative strength index (RSI) used by Berg is a built-in indicator in AmiBroker, so no additional code is necessary. See Figure 3 for an example.


FIGURE: AMIBROKER, VOLATILITY SYSTEM. Here is a sample AmiBroker chart demonstrating the techniques from Jim Berg’s article in this issue.

EntrySignal = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) );
ExitSignal = C < ( HHV( H, 20 ) – 2 * ATR( 10 ) );
Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal, colorOrange, colorGrey50 ));
TrailStop = HHV( C – 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);
/* plot price chart and stops */
Plot( TrailStop, “Trailing stop”, colorBrown, styleThick | styleLine );
Plot( ProfitTaker, “Profit taker”, colorLime, styleThick );
Plot( C, “Price”, Color, styleBar | styleThick );

/* plot color ribbon */
Plot( 1, “”, Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );

–Tomasz Janeczko,

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: