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

KAMA System Complete with Candlestick Pattern for Amibroker (AFL)
arm
about 15 years ago
Amibroker (AFL)

Rating:
4 / 5 (Votes 7)
Tags:

Same Kama System but with added candlestick patterns.

Screenshots

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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorGreen ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
 
// AMA System by Karthikmarar
// Two adjustable parameter "Buy sensitivity" and "Buy Finetune" provided to adjust entry points.
// Two adjustable parameter "Sell sensitivity" and "Sell Finetune" provided to adjust Exit points.
 
_SECTION_BEGIN("Background");
SetChartOptions(0,chartShowArrows|chartShowDates);
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
 ToolTip=StrFormat("Open: %g\nHigh:  %g\nLow:   %g\nClose:  %g
(%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1
)));
}
 
SetChartBkColor(ParamColor("Outer panel color ",colorBlack)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel color upper half",colorDarkTeal),
    ParamColor("Inner panel color lower half",colorBlack)); //color of inner panel
_SECTION_END();
 
_SECTION_BEGIN("KAMA System");
 
SetChartOptions(0,chartShowArrows|chartShowDates);
Title = ("KAMA SYSTEM - " + Name()+"  " + Date() +"  "+Interval(2) +"  "+ EncodeColor(colorLime)+",Open "+Open +" ,High "+H+" ,Low "+L+" ,Close "+C+" "+"{{VALUES}}");
 
 
//{{VALUES}}"+ O+ H+ L+C);
 
 
//_N(Title =StrFormat("{{Name}} - {{Interval}} {{Date}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
 
 
// Buy adjustments
bs=Param("BUY Sensitivity",3,2,20,1);
bf=Param("BUY Finetune",2,0.1,20,0.1);
// Sell Adjustments
ss=Param("SELL Sensitivity",3,2,20,1);
sf=Param("SELL Finetune",1,0.1,20,0.1);
//stock selection parameters
MyCL = Param( "CL", 10, 10, 100, 10 );
MyVK = Param( "VK", 30, 10, 100, 10 );
MyTL = Param( "TL", 300, 100, 1000, 100 );
//stock selection
//TLM = EMA(C*V/100000,100) ;
//include = C> MyCL AND V/1000> MyVK AND C*V/100000 > MyTL AND TLM > 0.333 * MyTL ;
 
// common
fast = 2/(2+1);
slow = 2/(30+1);
//BUY part
dirb=abs(Close-Ref(Close,-bs));
volb=Sum(abs(Close-Ref(Close,-1)),bs);
ERb=dirb/volb;
scb =( ERb*(fast-slow)+slow)^2;
xb = AMA( C, scb );
flb=bf*StDev(xb-Ref(xb,-1),20);
j=xb-Ref(xb,-3);
 
 
//SELL part
dirs=abs(Close-Ref(Close,-ss));
vols=Sum(abs(Close-Ref(Close,-1)),ss);
ERs=dirs/vols;
scs =( ERs*(fast-slow)+slow)^2;
xs = AMA( C, scs );
fls=sf*StDev(xs-Ref(xs,-1),20);
k=Ref(Xs,-3)-Xs;
 
Buy=Cross(j,flb) ;
Sell=Cross(k,fls);
mycolor=IIf(C>xb,colorLime,colorRed);
Plot( C, "Close", mycolor,styleNoTitle | styleBar|styleThick   );
Plot(xb,"KAMA-BUY",colorYellow,1);
Plot(xs,"KAMA-SELL",colorOrange,1);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
 
shape = Buy * shapeUpArrow +Sell * shapeDownArrow ;
 
PlotShapes( shape, IIf( Buy, colorGreen, colorYellow ),0, IIf( Buy, Low, High ) );
 
GraphXSpace = 5;
dist = 1.5*ATR(20);
 
for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist[i], colorLime );
if( Sell[i] ) PlotText( "sell\n@" + C[ i ], i, L[ i ]+dist[i], colorYellow );
}
Filter= Buy OR Sell;
 
PositionScore=100/C;
PositionSize = - 20;
SetBarsRequired(10000, 10000);
SetFormulaName("KAMA System");
 
_SECTION_END();
 
_SECTION_BEGIN("IIR2");
// IIR2.afl
//
// Documentation to describe what the function does.
// Second order smoother
// the function statement
function IIR2( input, f0, f1, f2 )
// the function body
{
result[ 0 ] = input[ 0 ];
result[ 1 ] = input[ 1 ];
for( i = 2; i < BarCount; i++ )
{
result[i] = f0 * input[i] + f1 * result[i-1] + f2 * result[i-2];
}
// the function returns a single value and exits.
return result;
}
// The routine that calls the function.
SmoothedClose = IIR2(Close, 0.2, 1.4, -0.6 );
//Plot( Close, "Price", 2, styleCandle );
Plot( SmoothedClose, "function example", colorRed );
//Figure 8.1 IIR2
_SECTION_END();
 
