Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Triangular Moving Average for Amibroker (AFL)

Rating:
3 / 5 (Votes 4)
Tags:
amibroker

This is an ordinary afl but it’s work very good indeed.

A Triangular moving average is similar to exponential AND
weighted moving averages except A different weighting scheme
is used. Exponential AND Weighted averages assign the majority
of the weight to the most recent data. Simple moving averages
assign the weight equally across all the data. With A Triangular
moving average, the majority of the weight is assigned to the middle
portion of the data

Screenshots

Similar Indicators / Formulas

Kavach Of Karna v2
Submitted by hbkwarez over 10 years ago
Advanced Elliott Waves
Submitted by MarcosEn over 13 years ago
3_6Day GuaiLiLv
Submitted by motorfly over 13 years ago
Williams Alligator System
Submitted by durgesh1712 over 13 years ago
*Level Breakout system*
Submitted by Tinych over 13 years ago
Horizontal Live Priceline Tool
Submitted by northstar over 13 years ago

Indicator / Formula

Copy & Paste Friendly
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
//------------------------------------------------------------------------------
//
//  Formula Name:    Triangular Moving Average
//  Author/Uploader: Foyej Ahmed Khan
//  E-mail:          foyej.ahmed@gmail.com
//  Date/Time Added: 2012
//
//------------------------------------------------------------------------------
//
//  //Triangular Moving average-Suparnova
//
//  //Anthony Faragasso
//
//  //june, 2012
//
//  /* A Triangular moving average is similar to exponential AND
//
//  weighted moving averages except A different weighting scheme
//
//  is used. Exponential AND Weighted averages assign the majority
//
//  of the weight to the most recent data. Simple moving averages
//
//  assign the weight equally across all the data. With A Triangular
//
//  moving average, the majority of the weight is assigned to the middle
//
//  portion of the data.*/
//
//  Odd=13;//enter Odd numbers only
//
//  CoefOdd=round(Odd/2);
//
//  Even=12;//enter Even numbers only
//
//  Coefeven=Even/2;
//
//  Coefeven2=Coefeven+1;
//
//  CongestionPercent=2.8;/*Set % above/below Moving average for congestion /
//  sideways market*/
//
//  TriangularOdd=MA(MA(C,CoefOdd),CoefOdd);
//
//  TriangularEven=MA(MA(C,Coefeven),Coefeven2);
//
//  finalMov_avg=IIf(Odd > even,triangularOdd,TriangularEven);
//
//  Color=colorBrightGreen;//select Moving average line color
//
//  tickercolor=colorBlack;//select price color
//
//  Plot(finalMov_avg,"",IIf(C <
//  finalmov_avg,colorRed,Color),styleLine|styleThick);
//
//  Plot(C,"",tickercolor,styleCandle);
//
//  Title=Name()+"..."+"( "+WriteIf(Odd >
//  even,WriteVal(Odd,1),WriteVal(even,1))+" ) Period
//  "+EncodeColor(Color)+"Triangular"+WriteIf(Odd > even,"ODD","EVEN")+" Moving
//  Average"+"..."+EncodeColor(colorBlack)+ WriteIf(C < finalMov_avg,"Close is
//  "+EncodeColor(colorRed)+"Below"+EncodeColor(colorBlack)+" Moving Average by
//  ","Close is"+EncodeColor(colorBrightGreen)+"
//  Above"+EncodeColor(colorBlack)+" Moving Average by
//  ")+"("+WriteVal(((C/finalMov_avg)-1)*100,1.1)+"%
//  )"+"\n"+WriteIf(finalmov_avg-Ref(finalmov_avg,-1)>0," Slope Of Average is
//  UP : ","Slope Of Average is DOWN :")+WriteIf((((C/finalMov_avg)-1)*100 <=
//  CongestionPercent AND ((C/finalMov_avg)-1)*100 >=
//  -CongestionPercent),EncodeColor(colorYellow)+" with Price Congestion /
//  Divergence to Average ","")+"\n"+WriteIf(Ref(C,-1) < Ref(finalmov_avg,-1)
//  AND C > finalmov_avg,EncodeColor(colorGreen)+"Possible Change in Trend From
//  Down to Up"+"\n"+" OR Short Term Correction of Previous
//  Trend",WriteIf(Ref(C,-1) > Ref(finalmov_avg,-1) AND C <
//  finalmov_avg,EncodeColor(colorRed)+"Possible Change in Trend From Up to
//  Down "+"\n"+" OR Short Term Correction to Previous
//  Trend",""))+"\n"+WriteIf(C > finalmov_avg,EncodeColor(colorGreen)+"Close
//  has been above Moving Average ( "+WriteVal(BarsSince(C < finalmov_avg),1)+"
//  ) Bars",EncodeColor(colorRed)+"Close has been Below Moving Average (
//  "+WriteVal(BarsSince(C > finalmov_avg),1)+" )
//  Bars")+"\n"+EncodeColor(colorBlack)+"The average # of Bars Above (
//  "+WriteVal(round(Cum(BarsSince(C < finalmov_avg)/Cum(1))),1)+" )"+"\n"+"The
//  average # of Bars Below ( "+WriteVal(round(Cum(BarsSince(C >
//  finalmov_avg)/Cum(1))),1)+" )";
//
//  _SECTION_BEGIN("AFL Example");
//
//  /*
//
//  This is an attempt to provide a basic trading system AFL. The system is
//  purely imaginary
//
//  AND NOT provided as one that would make money. This is just to provide a
//  guide to learners
//
//  on the common components of writing AFL.
//
//  Prepared by Graham Kavanagh 12 Aug 2005
//
//  AB Write http://e-wire.net.au/~eb_kavan/ab_write.htm
//
//  When you copy/paste ensure the existing continuous lines have not been
//  wrapped. This wrapping
//
//  can create error signals when you try to use the code. Click on the check
//  afl button in the
//
//  editor before trying to apply or scan.
//
//  I have used slash-asterisk /* */ /* for my comments to get around the
//  problem of wrapping,
//
//  which could happen if you used double slash //
//
//  I hope this helps the beginners in creating AFL code
//
//  */
//
//  /*firstly some basics common*/
//
//  SetBarsRequired(10000,10000); /* this ensures that the charts include all
//  bars AND NOT just those on screen */
//
//  SetFormulaName("Sample System"); /*name it for backtest report
//  identification */
//
//  SetTradeDelays( 1, 1, 1, 1 ); /* delay entry/exit by one bar */
//
//  SetOption( "initialequity", 100000 ); /* starting capital */
//
//  PositionSize = -10; /* trade size will be 10% of available equty */
//
//  SetOption( "MaxOpenPositions", 6 ); /* I don't want to comit more than 60%
//  of Equity at any one time */
//
//  SetOption( "PriceBoundChecking", 1 ); /* trade only within the chart bar's
//  price range */
//
//  SetOption( "CommissionMode", 2 ); /* set commissions AND costs as $ per
//  trade */
//
//  SetOption( "CommissionAmount", 32.95 ); /* commissions AND cost */
//
//  SetOption( "UsePrevBarEquityForPosSizing", 1 ); /*set the use of last bars
//  equity for trade size*/
//
//  PositionScore = 100/C; /*Set the order for which stock trades when get
//  mulitple signals in one bar in backtesting */
//
//  //Trade system
//
//  /*
//
//  Buy when exp mov avg crosses and the high is highest for 50 bars
//
//  Sell when exp mov avg crosses back
//
//  Cross is first variable moves to above the second variable
//
//  */
//
//  LongPer = Param("Long Period", 50, 30, 100, 5 ); /* select periods with
//  parameter window */
//
//  ShortPer = Param("Short Period", 5, 3, 10, 1 );
//
//  LongMA = EMA( C, LongPer );
//
//  ShortMA = EMA( C, ShortPer );
//
//  LastHigh = HHV( H, LongPer );
//
//  Buy = Cross( ShortMA, LongMA ) AND H > Ref( LastHigh, -1 );
//
//  /* ref,-1 is used for the high to have todays high greater than the
//  previous 50 bar high.
//
//  To just use H==LastHigh couold mean a previous high was equal to current
//  high */
//
//  Sell = Cross( LongMA, ShortMA );
//
//  /* exrem is one method to remove surplus strade signals*/
//
//  Buy = ExRem(Buy,Sell);
//
//  Sell = ExRem(Sell,Buy);
//
//  /* Now for exploration results.
//
//  Will restrict results of exploration to when the Buy AND Sell signals occur
//
//  You can use Filter=1; to display every bar result */
//
//  Filter = Buy OR Sell;
//
//  AddTextColumn( FullName(), "Company Name" );
//
//  AddColumn( Buy, "Buy", 1 );
//
//  AddColumn( Sell, "Sell", 1 );
//
//  AddColumn( C, "Close", 1.3 );
//
//  AddColumn( H, "High", 1.3 );
//
//  AddColumn( LastHigh, "HHV", 1.3 );
//
//  AddColumn( LongMA, "Long MA", 1,3 );
//
//  AddColumn( ShortMA, "Short MA", 1,3 );
//
//  /* Now to show this on a chart */
//
//  /* I use WriteVal to limit the values to the wanted number of decimal
//  places,
//
//  seeing a value of 5 decimal places can be frustrating.
//
//  I have included additional information in the plot title sections to add
//  some
//
//  information to the title block */
//
//  GraphXSpace = 10; /* create empty space of 10% top and bottom of chart */
//
//  Plot( C, " Close Price", colorGrey50, styleBar );
//
//  Plot( LongMA, " EMA(C,"+WriteVal(LongPer,1)+")", colorYellow,
//  styleLine|styleNoRescale );
//
//  Plot( ShortMA, " EMA(C,"+WriteVal(ShortPer,1)+")", colorblue,
//  styleLine|styleNoRescale );
//
//  Plot( Ref(Lasthigh,-1), " HHV(H,"+WriteVal(LongPer,1)+")", colorRed,
//  styleNoLine|styleDots|styleNoRescale );
//
//  /* styleNoRescale in the plots stops the added plots from compressing the
//  original bar chart to the middle of the pane */
//
//  PlotShapes( shapeUpArrow*Buy, colorGreen, 0, L, -10 );
//
//  PlotShapes( shapeDownArrow*Sell, colorRed, 0, H, -10 );
//
//  Title = " {{NAME}} {{DATE}} {{INTERVAL}} "+_DEFAULT_NAME()+" Chart values :
//  {{VALUES}} ";
//
//  /* _DEFAULT_NAME() shows the section name or, if not present, the file name
//
//  the items in {{}} are short cuts for the title block. It can be done long
//  hand
//
//  Title = Name() +" "+ Date() +" "+ "{{INTERVAL}}"+_DEFAULT_NAME()+" Chart
//  values : " +
//
//  " Close Price = " + C +
//
//  " EMA(C,"+WriteVal(LongPer,1)+") = "+WriteVal(LongMA,1.3) +
//
//  " EMA(C,"+WriteVal(ShortPer,1)+") = "+WriteVal(ShortMA,1.3) +
//
//  " HHV(H,"+WriteVal(LongPer,1)+") = "+WriteVal(Ref(LastHigh,-1),1.3) ;
//
//  */
//
//  _SECTION_END();
//
//------------------------------------------------------------------------------
 
