Friday, March 15, 2013

Amibroker AFL Code For Donchian Channels

The Donchian channel is an indicator used in market trading developed by Richard Donchian. It is formed by taking the highest high and the lowest low of the last n periods. The area between the high and the low is the channel for the period chosen.

It is commonly available on most trading platforms. On a charting program, a line is marked for the high and low values visually demonstrating the channel on the markets price (or other) values.

The Donchian channel is a useful indicator for seeing the volatility of a market price. If a price is stable the Donchian channel will be relatively narrow. If the price fluctuates a lot the Donchian channel will be wider. Its primary use, however, is for providing signals for long and short positions.

If a security trades above its highest n periods high, then a long is established. If it trades below its lowest n periods low, then a short is established.
Originally the n periods were based upon daily values. With today's trading platforms, the period may be of the value desired by the investor. i.e.: day, hour, minute, ticks, etc.

Source: Wikipedia

In Amibroker a trader would not find the Donchian Channel AFL by default. The AFL code for Donchian Channel is mentioned below. You may copy and paste the code through the Formula Editor in the Amibroker Software. To see how the Donchian Channels look you may see the image below.
 
====================== Copy The Code From Below=====================

// Plots a 20 period Donchian channel

pds=20;
DonchianUpper =HHV(Ref(H,-1),pds);
DonchianLower = LLV(Ref(L,-1),pds);
DonchianMiddle = (DonchianUpper+DonchianLower)/2;


Plot(DonchianUpper,"DU",colorBlue,styleLine);
Plot(DonchianMiddle,"DM",colorGreen,styleLine);
Plot(DonchianLower,"DL",colorRed,styleLine);

=================================================================

3 comments:

  1. Replies
    1. Hi Mehul, You can search on YouTube , how to insert a custom code on a price chart in Amibroker. The process will be explained in the video. Also you can search how to add a custom code through Formula Editor in Amibroker. Writing down each step here will be lengthy.

      Delete

Required US Government Disclaimer & CTFC Rule 4.41

Futures trading contains substantial risk and is not suitable for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only consider risk capital that should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. CTFC RULE 4.41 – HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS SUCH AS LIQUIDITY. SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN. All trades, patterns, charts, systems, etc., discussed in this website or advertisement are for illustrative purposes only and not construed as specific advisory recommendations. All ideas and materials presented herein are for information and educational purposes only. No system or trading methodology has ever been developed that can guarantee profits or prevent losses. The testimonials and examples used herein are exceptional results which do not apply to average people and are not intended to represent or guarantee that anyone will achieve the same or similar results. Trades placed on the reliance of Trend Methods systems are taken at your own risk for your own account. This is not an offer to buy or sell futures interests.