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

Trading - asfa.alam for Amibroker (AFL)

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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
// asfatul.alam@yahoo.com
 
_SECTION_BEGIN("Head & shoulder");
SetChartBkColor(colorLightGrey) ;
SetBarFillColor( IIf( C >O AND C>MA(C,21) AND C>EMA(C,8),colorBlue, IIf( C <O AND C>MA(C,21) AND C>EMA(C,8),colorBlueGrey,IIf(( C<O AND C<MA(C,21) AND C>EMA(C,8)) OR (
 
C<O AND C>MA(C,21) AND C<EMA(C,8)) ,colorYellow,IIf(( C>O AND C<MA(C,21) AND C>EMA(C,8)) OR ( C>O AND C>MA(C,21) AND C<EMA(C,8)) ,colorPink,IIf( C>O AND C<MA
 
(C,21) AND C<EMA(C,8) ,colorPink,colorRed) )))));
Col=IIf( C<MA(C,21) AND C<EMA(C,8) ,colorRed,IIf( C>MA(C,21) AND C>EMA(C,8),colorBlueGrey,IIf(( C<MA(C,21) AND C>EMA(C,8)) OR ( C>MA(C,21) AND C<EMA(C,8))
 
,colorYellow,colorYellow)));
Plot( C, "Close", col, styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
 
 
 
 
 
RequestTimedRefresh(0.1,True);
xx=BarIndex();x=xx;Lx=LastValue(x);
nbar=Param("N Pivot Bars",5,2,50,1);
tf=Param("Time Frame (min)",5,1,1440,1);tfrm=in1Minute*tf;
CleanPivots=ParamToggle("Use Clean Pivots","Off|On",1);
PivotSymmetry=ParamToggle("Use Symmetric Pivots","Off|On",0);
dispbe123=ParamToggle("Display bearish 123","Off|On",1);
dispbu123=ParamToggle("Display bullish 123","Off|On",1);
dispbeRetraceValues=ParamToggle("Display retrace value (Bearish)","Off|On",1);
dispbuRetraceValues=ParamToggle("Display retrace value (Bullish)","Off|On",1);
dispLabels=ParamToggle("Display Labels","Off|On",1);
entryType=ParamToggle("Entry Type","Regular|Agressive",1);
signalRangeCheck=ParamToggle("Signal Entry Range Limit","Off|On",1);
extendRange=Param("Extended entry range",100,0,500,1);
minRetrace=Param("Retrace Minimum",0.382,0,2,0.01);
maxRetrace=Param("Retrace Maximum",0.88,0,6,0.01);
 
TimeFrameSet(tfrm);
if(PivotSymmetry)
{
    fc=1;
    pk=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
    tr=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=L;
}
else
{
    fc=2;
    pk=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
    tr=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=L;
}
 
px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);
ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
ph3=ValueWhen(pk,H,3); tl3=ValueWhen(tr,L,3);
 