//Triangular Moving average
//Anthony Faragasso
//December, 2002
 
/* A Triangular moving average is similar to exponential AND
weighted moving averages except A different weighting scheme
is used. Exponential AND Weighted averages assign the majority
of the weight to the most recent data. Simple moving averages
assign the weight equally across all the data. With A Triangular
moving average, the majority of the weight is assigned to the middle
portion of the data.*/
 
Odd=13;//enter Odd numbers only
CoefOdd=round(Odd/2);
 
Even=12;//enter Even numbers only
Coefeven=Even/2;
Coefeven2=Coefeven+1;
 
CongestionPercent=2.8;/*Set % above/below Moving average for congestion / sideways market*/
 
TriangularOdd=MA(MA(C,CoefOdd),CoefOdd);
TriangularEven=MA(MA(C,Coefeven),Coefeven2);
 
finalMov_avg=IIf(Odd > even,triangularOdd,TriangularEven);
 
Color=colorBrightGreen;//select Moving average line color
tickercolor=colorBlack;//select price color
 
Plot(finalMov_avg,"",IIf(C < finalmov_avg,colorRed,Color),styleLine|styleThick);
Plot(C,"",tickercolor,styleCandle);
 
Title=Name()+"..."+"( "+WriteIf(Odd > even,WriteVal(Odd,1),WriteVal(even,1))+" ) Period "+EncodeColor(Color)+"Triangular"+WriteIf(Odd > even,"ODD","EVEN")+" Moving Average"+"..."+EncodeColor(colorBlack)+ WriteIf(C < finalMov_avg,"Close is "+EncodeColor(colorRed)+"Below"+EncodeColor(colorBlack)+" Moving Average by ","Close is"+EncodeColor(colorBrightGreen)+" Above"+EncodeColor(colorBlack)+" Moving Average by ")+"("+WriteVal(((C/finalMov_avg)-1)*100,1.1)+"% )"+"\n"+WriteIf(finalmov_avg-Ref(finalmov_avg,-1)>0," Slope Of Average is UP : ","Slope Of Average is DOWN :")+WriteIf((((C/finalMov_avg)-1)*100 <= CongestionPercent AND ((C/finalMov_avg)-1)*100 >= -CongestionPercent),EncodeColor(colorYellow)+" with Price Congestion / Divergence to Average ","")+"\n"+WriteIf(Ref(C,-1) < Ref(finalmov_avg,-1) AND C > finalmov_avg,EncodeColor(colorGreen)+"Possible Change in Trend From Down to Up"+"\n"+" OR Short Term Correction of Previous Trend",WriteIf(Ref(C,-1) > Ref(finalmov_avg,-1) AND C < finalmov_avg,EncodeColor(colorRed)+"Possible Change in Trend From Up to Down "+"\n"+" OR Short Term Correction to Previous Trend",""))+"\n"+WriteIf(C > finalmov_avg,EncodeColor(colorGreen)+"Close has been above Moving Average ( "+WriteVal(BarsSince(C < finalmov_avg),1)+" ) Bars",EncodeColor(colorRed)+"Close has been Below Moving Average ( "+WriteVal(BarsSince(C > finalmov_avg),1)+" ) Bars")+"\n"+EncodeColor(colorBlack)+"The average # of Bars Above ( "+WriteVal(round(Cum(BarsSince(C < finalmov_avg)/Cum(1))),1)+" )"+"\n"+"The average # of Bars Below ( "+WriteVal(round(Cum(BarsSince(C > finalmov_avg)/Cum(1))),1)+" )";
_SECTION_BEGIN("AFL Example");
/*
This is an attempt to provide a basic trading system AFL. The system is purely imaginary
 AND NOT provided as one that would make money. This is just to provide a guide to learners
 on the common components of writing AFL.
 
 Prepared by Graham Kavanagh 12 Aug 2005
 AB Write http://e-wire.net.au/~eb_kavan/ab_write.htm
 
When you copy/paste ensure the existing continuous lines have not been wrapped. This wrapping
 can create error signals when you try to use the code. Click on the check afl button in the
 editor before trying to apply or scan.
 I have used slash-asterisk /*  */ /* for my comments to get around the problem of wrapping,
 which could happen if you used double slash //
 
I hope this helps the beginners in creating AFL code
 
*/
 
