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

MA cross BBands and stop(mod) 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
_SECTION_BEGIN("Price Chart");
 
bgTop = ParamColor("BgTop",    colorBlack);
bgBot = ParamColor("BgBottom", colorBlack);
SetChartBkGradientFill( bgTop ,bgBot, colorLightGrey);
 
pStyle = ParamList("Price Style", "Candle|Solid Candle|Bar|Line|Heikin-Ashi",2);
cBull = ParamColor("Price Bull", colorLime);
CBear = ParamColor("Price Bear", colorRed);
cLine = ParamColor("Price Line", colorWhite);
 
_N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C= %g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
SetChartOptions(0,chartShowArrows|chartShowDates);
 
 
ThisStyle = styleCandle;
ThisTitle = "";
 
_O=O; _C=C; _H=H; _L=L;
 
ThisColor = IIf( _C>_O, cBull, IIf(_C<_O, CBear, CLine));
 
 
switch (pStyle )
{
 
  case "Solid Candle":  
        SetBarFillColor( ThisColor );
        break;
 
 
  case "Bar":
       ThisStyle = styleBar;
       break;
 
  case "Line":
      ThisStyle = styleLine;
      ThisColor = cLine;
       break;
 
 
  case "Heikin-Ashi":
       _C = (O+H+L+C)/4;
          _O = AMA( Ref( _C, -1 ), 0.5 );
       _H = Max( H, Max( _C, _O ) );
       _L = Min( L, Min( _C, _O ) );
 
       ThisColor = IIf(_C >= _O,CBull, CBear);
       SetBarFillColor( ThisColor );
  
       ThisColor = IIf(_C >= _O,cLine, cLine);
          ThisTitle = "Heikin-Ashi";
       break;
 
  default:  
        SetBarFillColor( ThisColor );
        ThisColor = cLine;
 
       break;
 
}
 
   PlotOHLC( _O, _H, _L, _C, ThisTitle, ThisColor, ThisStyle);
   GraphXSpace = 8;
 
_SECTION_END();
 
 
_SECTION_BEGIN("BandStop");
/* Done      by    Rajandran R */
/* Author of www.marketcalls.in  */
// BBands_Stop_v1.mq4 by igorad2004@list.ru
// translation in Amibroker AFL, E.M.Pottasch, 2011
 
// Modified By KelvinHand
 
Length=Param("Length",20, 2); // Bollinger Bands Period
Deviation=Param("Deviation",2);
// Deviation was 2
MoneyRisk=Param("Money Risk", 1);
 
LineStyle=ParamToggle("Display line mode", "No|Yes", 1);  // Display line mode: 0-no,1-yes 
cUpTrendLine = ParamColor("UpTrendLine", ColorRGB(65,105,225));
cDnTrendLine = ParamColor("DownTrendLine", colorRed);
 
 
 
 
 
// Offset Factor
TurnedUp=Nz(StaticVarGet("TurnedUp"));
TurnedDown=Nz(StaticVarGet("TurnedDown"));
SoundON = ParamToggle("Sound","Off|On",1);
 
 
procedure CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown)
{
global UpTrendLine;
global DownTrendLine;
global smax;
global smin;
 
    UpTrendLine=Null;
    DownTrendLine=Null;
    smax=Null;
    smin=Null;
    trend=0;
 
 
    for (i=Length+1; i<BarCount; i++)   
  {
        smax[i]=bbtop[i];
        smin[i]=bbbot[i];
        if (C[i]>smax[i-1]) trend=1;
        if (C[i]<smin[i-1]) trend=-1;
        if(trend>0 && smin[i]<smin[i-1]) smin[i]=smin[i-1];
        if(trend<0 && smax[i]>smax[i-1]) smax[i]=smax[i-1];
        bsmax[i]=smax[i]+0.5*(MoneyRisk-1)*(smax[i]-smin[i]);
        bsmin[i]=smin[i]-0.5*(MoneyRisk-1)*(smax[i]-smin[i]);
        if(trend>0 && bsmin[i]<bsmin[i-1]) bsmin[i]=bsmin[i-1];
        if(trend<0 && bsmax[i]>bsmax[i-1]) bsmax[i]=bsmax[i-1];
        if (trend>0)
        {
            UpTrendLine[i]=bsmin[i];
            if (SoundON==True && !TurnedUp && i==BarCount-1 && IsEmpty(UpTrendLine[i-1]))
            {
                Say("Bollinger Bands going Up");
                TurnedUp=StaticVarSet("TurnedUp",1);
                TurnedDown=StaticVarSet("TurnedDown",0);
 
            }
        }
     
    if (trend<0)
        {
            DownTrendLine[i]=bsmax[i];
            if (SoundON==True && !TurnedDown && i==BarCount-1 && IsEmpty(DownTrendLine[i-1]))
            {
                Say("Bollinger Bands going Down");
                TurnedUp=StaticVarSet("TurnedUp",0);
                TurnedDown=StaticVarSet("TurnedDown",1);
            }
        } //if (trend<0)
    } //for
} //procedure
 
    bbtop=BBandTop(C,Length,Deviation);
    bbbot=BBandBot(C,Length,Deviation);
 
