Author: Copyright © 2007, IZZY
Indicators Used
Bollinger bands indicator
2 Views
0 Downloads
0 Favorites
VTS_BB
ÿþ//+------------------------------------------------------------------+

//|                                                       VTS_BB.mq5 |

//|                                           Copyright © 2007, IZZY | 

//|                                                                  | 

//+------------------------------------------------------------------+  

//--- 02B>@AB2> 8=48:0B>@0

#property copyright "Copyright © 2007, IZZY"

//--- AAK;:0 =0 A09B 02B>@0

#property link      ""

//--- =><5@ 25@A88 8=48:0B>@0

#property version   "1.00"

//--- >B@8A>2:0 8=48:0B>@0 2 3;02=>< >:=5

#property indicator_chart_window 

//--- 4;O @0AG5B0 8 >B@8A>2:8 8=48:0B>@0 8A?>;L7>20=> 2>A5<L 1CD5@>2

#property indicator_buffers 8

//--- 8A?>;L7>20=> 2A53> 2>A5<L 3@0D8G5A:8E ?>AB@>5=89

#property indicator_plots   8

//+----------------------------------------------+

//|  0@0<5B@K >B@8A>2:8 <54256L53> 8=48:0B>@0 1 |

//+----------------------------------------------+

//--- >B@8A>2:0 8=48:0B>@0 2 2845 ;8=88 

#property indicator_type1   DRAW_LINE

//--- 2 :0G5AB25 F25B0 <54256L59 ;8=88 8=48:0B>@0 8A?>;L7>20= >@0=652K9 F25B

#property indicator_color1  clrOrange

//--- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 2

#property indicator_width1  2

//--- >B>1@065=85 1KG59 <5B:8 8=48:0B>@0

#property indicator_label1  "VTS Sell"

//+----------------------------------------------+

//|  0@0<5B@K >B@8A>2:8 1KGL3> 8=48:0B>@0 1     |

//+----------------------------------------------+

//--- >B@8A>2:0 8=48:0B>@0 2 2845 ;8=88 

#property indicator_type2   DRAW_LINE

//--- 2 :0G5AB25 F25B0 1KG59 ;8=88 8=48:0B>@0 8A?>;L7>20= 75;5=K9 F25B

#property indicator_color2  clrDarkGreen

//--- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 2

#property indicator_width2  2

//--- >B>1@065=85 <54256L59 <5B:8 8=48:0B>@0

#property indicator_label2 "VTS Buy"

//+----------------------------------------------+

//|  0@0<5B@K >B@8A>2:8 <54256L53> 8=48:0B>@0 2 |

//+----------------------------------------------+

//--- >B@8A>2:0 8=48:0B>@0 2 2845 ;8=88 

#property indicator_type3   DRAW_LINE

//--- 2 :0G5AB25 F25B0 <54256L59 ;8=88 8=48:0B>@0 8A?>;L7>20= >@0=652K9 F25B

#property indicator_color3  clrOrange

//--- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 2

#property indicator_width3  2

//--- >B>1@065=85 1KG59 <5B:8 8=48:0B>@0

#property indicator_label3  "VTS Sell"

//+----------------------------------------------+

//|  0@0<5B@K >B@8A>2:8 1KGL3> 8=48:0B>@0 2     |

//+----------------------------------------------+

//--- >B@8A>2:0 8=48:0B>@0 2 2845 ;8=88 

#property indicator_type4   DRAW_LINE

//--- 2 :0G5AB25 F25B0 1KG59 ;8=88 8=48:0B>@0 8A?>;L7>20= 75;5=K9 F25B

#property indicator_color4  clrDarkGreen

//--- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 2

#property indicator_width4  2

//--- >B>1@065=85 <54256L59 <5B:8 8=48:0B>@0

#property indicator_label4 "VTS Buy"

//+----------------------------------------------+

//|  0@0<5B@K >B@8A>2:8 <54256L53> 8=48:0B>@0 3 |

//+----------------------------------------------+

//--- >B@8A>2:0 8=48:0B>@0 2 2845 ;8=88 

#property indicator_type5   DRAW_LINE

//--- 2 :0G5AB25 F25B0 <54256L59 ;8=88 8=48:0B>@0 8A?>;L7>20= >@0=652K9 F25B

#property indicator_color5  clrOrange

//--- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 2

#property indicator_width5  2