_SECTION_BEGIN("GSMA");
SetBarsRequired(100000,0);
PI = 3.1415926;
 
function jIIR2( input, f0, f1, f2 )
{
    result[ 0 ] = input[ 0 ];
    result[ 1 ] = input[ 1 ];
 
    for( i = 2; i < BarCount; i++ )
    {
       result[ i ] = f0 * input[ i ] +
                     f1 * result[ i - 1 ] +
                     f2 * result[ i - 2 ];
    }
 
   return result;
}
 
function GSMA( input, Period )
{
  N = 0;
  an = 2 * PI / Period;
  c0 = b0 = 1;
  c1 = b1 = b2 = a1 = a2 = gamma1 = 0;
  beta1 = 2.415 * ( 1- cos( an ) );
  alpha = -beta1 + sqrt( beta1 ^ 2 + 2 * beta1 );
  alpha1 = ( cos( an ) + sin( an ) - 1 )/cos( an );
   {
    fo = alpha ^ 2;
    f1 = 2 * ( 1- alpha ); f2 = -( 1 - alpha )*( 1 - alpha );
  }
   
 
  return jIIR2( input, fo,f1,f2);
}
period=Param("period",13,1,40,1);
 
//Plot( Close, "Price", colorBlack, styleCandle );
Plot( GSMA( C,period), "GSMA", colorLime );
 
//  Linear Regression Line with 2 Standard Deviation Channels Plotted Above and Below
//  Written by Patrick Hargus, with critical hints from Marcin Gorzynski, Amibroker Technical Support
//      Designed for use with AB 4.63 beta and above, using drag and drop feature. 
//  Permits plotting a linear regression line of any price field available on the chart for a period determined by the user. 
//     2 Channels, based on a standard deviation each determined by the user, are plotted above and below the linear regression line.
//      A look back feature is also provided for examining how the indicator would have appeared on a chart X periods in the past.   
 
 
P = ParamField("Price field",-1);
Daysback = Param("Period for Liner Regression Line",21,1,240,1);
shift = Param("Look back period",0,0,240,1);
 
 
//  =============================== Math Formula =============================================================
 
x = Cum(1);
lastx = LastValue( x ) - shift;
aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) );
bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) );
y = Aa + bb * ( x - (Lastx - DaysBack +1 ) );
 
 
// ==================Plot the Linear Regression Line ==========================================================
 
 
LRColor = ParamColor("LR Color", colorCycle );
LRStyle = ParamStyle("LR Style");
 
LRLine =  IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );
Plot( LRLine , "LinReg", LRCOLOR, LRSTYLE ); //  styleDots );
 
// ==========================  Plot 1st SD Channel ===============================================================
 
SDP = Param("Standard Deviation", 1.5, 0, 6, 0.1);
SD = SDP/2;
 
width = LastValue( Ref(SD*StDev(p, Daysback),-shift) );   // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET 
SDU = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width , Null ) ;
SDL = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width , Null ) ;
 
SDColor = ParamColor("SD Color", colorCycle );
SDStyle = ParamStyle("SD Style");
 
Plot( SDU , "Upper Lin Reg", SDColor,SDStyle );
Plot( SDL , "Lower Lin Reg", SDColor,SDStyle );
 
//  ==========================  Plot 2d SD Channel ===============================================================
 
SDP2 = Param("2d Standard Deviation", 2.0, 0, 6, 0.1);
SD2 = SDP2/2;
 
width2 = LastValue( Ref(SD2*StDev(p, Daysback),-shift) );   // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET 
SDU2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width2 , Null ) ;
SDL2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width2 , Null ) ;
 
SDColor2 = ParamColor("2 SD Color", colorCycle );
SDStyle2 = ParamStyle("2 SD Style");
 
Plot( SDU2 , "Upper Lin Reg", SDColor2,SDStyle2 );
Plot( SDL2 , "Lower Lin Reg", SDColor2,SDStyle2 );
 
// ============================ End Indicator Code ==============================================================
 
_SECTION_BEGIN("Nuevo 4");
percent  = 0.01 * 1; /* Adjust this percent as necessary,  */
firstpointL = 2;
firstpointH = 2;
 
y0=LastValue(Trough(L,percent,firstpointL));
y1=LastValue(Trough(Ref(L,-1),percent,1));
 
for( i = 1; i < BarCount AND y0 >= y1; i++ )
{
       
      firstpointL++;  
      y0=LastValue(Trough(L,percent,firstpointL));      
}
 
