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

oz setup 2 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
// AFL code by Edward Pottasch, Jan 2013
procedure alternate1_proc(pk,tr,px0,px1,px2,ph0,ph1,ph2,tx0,tx1,tx2,tl0,tl1,tl2)
{
    global pkh;
    global trh;
     
    pk=IIf((px0==px1 AND px2>tx1 AND ph1<ph2)
    OR (tx0==tx1 AND px1<px0 AND px1>tx0 AND ph1<=ph0)
    OR (px0>px1 AND px1<tx0 AND px2>tx1 AND ph1<ph2)
    OR (px0>px1 AND px0<tx0 AND px1>tx1 AND ph1<ph0)
    OR (ph1==ph2 AND px2>tx1)
    OR (px1==tx1 AND px2>tx2),False,pk);
 
    tr=IIf((tx0==tx1 AND tx2>px1 AND tl1>tl2)
    OR (px0==px1 AND tx1<tx0 AND tx1>px0 AND tl1>=tl0)
    OR (tx0>tx1 AND tx1<px0 AND tx2>px1 AND tl1>tl2)
    OR (tx0>tx1 AND tx0<px0 AND tx1>px1 AND tl1>tl0)
    OR (tl1==tl2 AND tx2>px1)
    OR (px1==tx1 AND tx2>px2),False,tr);
     
    pkh=pk;trh=tr;
}
procedure calculatePivots(tfrm,PivotSymmetry,nbar,CleanPivots,x)
{
TimeFrameSet(tfrm);
 
global tr;global pk;global px0;global px1;global px2;global ph0;global ph1;global ph2;
global trl;global pkh;global tx0;global tx1;global tx2;global tl0;global tl1;global tl2;
global fact;
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);
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);
 
if(CleanPivots)
{
    alternate1_proc(pk,tr,px0,px1,px2,ph0,ph1,ph2,tx0,tx1,tx2,tl0,tl1,tl2);
    pk=pkh;tr=trh;
     
    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);
    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);
     
    alternate1_proc(pk,tr,px0,px1,px2,ph0,ph1,ph2,tx0,tx1,tx2,tl0,tl1,tl2);
    pk=pkh;tr=trh;
     
    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);
    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);
}
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);
}
}
function GetVisibleBarCount()
{
    lvb=Status("lastvisiblebar");
    fvb=Status("firstvisiblebar");
    return Min(lvb-fvb,BarCount-fvb);
}
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)));
}
function GfxConvertValueToPixelYlog(Value)
{
    local Miny,Maxy,pxchartbottom,pxchartheight;
    pxchartheight=Status("pxchartheight");
    pxchartbottom=Status("pxchartbottom");
    Miny=Status("axisminy");
    Maxy=Status("axismaxy");
    x=log(Value/Miny)/log(Maxy/Miny);
    return Nz(pxchartbottom-round(pxchartheight*x));
}
function displayLines(pk,tr,bkColorRes,bkColorSup,lnColorRes,lnColorSup,lnWidthRes,lnWidthSup,displayMode,logscale)
{
AllVisibleBars=GetVisibleBarCount();
fvb=Status("firstvisiblebar");
for(i=0;i<AllVisibleBars;i++)
{
    DisplayRes=1;
    DisplaySup=1;
    lvix=i+fvb;
    if(pk[lvix])
    {
        if(displayMode)
        {
            hval=H[lvix];
            for(j=i;j<AllVisibleBars;j++)
            {
                lvjx=j+fvb;
                if(H[lvjx]>hval)
                {
                    DisplayRes=0;
                    break;
                }
            }
        }
        if(DisplayRes)
        {
            if(logscale) vh=GfxConvertValueToPixelYLog(H[lvix]);
            else vh=GfxConvertValueToPixelY(H[lvix]);
            GfxSelectPen(lnColorRes,lnWidthRes,0);
            GfxMoveTo(GfxConvertBarToPixelX(i),vh);
            GfxLineTo(GfxConvertBarToPixelX(AllVisibleBars-1),vh);
            GfxSelectFont("Tahoma",8,650);GfxSetBkColor(bkColorRes);GfxSetTextColor(colorWhite);
            GfxTextOut(""+H[lvix],GfxConvertBarToPixelX(AllVisibleBars+1),vh);         
        }
    }
    if(tr[lvix])
    {
        if(displayMode)
        {
            lval=L[lvix];
            for(j=i;j<AllVisibleBars;j++)
            {
                lvjx=j+fvb;
                if(L[lvjx]<lval)
                {
                    DisplaySup=0;
                    break;
                }
            }
        }  
        if(DisplaySup)
        {  
            if(logscale) vl=GfxConvertValueToPixelYLog(L[lvix]);
            else vl=GfxConvertValueToPixelY(L[lvix]);      
            GfxSelectPen(lnColorSup,lnWidthSup,0);
            GfxMoveTo(GfxConvertBarToPixelX(i),vl);
            GfxLineTo(GfxConvertBarToPixelX(AllVisibleBars-1),vl);
            GfxSelectFont("Tahoma",8,650);GfxSetBkColor(bkColorSup);GfxSetTextColor(colorWhite);
            GfxTextOut(""+L[lvix],GfxConvertBarToPixelX(AllVisibleBars+1),vl);
        }
    }  
}
}
function plotPivots(pkh,trl,pk,tr,Lx,nbar,fact,x)
{
    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);
}
 