Buy = Cross (C,BBandTop(C,Length,Deviation ));
Sell = Cross (C,HHV( C - 2.8 * ATR(10), 15 ));
TrailStop = HHV( C - 2.8 * ATR(30), 15 );
/* plot price chart and stops */
Plot( TrailStop, "Trailing stop", colorOrange, styleThick | styleLine );
 
    CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown);
    UpTrendSigNal=UpTrendLine AND IsEmpty(Ref(UpTrendLine,-1));
    DownTrendSigNal=DownTrendLine AND IsEmpty(Ref(DownTrendLine,-1));
 
  DisplayStyle = styleNoLabel|styleDots|styleNoTitle;
  if(LineStyle == 0) DisplayStyle |= styleNoLine;
 
 
    Plot(UpTrendLine,"UPTRENDLINE",cUpTrendLine,DisplayStyle);
    Plot(DownTrendLine,"DOWNTRENDLINE",cDnTrendLine,DisplayStyle) ;
 
    PlotShapes(IIf(UpTrendSignal,shapeCircle,shapeNone),cUpTrendLine,0,bbbot,0);
    PlotShapes(IIf(DownTrendSignal,shapeCircle,shapeNone),cDnTrendLine,0,bbtop,0);
_SECTION_END();
 
_SECTION_BEGIN("Wave Channel");
 
cOutLine = ParamColor("Outer Line", colorWhite);
cMidLine = ParamColor("Mid Line", colorGrey40);
 
  Plot( MA(C, 34), "", cMidLine, styleNoLabel);
  Plot( MA(H, 34), "", cOutLine, styleThick|styleNoLabel);
  Plot( MA(L, 34), "", cOutLine, styleThick|styleNoLabel);
 
 
_SECTION_END();
 
_SECTION_BEGIN("WMA Rainbow");
 
cOutLine = ParamColor("Outline", colorBlue);
cInnerLine = ParamColor("Innerline", colorDarkBlue);
 
 
  Plot( WMA(C, 2), "", cOutLine, styleThick|styleNoLabel);
  Plot( WMA(C, 8), "", cOutLine, styleThick|styleNoLabel);
 
  Plot( WMA(C, 3), "", cInnerLine, styleNoLabel);
  Plot( WMA(C, 4), "", cInnerLine, styleNoLabel);
  Plot( WMA(C, 5), "", cInnerLine, styleNoLabel);
  Plot( WMA(C, 6), "", cInnerLine, styleNoLabel);
  Plot( WMA(C, 7), "", cInnerLine, styleNoLabel);
 
SetOption("InitialEquity", 100000 );
SetTradeDelays(1,1,1,1);
RoundLotSize = 1;
 
posqty = Optimize("PosQty", 5, 4, 8, 1 );
 
PositionSize = -100/posqty;
 
PositionScore = 100-RSI(); // prefer stocks that have low RSI;
 
PosQty = 10;
SetOption("MaxOpenPositions", PosQty );
PositionSize = -100/PosQty;
 
SetOption("futuresmode",False); //tryb futures wylaczony
SetOption("Minposvalue",5400); //min pozycja za kwote 1400 ze wzgledu na prowizje
SetOption("commissionmode",1); //rodzaj prowizji(procentowy)
SetOption("commissionamount",0.39); //wartosc prowizji
 
 
_SECTION_END();
Back