SupremAutoFibo_Grand

Download script
Author: Copyright © 2018, Nikolay Kositsin

Overview of SupremeAutoFibo_Grand Logic

This script is designed for the MetaTrader platform to automatically manage and display Fibonacci retracement levels on a trading chart. Instead of requiring a user to manually click points to draw lines, this tool automates the identification of significant price boundaries based on historical data within a specific timeframe.

Core Functionality

1. Automated Range Identification The script looks back at a user-defined number of bars (determined by the nPeriod setting). It scans this history to find the highest price point (High) and the lowest price point (Low) reached during that period. By identifying these two extremes, the script establishes the "trading range" automatically.

2. Smart Point Assignment Once the high and low points are found, the script intelligently assigns them as the starting and ending anchors for the Fibonacci tool. It detects the direction of the move (upward or downward) to ensure the levels are drawn correctly regardless of whether the market is currently in a bullish or bearish trend.

3. Dynamic Level Customization The script allows for a highly personalized visual experience. Users can define:

  • Specific Fibonacci Levels: You can set exactly which levels (e.g., 0.618, 0.786, 1.618) appear on the chart.
  • Visual Styling: Each individual level can be customized with its own unique color, line style (solid, dashed, etc.), and line thickness (width).
  • Offset Adjustments: There is a "Shift" feature that allows users to slightly nudge the vertical position of the levels if they prefer them to appear slightly above or below the actual price points.

4. Multi-Timeframe Awareness While you may be viewing a specific chart, the script can be configured to calculate its Fibonacci levels based on a different timeframe (e.g., looking at Daily data while viewing a 1-hour chart). This helps traders identify major structural levels that might be missed on shorter intervals.

5. Real-Time Updates and Cleanup

  • Auto-Updating: The tool constantly monitors price action. If the "High" or "Low" of the period changes as new candles form, the Fibonacci object automatically moves to stay anchored to the most relevant data.
  • Automatic Removal: To keep the trading workspace clean, the script is programmed to delete its previous drawing once it is removed from the chart, ensuring no "ghost" lines remain behind.

Summary of User Experience

When you apply this script, it replaces the manual effort of "hunting" for swing highs and lows. It instantly draws a professional-grade Fibonacci suite on your screen that adjusts dynamically as the market moves, providing a clear visual map of potential support and resistance zones based on the most recent price history.

5 Views
0 Downloads
0 Favorites
SupremAutoFibo_Grand
ÿþ//+------------------------------------------------------------------+

//|                                         SupremAutoFibo_Grand.mq5 |

//|                               Copyright © 2018, Nikolay Kositsin | 

//|                              Khabarovsk,   farria@mail.redcom.ru | 

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

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

#property copyright "Copyright © 2018, Nikolay Kositsin"

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

#property link      "farria@mail.redcom.ru"

//---- =><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 @0AGQB0 8 >B@8A>2:8 8=48:0B>@0 =5 8A?>;L7>20=> =8 >4=>3> 1CD5@0

#property indicator_buffers 0

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

#property indicator_plots   0

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

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

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

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

#define FIBO_LINES_TONAL 19        // >=AB0=B0 4;O :>;8G5AB20 C@>2=59 D81>

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

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

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

input string          FiboName="SupremAutoFibo_Grand";    //<O >1J5:B0 

input ENUM_TIMEFRAMES Timeframe=PERIOD_D1;          //"09<D@59< 8=48:0B>@0 4;O @0AG5B0 C@>2=59 $81>=0G8

input double  FiboRatio =1.000;                     //>MDD8F85=B 4><=>65=8O 2A5E D81>C@>2=59

input double  FiboLevelsShift=0.000;                //!4283 ?> 25@B8:0;8 2A5E D81>C@>2=59 2 $810E >B =C;52>3> C@>2=O

input uint   NumberofBar=1;                         //><5@ AB0@B>2>3> 10@0 4;O ?>8A:0 M:AB@5<C<>2

input uint   nPeriod=30;                            //>;8G5AB2> 10@>2 4;O ?>8A:0 M:AB@5<C<>2

