VTS_Float_Pivot_Smoothed

Author: Copyright © 2007, IZZY
0 Views
0 Downloads
0 Favorites
VTS_Float_Pivot_Smoothed
ÿþ//+------------------------------------------------------------------+

//|                                     VTS_Float_Pivot_Smoothed.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= Purple F25B

#property indicator_color1  clrPurple

//--- 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= A8=89 F25B

#property indicator_color2  clrBlue

//--- 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= Purple F25B

#property indicator_color3  clrPurple

//--- 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= A8=89 F25B

#property indicator_color4  clrBlue

//--- 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= Purple F25B

#property indicator_color5  clrPurple

//--- 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= A8=89 F25B

#property indicator_color6  clrBlue

//--- 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= @>7>2K9 F25B

#property indicator_color7  clrMagenta

//--- 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

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

//|  ?8A0=85 :;0AA>2 CA@54=5=89                 |

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

#include <SmoothAlgorithms.mqh> 

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

//---- >1JO2;5=85 ?5@5<5==KE :;0AA0 CXMA 87 D09;0 SmoothAlgorithms.mqh

CXMA XMAL,XMAH,XMAP;

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

//|  >1JO2;5=85 ?5@5G8A;5=89                     |

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

/*enum Smooth_Method - ?5@5G8A;5=85 >1JO2;5=> 2 D09;5 SmoothAlgorithms.mqh

  {

   MODE_SMA_,  //SMA

   MODE_EMA_,  //EMA

   MODE_SMMA_, //SMMA

   MODE_LWMA_, //LWMA

   MODE_JJMA,  //JJMA

   MODE_JurX,  //JurX

   MODE_ParMA, //ParMA

   MODE_T3,    //T3

   MODE_VIDYA, //VIDYA

   MODE_AMA,   //AMA

  }; */

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

//|  >1JO2;5=85 ?5@5G8A;5=89                     |

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

enum ENUM_APPLIED_PRICE_ //"8? :>=AB0=BK

  {

   PRICE_CLOSE_ = 1,     //PRICE_CLOSE

   PRICE_OPEN_,          //PRICE_OPEN

   PRICE_HIGH_,          //PRICE_HIGH

   PRICE_LOW_,           //PRICE_LOW

   PRICE_MEDIAN_,        //PRICE_MEDIAN

   PRICE_TYPICAL_,       //PRICE_TYPICAL

   PRICE_WEIGHTED_,      //PRICE_WEIGHTED

   PRICE_SIMPL_,         //PRICE_SIMPL_

   PRICE_QUARTER_,       //PRICE_QUARTER_

   PRICE_TRENDFOLLOW0_,  //PRICE_TRENDFOLLOW0_

   PRICE_TRENDFOLLOW1_,  //PRICE_TRENDFOLLOW0_2

   PRICE_DEMARK_         //Demark Price 

  };

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

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

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

input int IPeriod=30;                              //5@8>4 ?>8A:0 M:AB@5<C<>2

input ENUM_APPLIED_PRICE_ IPC=PRICE_MEDIAN_;       //F5=>20O :>=AB0=B0

input Smooth_Method     HMA_Method=MODE_SMA_;      //5B>4 A3;06820=8O

input uint              HLength=12;                //;C18=0  A3;06820=8O                    

input int               HPhase=100;                //0@0<5B@ A3;06820=8O,

//---- 4;O JJMA 87<5=ONI89AO 2 ?@545;0E -100 ... +100, 2;8O5B =0 :0G5AB2> ?5@5E>4=>3> ?@>F5AA0;

//---- ;O VIDIA MB> ?5@8>4 CMO, 4;O AMA MB> ?5@8>4 <54;5==>9 A:>;L7OI59

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

//--- >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 min_rates_total;

//---- >1JO2;5=85 3;>10;L=KE ?5@5<5==KE

int Count[];

double XHigh[],XLow[];

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