//--- >B>1@065=85 1KG59 <5B:8 8=48:0B>@0

#property indicator_label5  "VTS Sell"

//+----------------------------------------------+

//|  0@0<5B@K >B@8A>2:8 1KGL3> 8=48:0B>@0 3     |

//+----------------------------------------------+

//--- >B@8A>2:0 8=48:0B>@0 2 2845 ;8=88 

#property indicator_type6   DRAW_LINE

//--- 2 :0G5AB25 F25B0 1KG59 ;8=88 8=48:0B>@0 8A?>;L7>20= 75;5=K9 F25B

#property indicator_color6  clrDarkGreen

//--- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 2

#property indicator_width6  2

//--- >B>1@065=85 <54256L59 <5B:8 8=48:0B>@0

#property indicator_label6 "VTS Buy"

//+----------------------------------------------+

//|  0@0<5B@K >B@8A>2:8 <54256L53> 8=48:0B>@0 4 |

//+----------------------------------------------+

//--- >B@8A>2:0 8=48:0B>@0 2 2845 A8<2>;0

#property indicator_type7   DRAW_ARROW

//--- 2 :0G5AB25 F25B0 <54256L59 ;8=88 8=48:0B>@0 8A?>;L7>20= >@0=652K9 F25B

#property indicator_color7  clrRed

//--- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 2

#property indicator_width7  2

//--- >B>1@065=85 1KG59 <5B:8 8=48:0B>@0

#property indicator_label7  "VTS Sell"

//+----------------------------------------------+

//|  0@0<5B@K >B@8A>2:8 1KGL3> 8=48:0B>@0 4     |

//+----------------------------------------------+

//--- >B@8A>2:0 8=48:0B>@0 2 2845 A8<2>;0

#property indicator_type8   DRAW_ARROW

//--- 2 :0G5AB25 F25B0 1KG59 ;8=88 8=48:0B>@0 8A?>;L7>20= A0;0B>2K9 F25B

#property indicator_color8  clrMediumSpringGreen

//--- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 2

#property indicator_width8  2

//--- >B>1@065=85 <54256L59 <5B:8 8=48:0B>@0

#property indicator_label8 "VTS Buy"

//+----------------------------------------------+

//|  >1JO2;5=85 :>=AB0=B                         |

//+----------------------------------------------+

#define RESET  0 // >=AB0=B0 4;O 2>72@0B0 B5@<8=0;C :><0=4K =0 ?5@5AGQB 8=48:0B>@0

//+----------------------------------------------+

//| E>4=K5 ?0@0<5B@K 8=48:0B>@0                 |

//+----------------------------------------------+

input uint   BB_Period=10;

input double deviation=2.0;         // :>;-2> AB0=40@B=KE >B:;>=5=89 

input ENUM_APPLIED_PRICE  applied_price=PRICE_CLOSE;      // B8? F5=K

//+----------------------------------------------+

//--- >1JO2;5=85 48=0<8G5A:8E <0AA82>2, :>B>@K5 2 40;L=59H5< 1C4CB 8A?>;L7>20=K 2 :0G5AB25 8=48:0B>@=KE 1CD5@>2

double UpIndBuffer1[],DnIndBuffer1[];

double UpIndBuffer2[],DnIndBuffer2[];

double UpIndBuffer3[],DnIndBuffer3[];

double UpIndBuffer4[],DnIndBuffer4[];

//---

int BB_Handle,min_rates_total;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- 8=8F80;870F8O 3;>10;L=KE ?5@5<5==KE 

   min_rates_total=int(BB_Period)+30;

//--- ?>;CG5=85 E5=4;0 8=48:0B>@0 BB

   BB_Handle=iBands(NULL,0,BB_Period,0,deviation,applied_price);

   if(BB_Handle==INVALID_HANDLE)

     {

      Print(" 5 C40;>AL ?>;CG8BL E5=4; 8=48:0B>@0 BB");

      return(INIT_FAILED);

     }

//--- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(0,DnIndBuffer1,INDICATOR_DATA);

//--- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0 1

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

//--- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(DnIndBuffer1,true);

//--- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(1,UpIndBuffer1,INDICATOR_DATA);

//--- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);

//--- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(UpIndBuffer1,true);



//--- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(2,DnIndBuffer2,INDICATOR_DATA);

//--- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0

   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);

//--- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(DnIndBuffer2,true);

