Pivot_Fibs_Custom_Arr

Author: Archer Trading, LLC
2 Views
0 Downloads
0 Favorites
Pivot_Fibs_Custom_Arr
ÿþ//+------------------------------------------------------------------+ 

//|                                        Pivot_Fibs_Custom_Arr.mq5 | 

//|                            Copyright © 2006, Archer Trading, LLC |

//|                                    http://www.archertrading.net/ |

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

#property copyright "Archer Trading, LLC"

#property link      "http://www.archertrading.net/"

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

#property version   "1.00"

#property description "8=88 A>?@>B82;5=89 8 ?>445@6:8 ?> $81> C@>2=O< A 2K1>@>< B09<D@59<0 4;O ?82>B0"

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

#property indicator_chart_window

//---- :>;8G5AB2> 8=48:0B>@=KE 1CD5@>2 7

#property indicator_buffers 7 

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

#property indicator_plots   7

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

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

#define INDICATOR_NAME "Pivot_Fibs_Custom"     // >=AB0=B0 4;O 8<5=8 8=48:0B>@0

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

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

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

//---- >B@8A>2:0 8=48:0B>@0 1 2 2845 7=0G:0

#property indicator_type1   DRAW_ARROW

//---- 2 :0G5AB25 F25B0 8=48:0B>@0 8A?>;L7>20=

#property indicator_color1  clrDeepSkyBlue

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

#property indicator_width1  2

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

#property indicator_label1  "Res 3"



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

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

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

//---- >B@8A>2:0 8=48:0B>@0 2 2 2845 7=0G:0

#property indicator_type2   DRAW_ARROW

//---- 2 :0G5AB25 F25B0 8=48:0B>@0 8A?>;L7>20=

#property indicator_color2  clrDodgerBlue

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

#property indicator_width2  1

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

#property indicator_label2  "Res 2"



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

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

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

//---- >B@8A>2:0 8=48:0B>@0 3 2 2845 7=0G:0

#property indicator_type3   DRAW_ARROW

//---- 2 :0G5AB25 F25B0 8=48:0B>@0 8A?>;L7>20=

#property indicator_color3  clrBlue

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

#property indicator_width3  2

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

#property indicator_label3  "Res 1"

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

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

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

//---- >B@8A>2:0 8=48:0B>@0 4 2 2845 7=0G:0

#property indicator_type4   DRAW_ARROW

//---- 2 :0G5AB25 F25B0 8=48:0B>@0 8A?>;L7>20=

#property indicator_color4  clrPurple

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

#property indicator_width4  3

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

#property indicator_label4  "Pivot"

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

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

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

//---- >B@8A>2:0 8=48:0B>@0 5 2 2845 7=0G:0

#property indicator_type5   DRAW_ARROW

//---- 2 :0G5AB25 F25B0 8=48:0B>@0 8A?>;L7>20=

#property indicator_color5  clrRed

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

#property indicator_width5  2

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

#property indicator_label5  "Sup 1"

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

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

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

//---- >B@8A>2:0 8=48:0B>@0 6 2 2845 7=0G:0

#property indicator_type6   DRAW_ARROW

//---- 2 :0G5AB25 F25B0 8=48:0B>@0 8A?>;L7>20=

#property indicator_color6  clrHotPink

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

#property indicator_width6  1

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

#property indicator_label6  "Sup 2"

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

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

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

//---- >B@8A>2:0 8=48:0B>@0 7 2 2845 7=0G:0

#property indicator_type7   DRAW_ARROW

//---- 2 :0G5AB25 F25B0 8=48:0B>@0 8A?>;L7>20=

#property indicator_color7  clrViolet

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

#property indicator_width7  2

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

#property indicator_label7  "Sup 3"

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

//|  %+  " + "                 |

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

input ENUM_TIMEFRAMES TimeFrame=PERIOD_H12;           // 5@8>4 3@0D8:0

input double FiboRatio1=0.99;

input double FiboRatio2=0.382;