if(CleanPivots)
{
    tr=IIf((tr==1 AND pk==1) AND px2<tx2 AND Lx!=BarCount-1,False,tr);
    pk=IIf((tr==1 AND pk==1) AND px2>tx2 AND Lx!=BarCount-1,False,pk);
     
    px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
    px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
    px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
    px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);  
    ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
    ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
    ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
    ph3=ValueWhen(pk,H,3); tl3=ValueWhen(tr,L,3);  
     
    tr=IIf(tr AND ((tx0<px0 AND tl1>tl0) OR (tx2>px1 AND tl1>tl2) OR (px0==px1 AND tl1>tl0) OR (tl1>tl0 AND px0==tx0)),False,tr);
    pk=IIf(pk AND ((px0<tx0 AND ph1<ph0) OR (px2>tx1 AND ph1<ph2) OR (tx0==tx1 AND ph1<ph0) OR (ph1<ph0 AND px0==tx0)),False,pk);
 
    px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
    px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
    px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
    px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);
    ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
    ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
    ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
    ph3=ValueWhen(pk,H,3); tl3=ValueWhen(tr,L,3);  
 
    tr=IIf(tr AND ((tx0<px0 AND tl1>tl0) OR (tx2>px1 AND tl1>tl2) OR (px0==px1 AND tl1>tl0) OR (tl1>tl0 AND px0==tx0)),False,tr);
    pk=IIf(pk AND (((px0<tx0 AND ph1<ph0) OR px2>tx1 AND ph1<ph2) OR (tx0==tx1 AND ph1<ph0) OR (ph1<ph0 AND px0==tx0)),False,pk);
 
    px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
    px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
    px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
    px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);
    ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
    ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
    ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
    ph3=ValueWhen(pk,H,3); tl3=ValueWhen(tr,L,3);  
}
pkh=IIf(pk,H,Null);
trl=IIf(tr,L,Null);
TimeFrameRestore();
fact=Nz(Max(tfrm/60,Interval()/60)/(Interval()/60));
if(fact==0)fact=1;
Lkbk=Nz(tfrm/Interval());
if(Lkbk>1)
{
    pk=TimeFrameExpand(pk,tfrm,expandFirst);
    pkh=TimeFrameExpand(pkh,tfrm,expandFirst);
    pkhs=IIf(!IsEmpty(pkh),1,0);pkhs=pkhs-Ref(pkhs,-1);
    pk=pk AND H==pkh;
    cond1=Sum(pk,BarsSince(pkhs==1)+1)==1 AND pk;
    pk=pk AND cond1;
     
    tr=TimeFrameExpand(tr,tfrm,expandFirst);   
    trl=TimeFrameExpand(trl,tfrm,expandFirst);
    trls=IIf(!IsEmpty(trl),1,0);trls=trls-Ref(trls,-1);
    tr=tr AND L==trl;
    cond1=Sum(tr,BarsSince(trls==1)+1)==1 AND tr;
    tr=tr AND cond1;
     
    px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
    px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
    px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
    px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);
    ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
    ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
    ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
    ph3=ValueWhen(pk,H,3); tl3=ValueWhen(tr,L,3);
}
 
ll=tr AND tl1<tl2;
hl=tr AND tl1>tl2;
hh=pk AND ph1>ph2;
lh=pk AND ph1<ph2;
dt=pk AND ph1==ph2;
db=tr AND tl1==tl2;
 
ll_h=IIf(ll,1,0);
hl_h=IIf(hl,2,0);
hh_h=IIf(hh,3,0);
lh_h=IIf(lh,4,0);
dt_h=IIf(dt,5,0);
db_h=IIf(db,6,0);
 
combi=ll_h+hl_h+lh_h+hh_h+dt_h+db_h;
 
t0=ValueWhen(combi,combi,0);
t1=ValueWhen(combi,combi,1);
t2=ValueWhen(combi,combi,2);
t3=ValueWhen(combi,combi,3);
t4=ValueWhen(combi,combi,4);
t5=ValueWhen(combi,combi,5);
 
  
be123=pk AND t1==4 AND t2==2;
beAx=ValueWhen(be123,tx2);beAy=ValueWhen(be123,tl2);
beBx=ValueWhen(be123,px2);beBy=ValueWhen(be123,ph2);
beCx=ValueWhen(be123,tx1);beCy=ValueWhen(be123,tl1);
beDx=ValueWhen(be123,px1);beDy=ValueWhen(be123,ph1);
beRetrace=(beBy-beCy)/(beBy-beAy);
be123=be123 AND beRetrace>minRetrace AND beRetrace<maxRetrace AND beDy>beCy;
rr=BarsSince(be123)>=0 AND BarsSince(be123)<extendRange;
idx=IIf(rr,xx-ValueWhen(be123,beCx),Null);
if(entryType) aa=(beCy-beAy)/(beCx-beAx);else aa=0;bb=beCy;
aa=ValueWhen(be123,aa);bb=ValueWhen(be123,bb);
beEx=ValueWhen(be123,px1);ii=px1-beCx;beEy=aa*ii+bb;
be123=be123 AND beEy<beDy;
beTrendline=IIf(idx,aa*idx+bb,Null);beValidSignalArea=Flip(be123,Ref(tr,-1));
if(signalRangeCheck) beTrendline=IIf(beValidSignalArea,beTrendline,Null);
Short=Cross(beTrendline,C) AND !IsEmpty(beTrendline);Short=Ref(Short,-1);ShortPrice=O;
Short=ExRem(Short,be123);Sell=0;
 