/*firstly some basics common*/
SetBarsRequired(10000,10000); /* this ensures that the charts include all bars AND NOT just those on screen */
SetFormulaName("Sample System"); /*name it for backtest report identification */
SetTradeDelays( 1, 1, 1, 1 ); /* delay entry/exit by one bar */
SetOption( "initialequity", 100000 ); /* starting capital */
PositionSize = -10; /* trade size will be 10% of available equty */
SetOption( "MaxOpenPositions", 6 ); /* I don't want to comit more than 60% of Equity at any one time */
SetOption( "PriceBoundChecking", 1 ); /* trade only within the chart bar's price range */
SetOption( "CommissionMode", 2 ); /* set commissions AND costs as $ per trade */
SetOption( "CommissionAmount", 32.95 ); /* commissions AND cost */
SetOption( "UsePrevBarEquityForPosSizing", 1 ); /*set the use of last bars equity for trade size*/
PositionScore = 100/C; /*Set the order for which stock trades when get mulitple signals in one bar in backtesting */
 
//Trade system
/*
Buy when exp mov avg crosses and the high is highest for 50 bars
Sell when exp mov avg crosses back
Cross is first variable moves to above the second variable
*/
 
LongPer = Param("Long Period", 50, 30, 100, 5 ); /* select periods with parameter window */
ShortPer = Param("Short Period", 5, 3, 10, 1 );
 