input color   FiboColor=clrGray;                    //&25B $81>

//----

input double  FiboLevel1 =-1.000;                   //7=0G5=85 D81>C@>2=O 1

input ENUM_LINE_STYLE StyleLevel1=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 1

input uint   WidthLevel1=4;                         //B>;I8=0 ;8=88 D81>C@>2=O 1

input color  Color_Level1 = clrOrange;              //F25B D81>C@>2=O 1

//----

input double  FiboLevel2=-0.764;                    //7=0G5=85 D81>C@>2=O 2

input ENUM_LINE_STYLE StyleLevel2=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 2

input uint    WidthLevel2=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 2

input color   Color_Level2= clrDarkViolet;          //F25B D81>C@>2=O 2

//----

input double  FiboLevel3 =-0.618;                   //7=0G5=85 D81>C@>2=O 3

input ENUM_LINE_STYLE StyleLevel3=STYLE_DASH;       //AB8;L ;8=88 D81>C@>2=O 3

input uint    WidthLevel3=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 3

input color   Color_Level3 = clrMagenta;            //F25B D81>C@>2=O 3

//----

input double  FiboLevel4 =-0.500;                   //7=0G5=85 D81>C@>2=O 4

input ENUM_LINE_STYLE StyleLevel4=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 4

input uint    WidthLevel4=2;                        //B>;I8=0 ;8=88 D81>C@>2=O 4

input color   Color_Level4 = clrMediumSeaGreen;     //F25B D81>C@>2=O 4

//----  

input double  FiboLevel5 =-0.382;                   //7=0G5=85 D81>C@>2=O 5

input ENUM_LINE_STYLE StyleLevel5=STYLE_DASH;       //AB8;L ;8=88 D81>C@>2=O 5

input uint    WidthLevel5=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 5

input color   Color_Level5 = clrBlue;               //F25B D81>C@>2=O 5

//----

input double  FiboLevel6=-0.236;                    //7=0G5=85 D81>C@>2=O 6

input ENUM_LINE_STYLE StyleLevel6=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 6

input uint    WidthLevel6=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 6

input color   Color_Level6 = clrGray;               //F25B D81>C@>2=O 6

//----

input double  FiboLevel7 = 0.000;                   //7=0G5=85 D81>C@>2=O 7

input ENUM_LINE_STYLE StyleLevel7=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 7

input uint    WidthLevel7=4;                        //B>;I8=0 ;8=88 D81>C@>2=O 7

input color   Color_Level7 = clrOrange;               //F25B D81>C@>2=O 7

//----

input double  FiboLevel8=0.236;                     //7=0G5=85 D81>C@>2=O 8

input ENUM_LINE_STYLE StyleLevel8=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 8

input uint    WidthLevel8=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 8

input color   Color_Level8 = clrDarkViolet;         //F25B D81>C@>2=O 8

//----

input double  FiboLevel9 = 0.382;                   //7=0G5=85 D81>C@>2=O 9

input ENUM_LINE_STYLE StyleLevel9=STYLE_DASH;       //AB8;L ;8=88 D81>C@>2=O 9

input uint    WidthLevel9=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 9

input color   Color_Level9 = clrMagenta;            //F25B D81>C@>2=O 9

//---- 

input double  FiboLevel10 = 0.500;                  //7=0G5=85 D81>C@>2=O 10

input ENUM_LINE_STYLE StyleLevel10=STYLE_SOLID;     //AB8;L ;8=88 D81>C@>2=O 10

input uint    WidthLevel10=2;                       //B>;I8=0 ;8=88 D81>C@>2=O 10

input color  Color_Level10 = clrMediumSeaGreen;     //F25B D81>C@>2=O 10

//----

input double  FiboLevel11 = 0.618;                  //7=0G5=85 D81>C@>2=O 11

input ENUM_LINE_STYLE StyleLevel11=STYLE_DASH;      //AB8;L ;8=88 D81>C@>2=O 11

input uint    WidthLevel11=1;                       //B>;I8=0 ;8=88 D81>C@>2=O 11

input color   Color_Level11 = clrBlue;              //F25B D81>C@>2=O 11