x0=BarCount - 1 - LastValue(TroughBars(L,percent,firstpointL));
x1=BarCount - 1 - LastValue(TroughBars(Ref(L,-1),percent,1));
LineL = LineArray( x0, y0, x1, y1, 1 );
/*
Plot(C, "C", colorBlack, styleCandle);
*/
Plot( LineL, " Support Trend line", colorGreen,4 +8 );
 
 
yt0=LastValue(Peak(H,percent,firstpointH));
yt1=LastValue(Peak(Ref(H,-1),percent,1));
 
for(i = 1; i < BarCount AND yt0 <= yt1; i++ )
{
       
      firstpointH++;     
      yt0=LastValue(Peak(H,percent,firstpointH));
}
xt0=BarCount - 1 - LastValue(PeakBars(H,percent,firstpointH));
xt1=BarCount - 1 - LastValue(PeakBars(Ref(H,-1),percent,1));
LineH = LineArray( xt0, yt0, xt1, yt1, 1 );
 
Plot( LineH, "Resistance Trend line", colorBrown,4 + 8 );
_SECTION_END();
 
_SECTION_BEGIN("Elliot 2");
//-- Script Start -------
Option = ParamToggle("Insert To", "Price Chart|Indicator");
 
pr=Param("Elliot Wave minimum % move",2, 0.001,100);
 
//{ Beginner Elliot Wave stuff }
EWpk=PeakBars(H,pr)==0;
EWtr=TroughBars(L,pr)==0;
 
//{ Intermediate Elliot Wave stuff }
zz=Zig(C,pr);
zzHi=Zig(H,pr);
zzLo=Zig(L,pr);
Avg=(zzHi+zzLo)/2;
 
//{ Advanced Elliot Wave stuff }
RetroSuccessSecret=IIf(EWpk,zzHi,
                     IIf(EWtr,zzLo,IIf(Avg>Ref(Avg,-1),H,L)));
EW=Zig(RetroSuccessSecret,pr);
 
//{ Plot on price chart }
if (Option==0)
 Plot(EW, "EW", ParamColor("Color", colorBrown), ParamStyle("Style", styleNoLabel|styleThick));
else
{
 
//{ Buy/Sell Elliot Wave stuff }
EWbuy=TroughBars(EW,pr)==0;
EWsell=PeakBars(EW,pr)==0;
 
//{ Plot on own window }
Plot(EWbuy-EWsell, "EW2", ParamColor("Color", colorRed), ParamStyle("Style", styleNoLabel|styleThick));
 
}
//-- Script End   -------
_SECTION_END();
 
_SECTION_BEGIN("Elliot_Fractals");
 
/*
The basic definition of an 'up' fractal is a bar high that is both higher than the two bars immediately preceding it
and higher than the two bars immediately following it.
The lows of the bars are NOT considered in determining the up fractal progression.
 
If two bars in the progression have equal highs followed by two consecutive bars with lower highs,
then a total of six bars rather than the usual five bars will make up the progression.
The first High becomes the counting fractal. Reverse for 'down' fractals.
 
The 5 bar formation works best on Daily or longer time frame charts.For intraday data charts we often use 9 bar, 13 bar and 21 bar formations for fractal counting
*/
Up5BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND Ref(H,1) < H AND Ref(H,2) < H;
Up6BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND (H == Ref(H,1)) AND Ref(H,2) < H AND Ref(H,3) < H;
Down5BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND Ref(L,1) > L AND Ref(L,2) > L;
Down6BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND (L == Ref(L,1)) AND Ref(L,2) > L AND Ref(L,3) > L;
 
//TODO: More filtering: Show only troughs that are around atrough in trix(9).
 
