Author: Copyright © 2006, Eli hayun
0 Views
0 Downloads
0 Favorites
Fib_SR_v1
ÿþ//+------------------------------------------------------------------+

//|                                                       Fib_SR.mq5 |

//|                                      Copyright © 2006, Eli hayun |

//|                                          http://www.elihayun.com |

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

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

#property copyright "Copyright © 2006, Eli hayun"

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

#property link      "http://www.elihayun.com"

//---- =><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 FIB_RES2 "FIB_RES_2"

#define FIB_RES1 "FIB_RES_1"

#define FIB_SUP1 "FIB_SUP_1"

#define FIB_SUP2 "FIB_SUP_2"

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

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

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

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

input uint   NumberofBar=1;                 //><5@ 10@0 4;O @0AG5B0 8=48:0B>@0

input double Ratio1 = 0.618;                //?5@2>5 A>>B=>H5=85

input double Ratio2 = 1.382;                //2B>@>5 A>>B=>H5=85

input color  Color_Res2 = clrLime;          //F25B 2B>@>9 7>=K A>?@>B82;5=8O

input color  Color_Res1 = clrGreen;         //F25B ?5@2>9 7>=K A>?@>B82;5=8O

input color  Color_Sup1 = clrRed;           //F25B ?5@2>9 7>=K ?>445@6:8

input color  Color_Sup2 = clrMagenta;       //F25B 2B>@>9 7>=K ?>445@6:8

input uint   RightTail=60;                  //2KABC? ?@O<>C3>;L=8:>2 70 =C;52>9 10@ 2?@02> 2 <8=CB0E

input uint   LeftTail=60;                   //2KABC? ?@O<>C3>;L=8:>2 70 AB0@B>2K9 10@ 2;52> 2 <8=CB0E

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

uint SecondRightTail,SecondLeftTail;

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

//|  !>740=85 ?@O<>C3>;L=>3> >1J5:B0                                 |

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

void CreateRectangle

(

 long     chart_id,      // 845=B8D8:0B>@ 3@0D8:0

 string   name,          // 8<O >1J5:B0

 int      nwin,          // 8=45:A >:=0

 datetime time1,         // 2@5<O 1

 double   price1,        // F5=0 1

 datetime time2,         // 2@5<O 2

 double   price2,        // F5=0 2

 color    Color,         // F25B ;8=88

 bool     background,    // D>=>2>5 >B>1@065=85 ;8=88

 string   text           // B5:AB

 )

//---- 

  {

//----

   ObjectCreate(chart_id,name,OBJ_RECTANGLE,nwin,time1,price1,time2,price2);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetInteger(chart_id,name,OBJPROP_FILL,true);

   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,background);

   ObjectSetString(chart_id,name,OBJPROP_TOOLTIP,"\n"); //70?@5B 2A?;K20NI59 ?>4A:07:8

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,true); //>1J5:B =0 704=5< ?;0=5

//----

  }

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

//|  5@5CAB0=>2:0 ?@O<>C3>;L=>3> >1J5:B0                            |

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

void SetRectangle

(

 long     chart_id,      // 845=B8D8:0B>@ 3@0D8:0

 string   name,          // 8<O >1J5:B0

 int      nwin,          // 8=45:A >:=0

 datetime time1,         // 2@5<O 1

 double   price1,        // F5=0 1

 datetime time2,         // 2@5<O 2

 double   price2,        // F5=0 2

 color    Color,         // F25B ;8=88

 bool     background,    // D>=>2>5 >B>1@065=85 ;8=88

 string   text           // B5:AB

 )

//---- 

  {

//----

   if(ObjectFind(chart_id,name)==-1) CreateRectangle(chart_id,name,nwin,time1,price1,time2,price2,Color,background,text);

   else

     {

      ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

      ObjectMove(chart_id,name,0,time1,price1);

      ObjectMove(chart_id,name,1,time2,price2);

     }

//----

  }

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//----

   SecondRightTail=RightTail*60;

   SecondLeftTail=LeftTail*60;

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

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

   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//----

   ObjectDelete(0,FIB_SUP1);

   ObjectDelete(0,FIB_SUP2);

   ObjectDelete(0,FIB_RES1);

   ObjectDelete(0,FIB_RES2);

//----

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

//----

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

   datetime nTime[1];

   int to_copy;



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

   ArraySetAsSeries(time,true);

//----

   to_copy=1;

//----

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

   if(CopyClose(NULL,Timeframe,NumberofBar,to_copy,nClose)<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);

//----   

   double C=nClose[0];

   double H=nHigh[0];

   double L=nLow[0];

   double R=(H-L);

//----

   C=(H+L+C)/3;

   double D=(R/2)+C;

   double B=C-(R/2);

   double E=R+C;

   double A=C-R;

//----

   double R1=R*Ratio2;

   double R2=R*Ratio1;

   double B1=C-R2;

   double A1=C-R1;

//----

   double D1=C+R2;

   double E1=C+R1;

//----

   SetRectangle(0,FIB_RES2,0,nTime[0]-SecondLeftTail,E,time[0]+SecondRightTail,E1,Color_Res2,true,FIB_RES2);

   SetRectangle(0,FIB_RES1,0,nTime[0]-SecondLeftTail,D,time[0]+SecondRightTail,D1,Color_Res1,true,FIB_RES1);

   SetRectangle(0,FIB_SUP1,0,nTime[0]-SecondLeftTail,B,time[0]+SecondRightTail,B1,Color_Sup1,true,FIB_SUP1);

   SetRectangle(0,FIB_SUP2,0,nTime[0]-SecondLeftTail,A,time[0]+SecondRightTail,A1,Color_Sup2,true,FIB_SUP2);

//----

   ChartRedraw(0);

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