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

TSL&VSTOP&TGL 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
// VSTOP&ATR
 
// E.M.Pottasch, Jul 2010
// from Metastock formula, link: http://stocata.org/metastock/stop_trail_atr.html
// added separate parameters for upward and downward market environment
 
function vstop_func(trBull,trBear)
{
    trailArray[ 0 ] = C[ 0 ]; // initialize
    for( i = 1; i < BarCount; i++ )
    {
        prev = trailArray[ i - 1 ];
  
        if (C[ i ] > prev AND C[ i - 1 ] > prev)
        {
            trailArray[ i ] = Max(prev,C[ i ] - trBull[ i ]);
        }
        else if (C[ i ] < prev AND C[ i - 1 ] < prev)
        {
            trailArray[ i ] = Min(prev,C[ i ] + trBear[ i ]);
        }
        else if (C[ i ] > prev)
        {
            trailArray[ i ] = C[ i ] - trBull[ i ];
        }
        else
        {
            trailArray[ i ] = C[ i ] + trBear[ i ];
        }
    }
    return trailArray;
}
 
VSTOPATRper = Param("VSTOPper",14,1,50,1,0) ;
 
Res = Param("VSTOPMultRes",2,1,10,0.1,0) ;
Sup = Param("VSTOPMultSup",2,1,10,0.1,0) ;
 
trBear = res * ATR(VSTOPatrper);
trBull = sup  * ATR(VSTOPatrper);
 
trailArray = vstop_func(trbull,trbear);
trailARRAYcolor= IIf(C>trailARRAY,colorBlue,colorRed) ;
 
Plot(trailArray,"\nVSTOP",trailARRAYcolor,8+16) ;
 
//Plot(IIf(trailArray > C,trailArray,Null),"\ntrailShort",ParamColor("ColorTrailShort",ColorRGB(255,0,0)),styleStaircase);//ORIGINAL
//Plot(IIf(trailArray < C,trailArray,Null),"\ntrailLong",ParamColor("ColorTrailLong",ColorRGB(0,255,0)),styleStaircase);//ORIGINAL
 
Buystop= C>trailArray ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//PRICE
 
_SECTION_BEGIN("Price");
//SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%)Vol " +
            WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//HEIKIN-ASHI ORIGINAL
 
//SetChartOptions(0,chartShowArrows | chartShowDates);
HaClose = (O + H + L + C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
xDiff = (HaHigh - Halow) * 10000;
barcolor = IIf(HaClose >= HaOpen,colorGreen,colorRed);
//SetBarFillColor(IIf(HaClose>=HaOpen,colorBrightGreen,colorOrange));
//PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "\nHeikin-ashi", barcolor, styleCandle );
 
//HaDelta & MA
 
HaDelta= HaClose-HaOpen ;
Hadeltaup3= Hadelta>MA(Hadelta,3) ;
Hadeltaup33 = Hadelta>MA(MA(Hadelta,3),3) ;
//Plot(Hadelta,"haDelta",colorBlack) ;
//Plot(0,"",colorBrown) ;
//Plot( MA1, "MA1", colorRed );
//Plot( MA2, "MA2", colorBlue );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//TRENDING RIBBON
 
// Paste the code below to your price chart somewhere and green ribbon means both
// both MACD and ADX trending up so if the red ribbon shows up the MACD and the ADX
// are both trending down.
_SECTION_BEGIN("trending ribbon");
uptrend= (PDI()>MDI() AND MACD()>Signal()) ;
downtrend=MDI()>PDI() AND Signal()>MACD();
Plot( 2, /* defines the height of the ribbon in percent of pane width */"",
    IIf( uptrend , colorLime, IIf( downtrend ,
     colorRed, colorTan)) , /* choose color */styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//BB HISTOGRAM
 
_SECTION_BEGIN("BB Histogram");
bbhist=((C+2*StDev(C,20) - MA(C,18)) / ((4*StDev(C,18)))*4) - 2;
//Plot(bbhist, "BBands Histogram", IIf(bbhist > 0, colorLime, colorRed),styleHistogram + styleThick);
_SECTION_END();
 
bbhistup0= bbhist>0 ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//TRENDADVISOR
 
pointer[0] = 0;
 
/* Phase filter */
 
Cond1 = Close > MA(Close, 50)AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));
Cond2 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND NOT(MA(Close, 50) > MA(Close, 200));
Cond3 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200);
Cond4 = NOT(Close > MA(Close, 50))AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200);
Cond5 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND MA(Close, 50) > MA(Close, 200);
Cond6 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));
 
for (i = 1; i < BarCount; i++)
{
 
  if (Cond1[i])
    pointer[i] = 1;
  if (Cond2[i])
    pointer[i] = 2;
  if (Cond3[i])
    pointer[i] = 3;
  if (Cond4[i])
    pointer[i] = 4;
  if (Cond5[i])
    pointer[i] = 5;
  if (Cond6[i])
    pointer[i] = 6;
 
}
 
/* Plot Graphic */
//GraphXSpace= 15 ;
dynamic_color = IIf(pointer < 4, colorGreen, colorRed);
//Plot(pointer, "TrendAdv2", dynamic_color, styleHistogram | styleThick, Null, Null, 0);
//SetChartBkGradientFill(ParamColor("BgTop", colorWhite), ParamColor("BgBottom", colorLightYellow));
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//FORMULE
 
stochup= StochK()>StochD() ;
stoch80= StochK()<80 ;
MACDup= MACD()>Signal() ;
Hist= MACD()-Signal() ;
Histup= Hist>Ref(Hist,-1) ;
MFIupema5= MFI()>EMA(MFI(),5) ;
MFI30= MFI()>30 ;
Cupo= C>O ;
MA10up= MA(C,10)>=Ref(MA(C,10),-1) ;
MA20up= MA(C,20)>=Ref(MA(C,20),-1) ;
EMA50up= EMA(C,50)>=Ref(EMA(C,50),-1) ;
CupEMA50= C>EMA(C,50) ;
Cupma20= C>MA(C,20) ;
PDIupmdi= PDI()>MDI() ;
CCIup0= CCI()>0 ;
Cond= pointer<4 ;
top2up= BBandTop(C,20,2)>=Ref(BBandTop(C,20,2),-1) ;
top1up= BBandTop(C,20,1)>=Ref(BBandTop(C,20,1),-1) ;
Cuptop1= C>BBandTop(C,20,1) ;
buystop= C>trailArray ;
haup= HaClose>=HaOpen ;
Lim= (ADX()<50 AND MFI()>30) ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
//PARAMTOGGLE
 
// This combines indicators into one timing Signal
//function ParamOptimize( description, default, minv, maxv, step )
//    { return Optimize(description, Param(description,default, minv, maxv, step ), minv, maxv, step ); }
tgl = ParamToggle("Result", "AND logic|Compare");
// switch test calculation and compare the results
if(tgl)
{
myBuy = buystop AND macdup AND histup AND cupo AND haup ;
myShort = !buystop ;
}
else
{
myBuy   = IIf( C>trailArray AND MACD()>Signal() AND Hist>Ref(Hist,-1) AND C>O AND HaClose>=HaOpen     ,1,0);
myShort = IIf( C<trailArray      ,1,0);
}
 
Buy = ExRem(myBuy, myShort);
Sell = ExRem(myShort, myBuy);
 
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,trailArray);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,trailArray);
Back