LongMA = EMA( C, LongPer );
ShortMA = EMA( C, ShortPer );
LastHigh = HHV( H, LongPer );
 
Buy = Cross( ShortMA, LongMA ) AND H > Ref( LastHigh, -1 );
/* ref,-1 is used for the high to have todays high greater than the previous 50 bar high.
   To just use H==LastHigh couold mean a previous high was equal to current high */
Sell = Cross( LongMA, ShortMA );
/* exrem is one method to remove surplus strade signals*/
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
 
 
/* Now for exploration results.
   Will restrict results of exploration to when the Buy AND Sell signals occur
   You can use Filter=1; to display every bar result */
 
Filter = Buy OR Sell;
AddTextColumn( FullName(), "Company Name" );
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );
AddColumn( LastHigh, "HHV", 1.3 );
AddColumn( LongMA, "Long MA", 1,3 );
AddColumn( ShortMA, "Short MA", 1,3 );
 
 
/* Now to show this on a chart */
/* I use WriteVal to limit the values to the wanted number of decimal places,
   seeing a value of 5 decimal places can be frustrating.
   I have included additional information in the plot title sections to add some
   information to the title block */
 
GraphXSpace = 10; /* create empty space of 10% top and bottom of chart */
 
Plot( C, " Close Price", colorGrey50, styleBar );
Plot( LongMA, " EMA(C,"+WriteVal(LongPer,1)+")", colorYellow, styleLine|styleNoRescale );
Plot( ShortMA, " EMA(C,"+WriteVal(ShortPer,1)+")", colorBlue, styleLine|styleNoRescale );
Plot( Ref(Lasthigh,-1), " HHV(H,"+WriteVal(LongPer,1)+")", colorRed, styleNoLine|styleDots|styleNoRescale );
 