// bullish 123 pattern
bu123=tr AND t1==2 AND t2==4;
buAx=ValueWhen(bu123,px2);buAy=ValueWhen(bu123,ph2);
buBx=ValueWhen(bu123,tx2);buBy=ValueWhen(bu123,tl2);
buCx=ValueWhen(bu123,px1);buCy=ValueWhen(bu123,ph1);
buDx=ValueWhen(bu123,tx1);buDy=ValueWhen(bu123,tl1);
buRetrace=(buCy-buBy)/(buAy-buBy);
bu123=bu123 AND buRetrace>minRetrace AND buRetrace<maxRetrace AND buDy<buCy;;
rr=BarsSince(bu123)>=0 AND BarsSince(bu123)<extendRange;
idx=IIf(rr,xx-ValueWhen(bu123,buCx),Null);
if(entryType) aa=(buCy-buAy)/(buCx-buAx);else aa=0;bb=buCy;
aa=ValueWhen(bu123,aa);bb=ValueWhen(bu123,bb);
buEx=ValueWhen(bu123,tx1);ii=tx1-buCx;buEy=aa*ii+bb;
bu123=bu123 AND buEy>buDy;
buTrendline=IIf(idx,aa*idx+bb,Null);buValidSignalArea=Flip(bu123,Ref(pk,-1));
if(signalRangeCheck) buTrendline=IIf(buValidSignalArea,buTrendline,Null);
Buy=Cross(C,buTrendline) AND !IsEmpty(buTrendline);Buy=Ref(Buy,-1);BuyPrice=O;
Buy=ExRem(Buy,bu123);Cover=0;
 
GraphXSpace=5;SetChartBkColor(ColorRGB(0,0,0));SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"Price",IIf(C>O,colorDarkGreen,IIf(C<=O,colorDarkRed,colorLightGrey)),64,0,0,0,0);
Plot(pkh,"",colorRed,styleThick,0,0,0,-1);
Plot(trl,"",colorBrightGreen,styleThick,0,0,0,-1);
PlotShapes(shapeSmallCircle*tr,IIf(Lx-ValueWhen(tr,x)>nbar*fact,ColorRGB(0,100,0),colorWhite),0,L,-10);
PlotShapes(shapeSmallCircle*pk,IIf(Lx-ValueWhen(pk,x)>nbar*fact,ColorRGB(255,0,0),colorWhite),0,H,10);
 
if(dispbe123)
{
    Plot(beTrendline,"",ColorRGB(100,0,0),styleDots|styleNoLine,0,0,0,0);
    PlotShapes(IIf(Short,shapeSmallDownTriangle,shapeNone),colorRed,0,H,IIf(Short AND Sell,-30,-15));  
    PlotShapes(IIf(Short,shapeSmallCircle,shapeNone),colorWhite,0,ShortPrice,0);   
}
if(dispbu123)
{
    Plot(buTrendline,"",ColorRGB(0,100,0),styleDots|styleNoLine,0,0,0,0);  
    PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorDarkGreen,0,L,-15);
    PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
}
 
qq=Interval()/60;
if(qq < 60){tf=" min";tt=qq;}
else if(qq >= 60 AND qq < 1440){tf=" hrs";tt=qq/60;}
else if(qq >= 1440){tf=" days";tt=(qq/60)/24;}
qq=Max(tfrm/60,Interval()/60);
if(qq < 60){tfa=" min";tta=qq;}
else if(qq >= 60 AND qq < 1440){tfa=" hrs";tta=qq/60;}
else if(qq >= 1440){tfa=" days";tta=(qq/60)/24;}
 
 
 
abcdy_up=27;
abcdy_dn=15;
function GetVisibleBarCount()
{
    lvb=Status("lastvisiblebar");
    fvb=Status("firstvisiblebar");
    return Min(lvb-fvb,BarCount-fvb);
}
function GfxConvertPixelsToBarX(Pixels)
{
    lvb=Status("lastvisiblebar");
    fvb=Status("firstvisiblebar");
    pxchartleft=Status("pxchartleft");
    pxchartwidth=Status("pxchartwidth");
    fac=pxchartwidth/Pixels;
    bar=(lvb-fvb)/fac;
    return Nz(bar);
}
function GfxConvertPixelToValueY(Pixels)
{
    local Miny,Maxy,pxchartbottom,pxchartheight;
    Miny=Status("axisminy");
    Maxy=Status("axismaxy");
    pxchartbottom=Status("pxchartbottom");
    pxchartheight=Status("pxchartheight");
    fac=pxchartheight/Pixels;
    Value=(Maxy-Miny)/fac;
    return Nz(Value);
}
function GfxConvertBarToPixelX(bar)
{
    lvb=Status("lastvisiblebar");
    fvb=Status("firstvisiblebar");
    pxchartleft=Status("pxchartleft");
    pxchartwidth=Status("pxchartwidth");
    return Nz(pxchartleft+bar*pxchartwidth/(lvb-fvb+1));
}
function GfxConvertValueToPixelY(value)
{
    local Miny,Maxy,pxchartbottom,pxchartheight;
    Miny=Status("axisminy");
    Maxy=Status("axismaxy");
    pxchartbottom=Status("pxchartbottom");
    pxchartheight=Status("pxchartheight");
    return Nz(pxchartbottom-floor(0.5+(Value-Miny)*pxchartheight/(Maxy-Miny)));
}
AllVisibleBars=GetVisibleBarCount();
fvb=Status("firstvisiblebar");
abcdy_up=GfxConvertPixelToValueY(abcdy_up);
abcdy_dn=GfxConvertPixelToValueY(abcdy_dn);
 