//----

input double  FiboLevel12=0.764;                    //7=0G5=85 D81>C@>2=O 12

input ENUM_LINE_STYLE StyleLevel12=STYLE_SOLID;     //AB8;L ;8=88 D81>C@>2=O 12

input uint    WidthLevel12=1;                       //B>;I8=0 ;8=88 D81>C@>2=O 12

input color   Color_Level12 = clrGray;              //F25B D81>C@>2=O 12

//----

input double  FiboLevel13 = 1.000;                   //7=0G5=85 D81>C@>2=O 13

input ENUM_LINE_STYLE StyleLevel13=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 13

input uint   WidthLevel13=4;                         //B>;I8=0 ;8=88 D81>C@>2=O 13

input color  Color_Level13 = clrOrange;              //F25B D81>C@>2=O 13

//----

input double  FiboLevel14=1.236;                     //7=0G5=85 D81>C@>2=O 14

input ENUM_LINE_STYLE StyleLevel14=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 14

input uint    WidthLevel14=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 14

input color   Color_Level14 = clrDarkViolet;         //F25B D81>C@>2=O 14

//----

input double  FiboLevel15 = 1.382;                   //7=0G5=85 D81>C@>2=O 15

input ENUM_LINE_STYLE StyleLevel15=STYLE_DASH;       //AB8;L ;8=88 D81>C@>2=O 15

input uint    WidthLevel15=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 15

input color   Color_Level15 = clrMagenta;            //F25B D81>C@>2=O 15

//----

input double  FiboLevel16 = 1.500;                   //7=0G5=85 D81>C@>2=O 16

input ENUM_LINE_STYLE StyleLevel16=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 16

input uint    WidthLevel16=2;                        //B>;I8=0 ;8=88 D81>C@>2=O 16

input color   Color_Level16 = clrMediumSeaGreen;     //F25B D81>C@>2=O 16

//----  

input double  FiboLevel17 = 1.618;                   //7=0G5=85 D81>C@>2=O 17

input ENUM_LINE_STYLE StyleLevel17=STYLE_DASH;       //AB8;L ;8=88 D81>C@>2=O 17

input uint    WidthLevel17=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 17

input color   Color_Level17 = clrBlue;               //F25B D81>C@>2=O 17

//----

input double  FiboLevel18=1.764;                     //7=0G5=85 D81>C@>2=O 18

input ENUM_LINE_STYLE StyleLevel18=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 18

input uint    WidthLevel18=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 18

input color   Color_Level18 = clrGray;               //F25B D81>C@>2=O 18

//----

input double  FiboLevel19 = 2.000;                   //7=0G5=85 D81>C@>2=O 19

input ENUM_LINE_STYLE StyleLevel19=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 19

input uint    WidthLevel19=4;                        //B>;I8=0 ;8=88 D81>C@>2=O 19

input color   Color_Level19 = clrOrange;             //F25B D81>C@>2=O 19

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

//---- <0AA82K ?5@5<5==KE 4;O ;8=89 $81>

double Values[FIBO_LINES_TONAL];

color Colors[FIBO_LINES_TONAL];

ENUM_LINE_STYLE Styles[FIBO_LINES_TONAL];

uint Widths[FIBO_LINES_TONAL];

double nOpen[],nClose[],nHigh[],nLow[];

datetime nTime[];

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

//| C>7405B "#@>2=8 $81>=0GG8" ?> 7040==K< :>>@48=0B0<               | 

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

