SUPER TREND indicator by Olivier Seban coded for Amibroker (AFL)
In this blog I will share with you some of my software for quantitative trading. Actually I am using Amibroker 5.60, so this software is written in AFL (Amibroker Formula Language).
The first one is the indicator named SUPER TREND by Olivier Seban:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | function SuperTrend( Periods, Multiplier ) { AverageTrueRange = ATR( Periods ); MedianPrice = ( H + L ) / 2; UpBand = MedianPrice + Multiplier * AverageTrueRange; DnBand = MedianPrice - Multiplier * AverageTrueRange; ST = Null; Direction[0] = 1;//just to initialize for ( i = 1; i < BarCount; i++ ) { // Begin Direction calculation if ( Close[i] > UpBand[i-1] ) Direction[i] = 1; else if ( Close[i] < DnBand[i-1] ) Direction[i] = -1; else Direction[i] = Direction[i-1]; // End Direction calculation // Begin SuperTrend calculation if ( Direction[i] == 1 ) { if ( DnBand[i-1] > DnBand[i] ) DnBand[i] = DnBand[i-1]; ST[i] = DnBand[i]; } else if ( Direction[i] == -1 ) { if ( UpBand[i-1] < UpBand[i] ) UpBand[i] = UpBand[i-1]; ST[i] = UpBand[i]; } // End SuperTrend calculation } return ST; } |
To download the afl script click here.
If you want to have a SuperTrend charted with two colors, you can read "How to color an indicator"
If you find useful this post, please leave a comment, thank you
Comments
Post a Comment