for(i=0;i<AllVisibleBars;i++)
{
    if(ll[i+fvb] AND dispLabels)
    {
        lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
        GfxSetTextColor(colorYellow);GfxTextOut("LL",
        GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn));
    }
    if(hl[i+fvb] AND dispLabels)
    {
        lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
        GfxSetTextColor(colorYellow);GfxTextOut("HL",
        GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn));
    }  
    if(db[i+fvb] AND dispLabels)
    {
        lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
        GfxSetTextColor(colorYellow);GfxTextOut("DB",
        GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn));
    }      
    if(hh[i+fvb] AND dispLabels)
    {
        lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
        GfxSetTextColor(colorYellow);GfxTextOut("HH",
        GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up));
    }  
    if(lh[i+fvb] AND dispLabels)
    {
        lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
        GfxSetTextColor(colorYellow);GfxTextOut("LH",
        GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up));
    }  
    if(dt[i+fvb] AND dispLabels)
    {
        lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
        GfxSetTextColor(colorYellow);GfxTextOut("DT",
        GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up));
    }      
    if(be123[i+fvb] AND dispbe123)
    {
        GfxSetOverlayMode(1);
        GfxSelectPen(ColorRGB(100,0,0),2);
        GfxSelectSolidBrush(ColorRGB(20,0,0)); 
        lvix=i+fvb;
        GfxSetBkMode(1);GfxSetOverlayMode(1);GfxSelectPen(ColorRGB(100,0,0),1,1);
        GfxMoveTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beCx[lvix])),GfxConvertValueToPixelY(beCy[lvix]));
        GfxLineTo(GfxConvertBarToPixelX(i),GfxConvertValueToPixelY(beDy[lvix]));
        GfxMoveTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beBx[lvix])),GfxConvertValueToPixelY(beBy[lvix]));
        GfxLineTo(GfxConvertBarToPixelX(i),GfxConvertValueToPixelY(beDy[lvix]));
        GfxPolygon(
        GfxConvertBarToPixelX(i-(beDx[lvix]-beAx[lvix])),GfxConvertValueToPixelY(beAy[lvix]),
        GfxConvertBarToPixelX(i-(beDx[lvix]-beBx[lvix])),GfxConvertValueToPixelY(beBy[lvix]),
        GfxConvertBarToPixelX(i-(beDx[lvix]-beCx[lvix])),GfxConvertValueToPixelY(beCy[lvix]));     
        GfxSelectFont("Tahoma",10,500);GfxSetBkMode(1);        
        GfxSetTextColor(ColorRGB(200,0,0));GfxTextOut("1",GfxConvertBarToPixelX(i-(beDx[lvix]-beBx[lvix]))-7,GfxConvertValueToPixelY(beBy[lvix]+1.5*abcdy_up));
        GfxSetTextColor(ColorRGB(200,0,0));GfxTextOut("2",GfxConvertBarToPixelX(i-(beDx[lvix]-beCx[lvix]))-7,GfxConvertValueToPixelY(beCy[lvix]-1.6*abcdy_dn));
        GfxSetTextColor(ColorRGB(200,0,0));GfxTextOut("3",GfxConvertBarToPixelX(i-(beDx[lvix]-beDx[lvix]))-7,GfxConvertValueToPixelY(beDy[lvix]+1.5*abcdy_up));
        Plot(LineArray(beCx[lvix],beCy[lvix],beEx[lvix],beEy[lvix],0,True ),"",ColorRGB(100,0,0),styleDashed);
        if(dispbeRetraceValues)
        {
            GfxSelectFont("Tahoma",8,650); GfxSetBkMode(2);GfxSetOverlayMode(1);GfxSetBkColor(colorDarkRed);GfxSetTextColor(colorWhite);
            GfxTextOut(""+Prec(beRetrace[lvix],2),GfxConvertBarToPixelX(i-(beDx[lvix]-(beAx[lvix]+beCx[lvix])/2)),GfxConvertValueToPixelY((beAy[lvix]+beCy[lvix])/2));
        }          
    }
    if(bu123[i+fvb] AND dispbu123)
    {
        GfxSetOverlayMode(1);
        GfxSelectPen(ColorRGB(0,100,0),2);
        GfxSelectSolidBrush(ColorRGB(0,20,0)); 
        lvix=i+fvb;
        GfxSetBkMode(1);GfxSetOverlayMode(1);GfxSelectPen(ColorRGB(0,100,0),1,1);
        GfxMoveTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buCx[lvix])),GfxConvertValueToPixelY(buCy[lvix]));
        GfxLineTo(GfxConvertBarToPixelX(i),GfxConvertValueToPixelY(buDy[lvix]));
        GfxMoveTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buBx[lvix])),GfxConvertValueToPixelY(buBy[lvix]));
        GfxLineTo(GfxConvertBarToPixelX(i),GfxConvertValueToPixelY(buDy[lvix]));
        GfxPolygon(
        GfxConvertBarToPixelX(i-(buDx[lvix]-buAx[lvix])),GfxConvertValueToPixelY(buAy[lvix]),
        GfxConvertBarToPixelX(i-(buDx[lvix]-buBx[lvix])),GfxConvertValueToPixelY(buBy[lvix]),
        GfxConvertBarToPixelX(i-(buDx[lvix]-buCx[lvix])),GfxConvertValueToPixelY(buCy[lvix]));         
        GfxSelectFont("Tahoma",10,500);GfxSetBkMode(1);
        GfxSetTextColor(ColorRGB(0,200,0));GfxTextOut("1",GfxConvertBarToPixelX(i-(buDx[lvix]-buBx[lvix]))+3,GfxConvertValueToPixelY(buBy[lvix]-1.6*abcdy_dn));
        GfxSetTextColor(ColorRGB(0,200,0));GfxTextOut("2",GfxConvertBarToPixelX(i-(buDx[lvix]-buCx[lvix]))+3,GfxConvertValueToPixelY(buCy[lvix]+1.5*abcdy_up));
        GfxSetTextColor(ColorRGB(0,200,0));GfxTextOut("3",GfxConvertBarToPixelX(i-(buDx[lvix]-buDx[lvix]))+3,GfxConvertValueToPixelY(buDy[lvix]-1.6*abcdy_dn));
        Plot(LineArray(buCx[lvix],buCy[lvix],buEx[lvix],buEy[lvix],0,True ),"",ColorRGB(0,100,0),styleDashed);
        if(dispbuRetraceValues)
        {      
            GfxSelectFont("Tahoma",8,650); GfxSetBkMode(2);GfxSetOverlayMode(1);GfxSetBkColor(colorDarkGreen);GfxSetTextColor(colorWhite);
            GfxTextOut(""+Prec(buRetrace[lvix],2),GfxConvertBarToPixelX(i-(buDx[lvix]-(buAx[lvix]+buCx[lvix])/2)),GfxConvertValueToPixelY((buAy[lvix]+buCy[lvix])/2));
        }          
    }
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
PH1= ValueWhen(
(Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H), Ref(H,-2));
 