bool FiboLevelsCreate(const long            chart_ID=0,        // ID 3@0D8:0 

                      const string          name="FiboLevels", // 8<O >1J5:B0 

                      const int             sub_window=0,      // =><5@ ?>4>:=0  

                      datetime              time1=0,           // 2@5<O ?5@2>9 B>G:8 

                      double                price1=0,          // F5=0 ?5@2>9 B>G:8 

                      datetime              time2=0,           // 2@5<O 2B>@>9 B>G:8 

                      double                price2=0,          // F5=0 2B>@>9 B>G:8 

                      const color           clr=clrRed,        // F25B >1J5:B0 

                      const ENUM_LINE_STYLE style=STYLE_SOLID, // AB8;L ;8=88 >1J5:B0 

                      const int             width=1,           // B>;I8=0 ;8=88 >1J5:B0 

                      const bool            back=false,        // =0 704=5< ?;0=5 

                      const bool            selection=true,    // 2K45;8BL 4;O ?5@5<5I5=89 

                      const bool            ray_left=false,    // ?@>4>;65=85 >1J5:B0 2;52> 

                      const bool            ray_right=false,   // ?@>4>;65=85 >1J5:B0 2?@02> 

                      const bool            hidden=true,       // A:@KB 2 A?8A:5 >1J5:B>2 

                      const long            z_order=0)         // ?@8>@8B5B =0 =060B85 <KHLN 

  {

//--- CAB0=>28< :>>@48=0BK B>G5: ?@82O7:8, 5A;8 >=8 =5 7040=K 

   ChangeFiboLevelsEmptyPoints(time1,price1,time2,price2);



//--- A1@>A8< 7=0G5=85 >H81:8 

   ResetLastError();

//--- A>74048< "#@>2=8 $81>=0GG8" ?> 7040==K< :>>@48=0B0< 

   if(!ObjectCreate(chart_ID,name,OBJ_FIBO,sub_window,time1,price1,time2,price2))

     {

      Print(__FUNCTION__,

            ": =5 C40;>AL A>740BL \"#@>2=8 $81>=0GG8\"! >4 >H81:8 = ",GetLastError());

      return(false);

     }

//--- CAB0=>28< F25B 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

//--- CAB0=>28< AB8;L ;8=88 

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);

//--- CAB0=>28< B>;I8=C ;8=88 

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);

//--- >B>1@078< =0 ?5@54=5< (false) 8;8 704=5< (true) ?;0=5 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< 2K45;5=8O >1J5:B0 4;O ?5@5<5I5=89 

//--- ?@8 A>740=88 3@0D8G5A:>3> >1J5:B0 DC=:F859 ObjectCreate, ?> C<>;G0=8N >1J5:B 

//--- =5;L7O 2K45;8BL 8 ?5@5<5I0BL. =CB@8 65 MB>3> <5B>40 ?0@0<5B@ selection 

//--- ?> C<>;G0=8N @025= true, GB> ?>72>;O5B 2K45;OBL 8 ?5@5<5I0BL MB>B >1J5:B 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< ?@>4>;65=8O >B>1@065=8O >1J5:B0 2;52> 

   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_LEFT,ray_left);

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< ?@>4>;65=8O >B>1@065=8O >1J5:B0 2?@02> 

   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);

//--- A:@>5< (true) 8;8 >B>1@078< (false) 8<O 3@0D8G5A:>3> >1J5:B0 2 A?8A:5 >1J5:B>2 

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

//--- CAB0=>28 ?@8>@8B5B =0 ?>;CG5=85 A>1KB8O =060B8O <KH8 =0 3@0D8:5 

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

//--- CA?5H=>5 2K?>;=5=85 

   return(true);

  }

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

//| 0405B :>;8G5AB2> C@>2=59 8 8E ?0@0<5B@K                         | 

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