input double FiboRatio3=0.618;

input int Shift=0;                                    // A4283 8=48:0B>@0 ?> 3>@87>=B0;8 2 10@0E

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

//---- >1JO2;5=85 48=0<8G5A:8E <0AA82>2, :>B>@K5 1C4CB 2 

// 40;L=59H5< 8A?>;L7>20=K 2 :0G5AB25 8=48:0B>@=KE 1CD5@>2

double Ind1Buffer[];

double Ind2Buffer[];

double Ind3Buffer[];

double Ind4Buffer[];

double Ind5Buffer[];

double Ind6Buffer[];

double Ind7Buffer[];

//---- 1JO2;5=85 F5;KE ?5@5<5==KE =0G0;0 >BAGQB0 40==KE

int min_rates_total;

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

//| Custom indicator initialization function                         | 

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

int OnInit()

  {

//---- =8F80;870F8O ?5@5<5==KE 

   min_rates_total=2*PeriodSeconds(TimeFrame)/PeriodSeconds(Period());



//---- =8F80;870F8O 8=48:0B>@=KE 1CD5@>2

   IndInit(0,Ind1Buffer,0.0,min_rates_total,Shift);

   IndInit(1,Ind2Buffer,0.0,min_rates_total,Shift);

   IndInit(2,Ind3Buffer,0.0,min_rates_total,Shift);

   IndInit(3,Ind4Buffer,0.0,min_rates_total,Shift);

   IndInit(4,Ind5Buffer,0.0,min_rates_total,Shift);

   IndInit(5,Ind6Buffer,0.0,min_rates_total,Shift);

   IndInit(6,Ind7Buffer,0.0,min_rates_total,Shift);

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

   PlotIndexSetInteger(3,PLOT_ARROW,167);



//---- A>740=85 8<5=8 4;O >B>1@065=8O 2 >B45;L=>< ?>4>:=5 8 2> 2A?;K20NI59 ?>4A:07:5

   string shortname;

   StringConcatenate(shortname,INDICATOR_NAME,"(",Shift,")");

   IndicatorSetString(INDICATOR_SHORTNAME,shortname);



//---- >?@545;5=85 B>G=>AB8 >B>1@065=8O 7=0G5=89 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);



//---- 7025@H5=85 8=8F80;870F88

   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//----

   Comment("");

//----

   ChartRedraw(0);

  }

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

//| Custom iteration function                                        | 

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