PL1= ValueWhen(
(Ref(L,-2) <= Ref(L, -4)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= L), Ref(L,-2));
 
PH2= ValueWhen(
(Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H), Ref(H,-2),2);
 
PL2= ValueWhen(
(Ref(L,-2) <= Ref(L, -4)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= L), Ref(L,-2),2);
 
TendLong = (PL1 > PL2 AND PH1 > PL1 AND C>PL1);
TendShrt = (PH1 < PH2 AND PL1 > PH1 AND C<PH1);
 
 
 
_SECTION_BEGIN("Three Line Net Bar");
NetBarPeriod = Param("3Line Net Bar Period",13,5,30,1);
function ThreeLineUp()
{
    H2[0] = result[0] = 0;
    for (i = 10; i < BarCount; i++)
    {
        for (j = 1; j < i; j++) if((H[i-j]>H[i]))  {H2[i]  = H[i-j]; break;} 
        for (j = 1; j < i; j++)  if((H[i-j]>H2[i])) {result[i] =  H[i-j]; break;}
    }
    return result;
}
 
function ThreeLineDn()
{
    L2[0] = result[0] = 0;
    for (i = 10; i < BarCount; i++)
    {
        for (j = 1; j < i; j++) if((L[i-j]<L[i])) {L2[i] = L[i-j]; break;}   
        for (j = 1; j < i; j++) if((L[i-j]<L2[i])) {result[i] = L[i-j]; break;}
    }
     return result;
}
 