bool FiboLevelsSet(int             levels,            // :>;8G5AB2> ;8=89 C@>2=O 

                   double          &values[],         // 7=0G5=8O ;8=89 C@>2=O 

                   color           &colors[],         // F25B ;8=89 C@>2=O 

                   ENUM_LINE_STYLE &styles[],         // AB8;L ;8=89 C@>2=O 

                   uint             &widths[],// B>;I8=0 ;8=89 C@>2=O 

                   const long      chart_ID=0,        // ID 3@0D8:0 

                   const string    name="FiboLevels") // 8<O >1J5:B0 

  {

//--- ?@>25@8< @07<5@K <0AA82>2 

   if(levels!=ArraySize(colors) || levels!=ArraySize(styles) ||

      levels!=ArraySize(widths) || levels!=ArraySize(widths))

     {

      Print(__FUNCTION__,": 4;8=0 <0AA820 =5 A>>B25BAB2C5B :>;8G5AB2C C@>2=59, >H81:0!");

      return(false);

     }

//--- CAB0=>28< :>;8G5AB2> C@>2=59 

   ObjectSetInteger(chart_ID,name,OBJPROP_LEVELS,levels);

//--- CAB0=>28< A2>9AB20 C@>2=59 2 F8:;5 

   for(int i=0;i<levels;i++)

     {

      //--- 7=0G5=85 C@>2=O 

      ObjectSetDouble(chart_ID,name,OBJPROP_LEVELVALUE,i,values[i]);

      //--- F25B C@>2=O 

      ObjectSetInteger(chart_ID,name,OBJPROP_LEVELCOLOR,i,colors[i]);

      //--- AB8;L C@>2=O 

      ObjectSetInteger(chart_ID,name,OBJPROP_LEVELSTYLE,i,styles[i]);

      //--- B>;I8=0 C@>2=O 

      ObjectSetInteger(chart_ID,name,OBJPROP_LEVELWIDTH,i,int(widths[i]));

      //--- >?8A0=85 C@>2=O 

      ObjectSetString(chart_ID,name,OBJPROP_LEVELTEXT,i,DoubleToString(100*values[i],1));

     }

//--- CA?5H=>5 2K?>;=5=85 

   return(true);

  }

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

//| 5@5<5I05B B>G:C ?@82O7:8 "#@>2=59 $81>=0GG8"                    | 

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

bool FiboLevelsPointChange(const long   chart_ID=0,        // ID 3@0D8:0 

                           const string name="FiboLevels", // 8<O >1J5:B0 

                           const int    point_index=0,     // =><5@ B>G:8 ?@82O7:8 

                           datetime     time=0,            // :>>@48=0B0 2@5<5=8 B>G:8 ?@82O7:8 

                           double       price=0)           // :>>@48=0B0 F5=K B>G:8 ?@82O7:8 

  {

//--- 5A;8 :>>@48=0BK B>G:8 =5 7040=K, B> ?5@5<5I05< 55 =0 B5:CI89 10@ A F5=>9 Bid 

   if(!time)

      time=TimeCurrent();

   if(!price)

      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);

//--- A1@>A8< 7=0G5=85 >H81:8 

   ResetLastError();

//--- ?5@5<5AB8< B>G:C ?@82O7:8 

   if(!ObjectMove(chart_ID,name,point_index,time,price))

     {

      Print(__FUNCTION__,

            ": =5 C40;>AL ?5@5<5AB8BL B>G:C ?@82O7:8! >4 >H81:8 = ",GetLastError());

      return(false);

     }

//--- CA?5H=>5 2K?>;=5=85 

   return(true);

  }

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

//| #40;O5B "#@>2=8 $81>=0GG8"                                       | 

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

bool FiboLevelsDelete(const long   chart_ID=0,        // ID 3@0D8:0 

                      const string name="FiboLevels") // 8<O >1J5:B0 

  {

//--- A1@>A8< 7=0G5=85 >H81:8 

   ResetLastError();

//--- C40;8< >1J5:B 

   if(!ObjectDelete(chart_ID,name))

     {

      Print(__FUNCTION__,

            ": =5 C40;>AL C40;8BL \"#@>2=8 $81>=0GG8\"! >4 >H81:8 = ",GetLastError());

      return(false);

     }

//--- CA?5H=>5 2K?>;=5=85 

   return(true);

  }

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

//| @>25@O5B 7=0G5=8O B>G5: ?@82O7:8 "#@>2=59 $81>=0GG8" 8 4;O      | 

//| ?CABKE 7=0G5=89 CAB0=02;8205B 7=0G5=8O ?> C<>;G0=8N              | 

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