//--- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(3,UpIndBuffer2,INDICATOR_DATA);

//--- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0

   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total);

//--- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(UpIndBuffer2,true);



//--- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(4,DnIndBuffer3,INDICATOR_DATA);

//--- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0

   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,min_rates_total);

//--- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(DnIndBuffer3,true);

//--- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(5,UpIndBuffer3,INDICATOR_DATA);

//--- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0

   PlotIndexSetInteger(5,PLOT_DRAW_BEGIN,min_rates_total);

//--- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(UpIndBuffer3,true);



//--- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(6,DnIndBuffer4,INDICATOR_DATA);

//--- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0

   PlotIndexSetInteger(6,PLOT_DRAW_BEGIN,min_rates_total);

//--- A8<2>; 4;O 8=48:0B>@0

   //PlotIndexSetInteger(6,PLOT_ARROW,234);

//--- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(DnIndBuffer4,true);

//--- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(7,UpIndBuffer4,INDICATOR_DATA);

//--- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0

   PlotIndexSetInteger(7,PLOT_DRAW_BEGIN,min_rates_total);

//--- A8<2>; 4;O 8=48:0B>@0

   //PlotIndexSetInteger(7,PLOT_ARROW,233);

//--- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(UpIndBuffer4,true);



//--- #AB0=>2:0 D>@<0B0 B>G=>AB8 >B>1@065=8O 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//--- 8<O 4;O >:>= 40==KE 8 <5B:0 4;O ?>4>:>= 

   string short_name="VTS_BB";

   IndicatorSetString(INDICATOR_SHORTNAME,short_name);

//---   

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//--- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AG5B0

   if(BarsCalculated(BB_Handle)<rates_total || rates_total<min_rates_total) return(RESET);



//--- >1JO2;5=8O ;>:0;L=KE ?5@5<5==KE 

   int to_copy,limit,bar;

   double UpBB[],DnBB[];

   double VTS,VTS1,VTS2,VTS3,VTS4,VTS5,VTS6,VTS7,VTS8,VTS9;

   double VTS10,VTS11,VTS12,VTS13,VTS14,VTS15,VTS16,VTS17,VTS18,VTS19;

   double VTS20,VTS21,VTS22,VTS23;



   static double VTS_prev,VTS1_prev,VTS2_prev,VTS3_prev,VTS4_prev,VTS5_prev,VTS6_prev,VTS7_prev,VTS8_prev,VTS9_prev;

   static double VTS10_prev,VTS11_prev,VTS12_prev,VTS13_prev,VTS14_prev,VTS15_prev,VTS16_prev,VTS17_prev,VTS18_prev,VTS19_prev;

   static double VTS20_prev,VTS21_prev,VTS22_prev,VTS23_prev;



//--- @0AG5BK =5>1E>48<>3> :>;8G5AB20 :>?8@C5<KE 40==KE 8 AB0@B>2>3> =><5@0 limit 4;O F8:;0 ?5@5AG5B0 10@>2

   if(prev_calculated>rates_total || prev_calculated<=0)// ?@>25@:0 =0 ?5@2K9 AB0@B @0AG5B0 8=48:0B>@0

     {

      limit=rates_total-min_rates_total; // AB0@B>2K9 =><5@ 4;O @0AG5B0 2A5E 10@>2

      double res=close[limit+1];

      VTS_prev=res;

      VTS1_prev=res;

      VTS2_prev=res;

      VTS3_prev=res;

      VTS4_prev=res;

      VTS5_prev=res;

      VTS6_prev=res;

      VTS7_prev=res;

      VTS8_prev=res;

      VTS9_prev=res;

      VTS10_prev=res;

      VTS11_prev=res;

      VTS12_prev=res;

      VTS13_prev=res;

      VTS14_prev=res;

      VTS15_prev=res;

      VTS16_prev=res;

      VTS17_prev=res;

      VTS18_prev=res;

      VTS19_prev=res;

      VTS20_prev=res;

      VTS21_prev=res;

      VTS22_prev=res;

      VTS23_prev=res;

     }

   else

     {

      limit=rates_total-prev_calculated; // AB0@B>2K9 =><5@ 4;O @0AG5B0 =>2KE 10@>2

     }

   to_copy=limit+1; 