/* styleNoRescale in the plots stops the added plots from compressing the original bar chart to the middle of the pane */
 
PlotShapes( shapeUpArrow*Buy, colorGreen, 0, L, -10 );
PlotShapes( shapeDownArrow*Sell, colorRed, 0, H, -10 );
 
Title = " {{NAME}} {{DATE}} {{INTERVAL}} "+_DEFAULT_NAME()+" Chart values : {{VALUES}} ";
/* _DEFAULT_NAME() shows the section name or, if not present, the file name
the items in {{}} are short cuts for the title block. It can be done long hand
 
Title = Name() +" "+ Date() +" "+ "{{INTERVAL}}"+_DEFAULT_NAME()+" Chart values : " +
" Close Price = " + C +
" EMA(C,"+WriteVal(LongPer,1)+") = "+WriteVal(LongMA,1.3) +
" EMA(C,"+WriteVal(ShortPer,1)+") = "+WriteVal(ShortMA,1.3) +
" HHV(H,"+WriteVal(LongPer,1)+") = "+WriteVal(Ref(LastHigh,-1),1.3) ;
 
 */
 
_SECTION_END();

1 comments

1. Foyej Ahmed Khan

Every DSE Technical analyst can see this. I hope this will help to them for trading. It,s a simple but effective Afl for Amibroker.
Thank to everyone who encourage me to learn TA.

Leave Comment

Please login here to leave a comment.

Back