void ChangeFiboLevelsEmptyPoints(datetime &time1,double &price1,

                                 datetime &time2,double &price2)

  {

//--- 5A;8 2@5<O 2B>@>9 B>G:8 =5 7040=>, B> >=0 1C45B =0 B5:CI5< 10@5 

   if(!time2)

      time2=TimeCurrent();

//--- 5A;8 F5=0 2B>@>9 B>G:8 =5 7040=0, B> >=0 1C45B 8<5BL 7=0G5=85 Bid 

   if(!price2)

      price2=SymbolInfoDouble(Symbol(),SYMBOL_BID);

//--- 5A;8 2@5<O ?5@2>9 B>G:8 =5 7040=>, B> >=0 ;568B =0 9 10@>2 ;5255 2B>@>9 

   if(!time1)

     {

      //--- <0AA82 4;O ?@85<0 2@5<5=8 >B:@KB8O 10 ?>A;54=8E 10@>2 

      datetime temp[10];

      CopyTime(Symbol(),Period(),time2,10,temp);

      //--- CAB0=>28< ?5@2CN B>G:C =0 9 10@>2 ;5255 2B>@>9 

      time1=temp[0];

     }

//--- 5A;8 F5=0 ?5@2>9 B>G:8 =5 7040=0, B> A428=5< 55 =0 200 ?C=:B>2 =865 2B>@>9 

   if(!price1)

      price1=price2-200*SymbolInfoDouble(Symbol(),SYMBOL_POINT);

  }

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//----

   Values[0]=FiboLevel1*FiboRatio;

   Values[1]=FiboLevel2*FiboRatio;

   Values[2]=FiboLevel3*FiboRatio;

   Values[3]=FiboLevel4*FiboRatio;

   Values[4]=FiboLevel5*FiboRatio;

   Values[5]=FiboLevel6*FiboRatio;

   Values[6]=FiboLevel7*FiboRatio;

   Values[7]=FiboLevel8*FiboRatio;

   Values[8]=FiboLevel9*FiboRatio;

   Values[9]=FiboLevel10*FiboRatio;

   Values[10]=FiboLevel11*FiboRatio;

   Values[11]=FiboLevel12*FiboRatio;

   Values[12]=FiboLevel13*FiboRatio;

   Values[13]=FiboLevel14*FiboRatio;

   Values[14]=FiboLevel15*FiboRatio;

   Values[15]=FiboLevel16*FiboRatio;

   Values[16]=FiboLevel17*FiboRatio;

   Values[17]=FiboLevel18*FiboRatio;

   Values[18]=FiboLevel19*FiboRatio;

//----   

   Colors[0]=Color_Level1;

   Colors[1]=Color_Level2;

   Colors[2]=Color_Level3;

   Colors[3]=Color_Level4;

   Colors[4]=Color_Level5;

   Colors[5]=Color_Level6;

   Colors[6]=Color_Level7;

   Colors[7]=Color_Level8;

   Colors[8]=Color_Level9;

   Colors[9]=Color_Level10;

   Colors[10]=Color_Level11;

   Colors[11]=Color_Level12;

   Colors[12]=Color_Level13;

   Colors[13]=Color_Level14;

   Colors[14]=Color_Level15;

   Colors[15]=Color_Level16;

   Colors[16]=Color_Level17;

   Colors[17]=Color_Level18;

   Colors[18]=Color_Level19;

//----   

   Styles[0]=StyleLevel1;

   Styles[1]=StyleLevel2;

   Styles[2]=StyleLevel3;

   Styles[3]=StyleLevel4;

   Styles[4]=StyleLevel5;

   Styles[5]=StyleLevel6;

   Styles[6]=StyleLevel7;

   Styles[7]=StyleLevel8;

   Styles[8]=StyleLevel9;

   Styles[9]=StyleLevel10;

   Styles[10]=StyleLevel11;

   Styles[11]=StyleLevel12;

   Styles[12]=StyleLevel13;

   Styles[13]=StyleLevel14;

   Styles[14]=StyleLevel15;

   Styles[15]=StyleLevel16;

   Styles[16]=StyleLevel17;

   Styles[17]=StyleLevel18;

   Styles[18]=StyleLevel19;