int OnCalculate(

                const int rates_total,    // :>;8G5AB2> 8AB>@88 2 10@0E =0 B5:CI5< B8:5

                const int prev_calculated,// :>;8G5AB2> 8AB>@88 2 10@0E =0 ?@54K4CI5< B8:5

                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 ?5@8>4>2 3@0D8:>2 =0 :>@@5:B=>ABL

   if(!TimeFramesCheck(INDICATOR_NAME,TimeFrame)) return(RESET);

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

   if(rates_total<min_rates_total) return(RESET);



//---- 1JO2;5=85 F5;KE ?5@5<5==KE

   int limit,bar;



//---- 1JO2;5=85 ?5@5<5==KE A ?;020NI59 B>G:>9  

   double P,R,S1,R1,S2,R2,S3,R3;

   static double LastHigh,LastLow;

//----    

   datetime Time[1];

   static uint LastCountBar;



//---- @0AGQBK =5>1E>48<>3> :>;8G5AB20 :>?8@C5<KE 40==KE 8

//AB0@B>2>3> =><5@0 limit 4;O F8:;0 ?5@5AGQB0 10@>2

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

     {

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

      LastCountBar=rates_total;

      LastHigh=0;

      LastLow=999999999;

     }

   else limit=int(LastCountBar)+rates_total-prev_calculated; // AB0@B>2K9 =><5@ 4;O @0AGQB0 =>2KE 10@>2 



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

   ArraySetAsSeries(time,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(close,true);

   ArraySetAsSeries(open,true);



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

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

     {

      Ind1Buffer[bar]=Ind2Buffer[bar]=Ind3Buffer[bar]=Ind4Buffer[bar]=Ind5Buffer[bar]=Ind6Buffer[bar]=Ind7Buffer[bar]=NULL;



      if(high[bar+1]>LastHigh) LastHigh=high[bar+1];

      if(low[bar+1]<LastLow) LastLow=low[bar+1];



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

      if(CopyTime(Symbol(),TimeFrame,time[bar],1,Time)<=0) return(RESET);



      if(time[bar]>=Time[0] && time[bar+1]<Time[0])

        {

         LastCountBar=bar;

         Ind1Buffer[bar+1]=Ind2Buffer[bar+1]=Ind3Buffer[bar+1]=Ind4Buffer[bar+1]=Ind5Buffer[bar+1]=Ind6Buffer[bar+1]=Ind7Buffer[bar+1]=NULL;

         

         P=(LastHigh+LastLow+close[bar+1])/3;

         R=LastHigh-LastLow;

         R1=P+(R*FiboRatio2);

         S1=P-(R*FiboRatio2);

         R2=P+(R*FiboRatio3);

         S2=P-(R*FiboRatio3);

         R3=P+(R*FiboRatio1);

         S3=P-(R*FiboRatio1);

         LastLow=open[bar];

         LastHigh=open[bar];



         //---- 03@C7:0 ?>;CG5==KE 7=0G5=89 2 8=48:0B>@=K5 1CD5@K

         Ind1Buffer[bar]=R3;

         Ind2Buffer[bar]=R2;

         Ind3Buffer[bar]=R1;

         Ind4Buffer[bar]=P;

         Ind5Buffer[bar]=S1;

         Ind6Buffer[bar]=S2;

         Ind7Buffer[bar]=S3;

        }



      if(Ind1Buffer[bar+1] && !Ind1Buffer[bar])

        {

         Ind1Buffer[bar]=Ind1Buffer[bar+1];

         Ind2Buffer[bar]=Ind2Buffer[bar+1];

         Ind3Buffer[bar]=Ind3Buffer[bar+1];

         Ind4Buffer[bar]=Ind4Buffer[bar+1];

         Ind5Buffer[bar]=Ind5Buffer[bar+1];

         Ind6Buffer[bar]=Ind6Buffer[bar+1];

         Ind7Buffer[bar]=Ind7Buffer[bar+1];

        }

     }

//----     

   return(rates_total);

  }

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

//| =8F80;870F8O 8=48:0B>@=>3> 1CD5@0                               |

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

void IndInit(int Number,double &Buffer[],double Empty_Value,int Draw_Begin,int nShift)

  {

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

   SetIndexBuffer(Number,Buffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(Number,PLOT_DRAW_BEGIN,Draw_Begin);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(Number,PLOT_EMPTY_VALUE,Empty_Value);

//---- >ACI5AB2;5=85 A42830 8=48:0B>@0 2 ?> 3>@87>=B0;8 =0 Shift

   PlotIndexSetInteger(Number,PLOT_SHIFT,nShift);

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

   ArraySetAsSeries(Buffer,true);

//----

  }

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

//| TimeFramesCheck()                                                |

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

bool TimeFramesCheck(string IndName,

                     ENUM_TIMEFRAMES TFrame) // 5@8>4 3@0D8:0 8=48:0B>@0

  {

//--- ?@>25@:0 ?5@8>4>2 3@0D8:>2 =0 :>@@5:B=>ABL

   if(TFrame<Period() && TFrame!=PERIOD_CURRENT)

     {

      Comment("5@8>4 3@0D8:0 4;O 8=48:0B>@0 "+IndName+" =5 <>65B 1KBL <5=LH5 ?5@8>40 B5:CI53> 3@0D8:0! \n !;54C5B 87<5=8BL 2E>4=K5 ?0@0<5B@K 8=48:0B>@0!");

      return(RESET);

     }

//---

   return(true);

  }

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

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