//--- :>?8@C5< 2=>2L ?>O282H85AO 40==K5 2 <0AA82K

   if(CopyBuffer(BB_Handle,UPPER_BAND,0,to_copy,UpBB)<=0) return(RESET);

   if(CopyBuffer(BB_Handle,LOWER_BAND,0,to_copy,DnBB)<=0) return(RESET);

//--- 8=45:A0F8O M;5<5=B>2 2 <0AA820E :0: 2 B09<A5@8OE  

   ArraySetAsSeries(UpBB,true);

   ArraySetAsSeries(DnBB,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);



//--- >A=>2=>9 F8:; @0AG5B0 8=48:0B>@0

   for(bar=limit; bar>=0 && !IsStopped(); bar--)

     {

      //---

      VTS=DnBB[bar];

      VTS1=UpBB[bar];

      //---  

      VTS2= MathMax(VTS,VTS_prev);

      VTS3= MathMin(VTS1,VTS1_prev);

      VTS4= MathMax(VTS2,VTS2_prev);

      VTS5= MathMin(VTS3,VTS3_prev);

      VTS6= MathMax(VTS4,VTS4_prev);

      VTS7= MathMin(VTS5,VTS5_prev);

      VTS8= MathMax(VTS6,VTS6_prev);

      VTS9= MathMin(VTS7,VTS7_prev);

      VTS10= MathMax(VTS8,VTS8_prev);

      VTS11= MathMin(VTS9,VTS9_prev);

      VTS12= MathMax(VTS10,VTS10_prev);

      VTS13= MathMin(VTS11,VTS11_prev);

      VTS14= MathMax(VTS12,VTS12_prev);

      VTS15= MathMin(VTS13,VTS13_prev);

      VTS16= MathMax(VTS14,VTS14_prev);

      VTS17= MathMin(VTS15,VTS15_prev);

      VTS18= MathMax(VTS16,VTS16_prev);

      VTS19= MathMin(VTS17,VTS17_prev);

      VTS20= MathMax(VTS18,VTS18_prev);

      VTS21= MathMin(VTS19,VTS19_prev);

      VTS22= MathMax(VTS20,VTS20_prev);

      VTS23= MathMin(VTS21,VTS21_prev);

      UpIndBuffer1[bar]= MathMax(VTS22,VTS22_prev);

      DnIndBuffer1[bar]= MathMin(VTS23,VTS23_prev);

      UpIndBuffer2[bar]= MathMax(UpIndBuffer1[bar],UpIndBuffer1[bar+1]);

      DnIndBuffer2[bar]= MathMin(DnIndBuffer1[bar],DnIndBuffer1[bar+1]);

      UpIndBuffer3[bar]= MathMax(UpIndBuffer2[bar],UpIndBuffer2[bar+1]);

      DnIndBuffer3[bar]= MathMin(DnIndBuffer2[bar],DnIndBuffer2[bar+1]);

      UpIndBuffer4[bar]=UpIndBuffer4[bar+1];

      DnIndBuffer4[bar]=DnIndBuffer4[bar+1];

      if(close[bar]>DnIndBuffer3[bar])

        {

         UpIndBuffer4[bar]=UpIndBuffer3[bar];

         DnIndBuffer4[bar]=NULL;

        }

      if(close[bar]<UpIndBuffer3[bar])

        {

         DnIndBuffer4[bar]=DnIndBuffer3[bar];

         UpIndBuffer4[bar]=NULL;

        }



      if(bar)

        {

         VTS_prev=VTS;

         VTS1_prev=VTS1;

         VTS2_prev=VTS2;

         VTS3_prev=VTS3;

         VTS4_prev=VTS4;

         VTS5_prev=VTS5;

         VTS6_prev=VTS6;

         VTS7_prev=VTS7;

         VTS8_prev=VTS8;

         VTS9_prev=VTS9;

         VTS10_prev=VTS10;

         VTS11_prev=VTS11;

         VTS12_prev=VTS12;

         VTS13_prev=VTS13;

         VTS14_prev=VTS14;

         VTS15_prev=VTS15;

         VTS16_prev=VTS16;

         VTS17_prev=VTS17;

         VTS18_prev=VTS18;

         VTS19_prev=VTS19;

         VTS20_prev=VTS20;

         VTS21_prev=VTS21;

         VTS22_prev=VTS22;

         VTS23_prev=VTS23;

        }

     }

//---     

   return(rates_total);

  }

//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---