//----//----   

   Widths[0]=WidthLevel1;

   Widths[1]=WidthLevel2;

   Widths[2]=WidthLevel3;

   Widths[3]=WidthLevel4;

   Widths[4]=WidthLevel5;

   Widths[5]=WidthLevel6;

   Widths[6]=WidthLevel7;

   Widths[7]=WidthLevel8;

   Widths[8]=WidthLevel9;

   Widths[9]=WidthLevel10;

   Widths[10]=WidthLevel11;

   Widths[11]=WidthLevel12;

   Widths[12]=WidthLevel13;

   Widths[13]=WidthLevel14;

   Widths[14]=WidthLevel15;

   Widths[15]=WidthLevel16;

   Widths[16]=WidthLevel17;

   Widths[17]=WidthLevel18;

   Widths[18]=WidthLevel19;

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

   ArrayResize(nTime,nPeriod);

   ArrayResize(nHigh,nPeriod);

   ArrayResize(nLow,nPeriod);

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

   ArraySetAsSeries(nTime,true);

   ArraySetAsSeries(nHigh,true);

   ArraySetAsSeries(nLow,true);

//--- A>74048< >1J5:B 

   if(!FiboLevelsCreate(0,FiboName,0,0,0,0,0,FiboColor,STYLE_SOLID,0,true,false,false,true,false,0))

     {

      Print("5 C40;>AL A>740BL $81>!");

      return(INIT_FAILED);

     }

   if(!FiboLevelsSet(FIBO_LINES_TONAL,Values,Colors,Styles,Widths,0,FiboName))

     {

      Print("5 C40;>AL =0AB@>8BL $81>!");

      return(INIT_FAILED);

     }

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

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

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

   IndicatorSetString(INDICATOR_SHORTNAME,"SupremAutoFibo_Grand");

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

   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//----

   FiboLevelsDelete(0,FiboName);

//----

   ChartRedraw(0);

  }

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

//| Custom indicator 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[],     // F5=>2>9 <0AA82 <0:A8<C<>2 F5=K 4;O @0AGQB0 8=48:0B>@0

                const double& low[],      // F5=>2>9 <0AA82 <8=8<C<>2 F5=K  4;O @0AGQB0 8=48:0B>@0

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[]

                )

  {

//---- 

//if(prev_calculated==rates_total && NumberofBar) return(rates_total);

   if(!ObjectFind(0,FiboName))

     {

      //--- A>74048< >1J5:B 

      if(!FiboLevelsCreate(0,FiboName,0,0,0,0,0,FiboColor,STYLE_SOLID,0,true,false,false,true,false,0))

        {

         Print("5 C40;>AL A>740BL $81>!");

         return(0);

        }

      if(!FiboLevelsSet(FIBO_LINES_TONAL,Values,Colors,Styles,Widths,0,FiboName))

        {

         Print("5 C40;>AL =0AB@>8BL $81>!");

         return(0);

        }

     }

//----

   double P1,P2;

   int to_copy;

   datetime D1,D2;



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

   ArraySetAsSeries(time,true);

//----

   to_copy=int(nPeriod);

//----

   if(CopyTime(NULL,Timeframe,NumberofBar,to_copy,nTime)<to_copy)return(RESET);

   if(CopyHigh(NULL,Timeframe,NumberofBar,to_copy,nHigh)<to_copy)return(RESET);

   if(CopyLow(NULL,Timeframe,NumberofBar,to_copy,nLow)<to_copy)return(RESET);

//----

   int hbar=ArrayMaximum(nHigh,0,nPeriod);

   int lbar=ArrayMinimum(nLow,0,nPeriod);

//----   

   if(lbar<=hbar)

     {

      P1=nHigh[hbar];

      P2=nLow[lbar];

     }

   else

     {

      P1=nLow[lbar];

      P2=nHigh[hbar];

     }

   double vertSfift=(P2-P1)*FiboLevelsShift;

   P1+=vertSfift;

   P2+=vertSfift;

   D1=nTime[nPeriod-1];

   D2=TimeCurrent();

//----

   if(!FiboLevelsPointChange(0,FiboName,0,D1,P1)) return(rates_total);

   if(!FiboLevelsPointChange(0,FiboName,1,D2,P2)) return(rates_total);

//----

   ChartRedraw(0);

   return(rates_total);

  }

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

Comments