LineDn = ValueWhen(H==HHV(H,NetBarPeriod),ThreeLineDn(),1);
LineUp = ValueWhen(L==LLV(L,NetBarPeriod),ThreeLineUp(),1);
Hlv = IIf(C>LineDn,1,IIf(C<LineUp,-1,0));
Hlv = ValueWhen(Hlv!=0,Hlv,1);
ThreeLineNetBar = IIf(Hlv==1,LineDn,LineUp);
 
_SECTION_END();
 
 
TendencyCritery = ParamList("Tendency System","Stormer|Leandro");
 
if (TendencyCritery == "Stormer" )
{
    Plot(EMA(C,9),"EMA(9)",colorBlue,styleThick);
    Plot(EMA(C,21),"EMA(21)",colorRed,styleThick);
    Plot(ThreeLineNetBar, "3Line Net Bar", ParamColor("Color",colorRed),ParamStyle("Style",styleDashed));
}
if (TendencyCritery == "Leandro" )
{
    Plot(MA(C,21),"MA(21)",colorBlue,styleThick);
    Plot(MA(C,50),"MA(50)",colorRed,styleThick);
    Plot(MA(C,200),"MA(200)",colorOrange,styleThick);
}
 
_SECTION_BEGIN("trending ribbon");
 
global points;
 
function bgColorPerc(P)
{
  return ColorRGB(255-(P/100)*255,(P/100)*255,0);
}
 
if (TendencyCritery == "Stormer")
   Points = IIf(C>EMA(C,9),1,0)+(EMA(C,9)>EMA(C,21))+(EMA(C,21)>Ref(EMA(C,21),-1))+TendLong+IIf(C>ThreeLineNetBar,1,0);
else
   Points = IIf(C>MA(C,21),1,0)+(MA(C,21)>MA(C,50))+(MA(C,50)>MA(C,200))+(MA(C,21)>Ref(MA(C,21),-1))+TendLong;
 
ColorNumber = (Points/5)*100;   
Plot( 2, "", bgColorPerc(ColorNumber), styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();
 
_SECTION_BEGIN("Title");
 
SetChartOptions(0,chartShowDates|chartShowArrows|chartLogarithmic|chartWrapTitle);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ))+"\n"+
EncodeColor(colorBlue)+"Tendency: "+EncodeColor(colorBlack)+WriteIf(Points==5,"Strong Buy",WriteIf(Points==4,"Buy",WriteIf(Points==3,"Hold",WriteIf(points==0,"Strong Sell","Sell")))));
 
Plot(C,"",ParamColor("color",colorBlack),styleCandle);
_SECTION_END();
 
 
_SECTION_BEGIN("Background text");
SetChartOptions(0,chartShowArrows|chartShowDates);
C11=ParamColor("up panel",colorAqua );
C12=ParamColor("dn panel",colorDarkGrey );
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode( 0 );
GfxSetOverlayMode(1);
GfxGradientRect(0,0,pxwidth, pxheight, C11, C12 );
 
_SECTION_END();
 
 
Buy = (Points > 3);
Sell = (Points < 3);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
 
 
 
  
 
 
PlotShapes( Buy* shapeUpArrow, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy,Low, High) );
PlotShapes( Sell* shapeDownArrow, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy,Low, High) );
 
 
 
AddColumn(Close,"Close",1.2);
AddColumn((V/MA(V,20))*100,"Vol (%)",1.2);
AddColumn(Points,"Force Tendency",1.0, colorDefault, bgColorPerc((Points/5)*100));
Filter = MA(V,20)>(C*5000);
Back