// MAIN code
RequestTimedRefresh(0.1,True);
xx=BarIndex();x=xx;Lx=LastValue(x);
nbar=Param("N Pivot Bars",5,2,50,1);
CleanPivots=ParamToggle("Use Clean Pivots","Off|On",1);
PivotSymmetry=ParamToggle("Use Symmetric Pivots","Off|On",0);
displayMode=ParamToggle("Display Mode","Classic|Alternative",1);
logscale=ParamToggle("Axis type","Linear|Logarithmic",0);
weeklyTF=ParamToggle("WEEKLY timeframe","Off|On",1);
weeklyLineColorRes=ParamColor("WEEKLY Line Color (resistance)",ColorRGB(150,0,0));
weeklyLineColorSup=ParamColor("WEEKLY Line Color (support)",ColorRGB(0,0,150));
weeklyBackColorRes=ParamColor("WEEKLY Back Color (resistance)",ColorRGB(250,0,0));
weeklyBackColorSup=ParamColor("WEEKLY Back Color (support)",ColorRGB(0,0,250));
weeklyLineWidth=Param("WEEKLY Line Width",6,1,10,1);
dailyTF=ParamToggle("DAILY timeframe","Off|On",1);
dailyLineColorRes=ParamColor("DAILY Line Color (resistance)",ColorRGB(50,0,0));
dailyLineColorSup=ParamColor("DAILY Line Color (support)",ColorRGB(0,0,50));
dailyBackColorRes=ParamColor("DAILY Back Color (resistance)",ColorRGB(250,0,0));
dailyBackColorSup=ParamColor("DAILY Back Color (support)",ColorRGB(0,0,250));
dailyLineWidth=Param("DAILY Line Width",2,1,10,1);
 
SetChartOptions(0,chartShowDates);
if(logscale) SetChartOptions(2,chartLogarithmic,chartGridMiddle|chartGridMargins);
else SetChartOptions(3,chartLogarithmic,!(chartGridMiddle|chartGridMargins)); 
 
GraphXSpace=5;SetChartBkColor(ColorRGB(0,0,0));
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);
 
// setup for weekly
if(weeklyTF)
{
calculatePivots(inWeekly,PivotSymmetry,nbar,CleanPivots,x);
displayLines(pk,tr,weeklyBackColorRes,weeklyBackColorSup,weeklyLineColorRes,weeklyLineColorSup,weeklyLineWidth,weeklyLineWidth,displayMode,logscale);
plotPivots(pkh,trl,pk,tr,Lx,nbar,fact,x);
}
// setup for daily
if(dailyTF)
{
calculatePivots(inDaily,PivotSymmetry,nbar,CleanPivots,x);
displayLines(pk,tr,dailyBackColorRes,dailyBackColorSup,dailyLineColorRes,dailyLineColorSup,dailyLineWidth,dailyLineWidth,displayMode,logscale);
plotPivots(pkh,trl,pk,tr,Lx,nbar,fact,x);
}
Back