//|  5@5AG5B ?>78F88 A0<>3> =>2>3> M;5<5=B0 2 <0AA825               |

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

void Recount_ArrayZeroPos(int &CoArr[],// >72@0B ?> AAK;:5 =><5@0 B5:CI53> 7=0G5=8O F5=>2>3> @O40

                          int Size)

  {

//----

   int numb,Max1,Max2;

   static int count=1;



   Max2=Size;

   Max1=Max2-1;



   count--;

   if(count<0) count=Max1;



   for(int iii=0; iii<Max2; iii++)

     {

      numb=iii+count;

      if(numb>Max1) numb-=Max2;

      CoArr[iii]=numb;

     }

//----

  }

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

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

   min_rates_total=GetStartBars(HMA_Method,HLength,HPhase)+1;

   min_rates_total+=int(MathMax(3,IPeriod));

   min_rates_total+=30;

//---- @0A?@545;5=85 ?0<OB8 ?>4 <0AA82K ?5@5<5==KE  

   ArrayResize(Count,IPeriod);

   ArrayResize(XHigh,IPeriod);

   ArrayResize(XLow,IPeriod);

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

   ArraySetAsSeries(Count,true);

   ArraySetAsSeries(XHigh,true);

   ArraySetAsSeries(XLow,true);



//--- ?@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);

//--- ?@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);



//--- ?@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);

//--- ?@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);



//--- ?@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);

//--- ?@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);



//--- ?@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);

//--- ?@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);





//--- #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_Float_Pivot_Smoothed";

   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(rates_total<min_rates_total) return(RESET);



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

   int first,bar;

   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 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

     {

      first=0; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2

      ArrayInitialize(Count,NULL);

      ArrayInitialize(XHigh,NULL);

      ArrayInitialize(XLow,NULL);

      int start=min_rates_total-2;

      UpIndBuffer1[start]=UpIndBuffer2[start]=DnIndBuffer1[start]=DnIndBuffer2[start]=PriceSeries(IPC,start,open,low,high,close);

      double res=UpIndBuffer1[start];

      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 first=prev_calculated-1;// AB0@B>2K9 =><5@ 4;O @0AGQB0 =>2KE 10@>2



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

   for(bar=first; bar<rates_total && !IsStopped(); bar++)

     {

      //---- "@8 2K7>20 DC=:F88 XMASeries.  

      double pivot=XMAP.XMASeries(0,prev_calculated,rates_total,HMA_Method,HPhase,HLength,PriceSeries(IPC,bar,open,low,high,close),bar,false);

      XHigh[Count[0]]=XMAH.XMASeries(0,prev_calculated,rates_total,HMA_Method,HPhase,HLength,high[bar],bar,false);

      XLow[Count[0]]=XMAL.XMASeries(0,prev_calculated,rates_total,HMA_Method,HPhase,HLength,low[bar],bar,false);      

      //----

      double max=XHigh[ArrayMaximum(XHigh,0,IPeriod)];

      double min=XLow[ArrayMinimum(XLow,0,IPeriod)];

      //---- Pivot

      double res=(max+min+pivot)/3;

      //---- (R1 - Pivot) / 2

      VTS1=((2*res-min)+res)/2;

      VTS=(res+(2*res-max))/2;

      //---- 

      if(bar<rates_total-1) Recount_ArrayZeroPos(Count,IPeriod);

      if(bar<min_rates_total-1) continue;

      //---  

      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];

      double price=PriceSeries(IPC,bar,open,low,high,close);

      if(price>DnIndBuffer3[bar])

        {

         UpIndBuffer4[bar]=UpIndBuffer3[bar];

         DnIndBuffer4[bar]=NULL;

        }

      if(price<UpIndBuffer3[bar])

        {

         DnIndBuffer4[bar]=DnIndBuffer3[bar];

         UpIndBuffer4[bar]=NULL;

        }



      if(bar<rates_total-1)

        {

         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 ---