1 //+------------------------------------------------------------------+
\r
2 //| VoltyChannel_Stop_v2.mq4 |
\r
3 //| Copyright © 2007, TrendLaboratory |
\r
4 //| http://finance.groups.yahoo.com/group/TrendLaboratory |
\r
5 //| E-mail: igorad2003@yahoo.co.uk |
\r
6 //+------------------------------------------------------------------+
\r
7 #property copyright "Copyright © 2007, TrendLaboratory"
\r
8 #property link "http://finance.groups.yahoo.com/group/TrendLaboratory"
\r
10 #property indicator_chart_window
\r
11 #property indicator_buffers 4
\r
12 #property indicator_color1 Blue
\r
13 #property indicator_color2 Red
\r
14 #property indicator_color3 Blue
\r
15 #property indicator_color4 Red
\r
16 #property indicator_width1 1
\r
17 #property indicator_width2 1
\r
18 #property indicator_width3 1
\r
19 #property indicator_width4 1
\r
20 //---- input parameters
\r
21 extern int Price = 0; //Applied Price: 0-C,1-O,2-H,3-L,4-Median,5-Typical,6-Weighted
\r
22 extern int MA_Length = 1; //MA's Period
\r
23 extern int MA_Mode = 0; //MA's Method:0-SMA,1-EMA,2-SMMA,3-LWMA
\r
24 extern int ATR_Length =10; //ATR's Period
\r
25 extern double Kv = 4; //Volatility's Factor or Multiplier
\r
26 extern double MoneyRisk = 1; //Offset Factor
\r
27 extern int AlertMode = 0; //0-alert off,1-on
\r
28 extern int VisualMode = 0; //0-lines,1-dots
\r
29 //---- indicator buffers
\r
38 bool UpTrendAlert=false, DownTrendAlert=false;
\r
39 //+------------------------------------------------------------------+
\r
40 //| Custom indicator initialization function |
\r
41 //+------------------------------------------------------------------+
\r
45 //---- indicator line
\r
46 IndicatorBuffers(7);
\r
47 SetIndexBuffer(0,UpBuffer);
\r
48 SetIndexBuffer(1,DnBuffer);
\r
49 SetIndexBuffer(2,UpSignal);
\r
50 SetIndexBuffer(3,DnSignal);
\r
51 SetIndexBuffer(4,smin);
\r
52 SetIndexBuffer(5,smax);
\r
53 SetIndexBuffer(6,trend);
\r
57 SetIndexStyle(0,DRAW_LINE);
\r
58 SetIndexStyle(1,DRAW_LINE);
\r
62 SetIndexStyle(0,DRAW_ARROW);
\r
63 SetIndexStyle(1,DRAW_ARROW);
\r
64 SetIndexArrow(0,159);
\r
65 SetIndexArrow(1,159);
\r
68 SetIndexStyle(2,DRAW_ARROW);
\r
69 SetIndexStyle(3,DRAW_ARROW);
\r
70 SetIndexArrow(2,108);
\r
71 SetIndexArrow(3,108);
\r
72 //---- name for DataWindow and indicator subwindow label
\r
73 short_name="VoltyChannel_Stop("+MA_Length+","+ATR_Length+","+DoubleToStr(Kv,3)+")";
\r
74 IndicatorShortName(short_name);
\r
75 SetIndexLabel(0,"UpTrend");
\r
76 SetIndexLabel(1,"DnTrend");
\r
77 SetIndexLabel(2,"UpSignal");
\r
78 SetIndexLabel(3,"DnSignal");
\r
80 SetIndexDrawBegin(0,MA_Length+ATR_Length);
\r
81 SetIndexDrawBegin(1,MA_Length+ATR_Length);
\r
82 SetIndexDrawBegin(2,MA_Length+ATR_Length);
\r
83 SetIndexDrawBegin(3,MA_Length+ATR_Length);
\r
89 //+------------------------------------------------------------------+
\r
90 //| VoltyChannel_Stop_2 |
\r
91 //+------------------------------------------------------------------+
\r
95 int shift,limit, counted_bars=IndicatorCounted();
\r
97 if ( counted_bars > 0 ) limit=Bars-counted_bars;
\r
98 if ( counted_bars < 0 ) return(0);
\r
99 if ( counted_bars ==0 ) limit=Bars-MA_Length-1;
\r
101 for(shift=limit;shift>=0;shift--)
\r
103 if(Price==2 || Price==3)
\r
105 double bprice = iMA(NULL,0,MA_Length,0,MA_Mode,2,shift);
\r
106 double sprice = iMA(NULL,0,MA_Length,0,MA_Mode,3,shift);
\r
110 bprice = iMA(NULL,0,MA_Length,0,MA_Mode,Price,shift);
\r
111 sprice = iMA(NULL,0,MA_Length,0,MA_Mode,Price,shift);
\r
114 smin[shift] = sprice - Kv*iATR(NULL,0,ATR_Length,shift);
\r
115 smax[shift] = bprice + Kv*iATR(NULL,0,ATR_Length,shift);
\r
117 trend[shift]=trend[shift+1];
\r
118 if ( bprice > smax[shift+1] ) trend[shift] = 1;
\r
119 if ( sprice < smin[shift+1] ) trend[shift] = -1;
\r
121 if ( trend[shift] >0 )
\r
123 if( smin[shift] < smin[shift+1]) smin[shift] = smin[shift+1];
\r
124 UpBuffer[shift] = smin[shift] - (MoneyRisk - 1)*iATR(NULL,0,ATR_Length,shift);
\r
125 if( UpBuffer[shift] < UpBuffer[shift+1] && UpBuffer[shift+1]!=EMPTY_VALUE) UpBuffer[shift] = UpBuffer[shift+1];
\r
126 if(trend[shift+1] != trend[shift]) UpSignal[shift] = UpBuffer[shift];
\r
127 else UpSignal[shift] = EMPTY_VALUE;
\r
128 DnBuffer[shift] = EMPTY_VALUE;
\r
129 DnSignal[shift] = EMPTY_VALUE;
\r
132 if ( trend[shift] <0 )
\r
134 if( smax[shift]>smax[shift+1]) smax[shift] = smax[shift+1];
\r
135 DnBuffer[shift] = smax[shift] + (MoneyRisk - 1)*iATR(NULL,0,ATR_Length,shift);
\r
136 if( DnBuffer[shift] > DnBuffer[shift+1]) DnBuffer[shift] = DnBuffer[shift+1];
\r
137 if(trend[shift+1] != trend[shift]) DnSignal[shift] = DnBuffer[shift];
\r
138 else DnSignal[shift] = EMPTY_VALUE;
\r
139 UpBuffer[shift] = EMPTY_VALUE;
\r
140 UpSignal[shift] = EMPTY_VALUE;
\r
146 if ( trend[2]<0 && trend[1]>0 && Volume[0]>1 && !UpTrendAlert)
\r
148 Message = " "+Symbol()+" M"+Period()+": Signal for BUY";
\r
149 if ( AlertMode>0 ) Alert (Message);
\r
150 UpTrendAlert=true; DownTrendAlert=false;
\r
153 if ( trend[2]>0 && trend[1]<0 && Volume[0]>1 && !DownTrendAlert)
\r
155 Message = " "+Symbol()+" M"+Period()+": Signal for SELL";
\r
156 if ( AlertMode>0 ) Alert (Message);
\r
157 DownTrendAlert=true; UpTrendAlert=false;
\r