PlotShapes( IIf(Down5BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
PlotShapes( IIf(Down6BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
 
PlotShapes( IIf(Up5BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
PlotShapes( IIf(Up6BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
 
Up = (Up5BarFractal OR Up6BarFractal);
Down = (Down5BarFractal OR Down6BarFractal);
//Removing false fractals:
DownSignal = Flip(Ref(Up,-1), Ref(Down,-1));
UpSignal = Flip(Ref(Down,-1), Ref(Up,-1));
 
LastHigh[0] = H[0];
LastLow[0] = L[0];
 
LastLowIndex = 0;
LastHighIndex = 0;
Valid = 0;
for (i=1; i < BarCount; i++)
{
 
    LastHigh[i] = LastHigh[i-1];
    LastLow[i] = LastLow[i-1];
    if (Up[i])
    {                              
        Valid[i] = True;
        if (DownSignal[i])
        {
            //Sequence of 2 Up Fractals. Validate only the higher one.
            Valid[i] = H[i] >= H[LastHighIndex];
            Valid[LastHighIndex] = H[LastHighIndex] >  H[i];
        }
        LastHigh[i] = Max(H[i], H[LastHighIndex ]);
        LastHighIndex = i; 
    }
 
    if (Down[i])
    {  
        Valid[i] = True;
        if (UpSignal[i])
        {
            //Sequence of 2 Down Fractals. Validate only the lower one.
            Valid[i] = L[i] <= L[LastLowIndex];
            Valid[LastLowIndex] = L[LastLowIndex] <  L[i];
        }
     
        LastLow[i] = Min(L[i], L[LastLowIndex]);
        LastLowIndex = i;      
    }  
}
 
TrixN = Trix(9);
TroughLow = Ref(TrixN, -3) > TrixN AND Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN AND Ref(TrixN, 3) > TrixN;
TroughHigh = Ref(TrixN, -3) < TrixN AND Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN AND Ref(TrixN, 3) < TrixN;
//TroughLow = Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN;
//TroughHigh = Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN;
ZeroValid = Cross(TrixN, 0) OR Cross(0, TrixN) OR Ref(Cross(TrixN, 0),1) OR Ref(Cross(0, TrixN),1);
ValidLow = TroughLow OR Ref(TroughLow, 1) OR Ref(TroughLow, 2) OR Ref(TroughLow, 3) OR Ref(TroughLow, 4);// OR Ref(TroughLow, 5));
ValidHigh = TroughHigh OR Ref(TroughHigh, 1) OR Ref(TroughHigh, 2) OR Ref(TroughHigh, 3) OR Ref(TroughHigh, 4);// OR Ref(TroughHigh, 5));
 
//Plot(LastHigh-10 ,"LastHigh", colorBlue, styleLine);
//Plot(LastLow-10 ,"LastLow ", colorRed, styleLine);
//Plot(Valid*5 + 10 ,"LastLow ", colorGreen, styleLine | styleThick);
 
//PlotShapes( IIf(Down AND Valid,shapeSmallUpTriangle,0) ,colorGreen, 0, L,-12);
//PlotShapes( IIf(Up AND Valid,shapeSmallDownTriangle,0) ,colorRed, 0, H,-12);
Maxi = Up AND (ValidHigh OR ZeroValid);
Mini = Down AND (ValidLow OR ZeroValid);
PlotShapes( IIf(Down AND (ValidLow OR ZeroValid),shapeSmallUpTriangle,0) ,colorBlue, 0, L,-12);
PlotShapes( IIf(Up AND (ValidHigh OR ZeroValid),shapeSmallDownTriangle,0) ,colorOrange, 0, H,-12);
//Plot(UpSignal*3+5,"UpSignal", colorBlue, styleLine| styleThick);
//Plot(DownSignal*3 ,"DownSignal", colorRed, styleLine| styleThick);
 
/*
LastMaxi = 0;
LastMini = 0;
ElliotLines = 0;
State = 0;
for (i=1; i < BarCount; i++)
{
    State[i] = State[i-1];
    if (Maxi[i])
    {      
        State[i] = 1;//down
    }
 
    if (Mini[i])
    {      
        State[i] = 2;
    }
 
}
 
PlotShapes(IIf(State > 0, shapeSmallCircle, 0), IIf(State == 1, colorRed, colorBlue), 0, IIf(State == 1, H, L), -5);
*/
//Line = LineArray( x0, y0, x1, y1, 1 );
//Plot( Line, "Trend line", colorBlue );
 
/*
Wave B
Usually 50% of Wave A
Should not exceed 75% of Wave A
Wave C
either 1 x Wave A
or 1.62 x Wave A
or 2.62 x Wave A
*/
function CorrectiveRatios(StartPrice, A, B, C, RatioDelta, Delta)
{
     
    ALength = abs(startPrice - A);  BLength = abs(A-B);
    CLength = abs(B-C);
 
    Ratio1 = BLength  / CLength ;
    Cond1 = Ration1 >= 0.5 - RatioDelta AND ratio1 <= 0.75 + RatioDelta;
    Cond2 = abs(Clength - ALength) < Delta  OR abs(Clength - 1.62 * ALength) < Delta OR abs(CLength - 2.62 * ALength) < Delta;
     
    return Cond1 AND Cond2;
}
 
function ImpulseRules(StartPrice, One, Two, Three, Four, Five)
{
    //Wave 2 should be beneath wave 1 start:
    Cond1 = Two > StartPrice AND Two < One;
    //Wave 4 - the same:
    Cond2 = Four > Two AND Four < Three;
    //Wave 5 should be <= wave 3
    Cond3 = abs(Three-Two) >= abs(Five - Four);
    //Wave 1 should be smaller than wave five, making wave 3 the biggest:
    Cond4 = abs(StartPrice - One) < abs(Five - Four);
    return Cond1 AND Cond2 AND Cond3 AND Cond4;
}
_SECTION_END();

0 comments

Leave Comment

Please login here to leave a comment.

Back