Waddah_Attar_Pivot

Author: Copyright © 2007, waddahattar@hotmail.com
2 Views
0 Downloads
0 Favorites
Waddah_Attar_Pivot
ÿþ//+------------------------------------------------------------------+

//|                                           Waddah_Attar_Pivot.mq5 |

//|                        Copyright © 2007, waddahattar@hotmail.com |

//|                             Waddah Attar waddahattar@hotmail.com |

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

#property copyright "Copyright © 2007, waddahattar@hotmail.com"

#property link      "waddahattar@hotmail.com"

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

#property version   "1.00"

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

#property indicator_chart_window

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

#property indicator_buffers 3

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

#property indicator_plots   3

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

//| 0@0<5B@K >B@8A>2:8 Daily Pivot              |

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

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

#property indicator_type1   DRAW_LINE

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

#property indicator_color1  clrLime

//---- ;8=8O 8=48:0B>@0 1 - =5?@5@K2=0O :@820O

#property indicator_style1  STYLE_SOLID

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

#property indicator_width1  3

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

#property indicator_label1  "Daily Pivot"

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

//| 0@0<5B@K >B@8A>2:8 Weekly Pivot             |

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

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

#property indicator_type2   DRAW_LINE

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

#property indicator_color2  clrRed

//---- ;8=8O 8=48:0B>@0 2 - =5?@5@K2=0O :@820O

#property indicator_style2  STYLE_SOLID

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

#property indicator_width2  4

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

#property indicator_label2  "Weekly Pivot"

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

//| 0@0<5B@K >B@8A>2:8 Monthly Pivot            |

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

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

#property indicator_type3   DRAW_LINE

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

#property indicator_color3  clrBlue

//---- ;8=8O 8=48:0B>@0 3 - =5?@5@K2=0O :@820O

#property indicator_style3  STYLE_SOLID

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

#property indicator_width3  5

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

#property indicator_label3  "Monthly Pivot"

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

//|  %+  " + "                 |

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

input string  SirName="Waddah_Attar_Pivot";         //5@20O G0ABL 8<5=8 3@0D8G5A:8E >1J5:B>2

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

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

//---- >1JO2;5=85 48=0<8G5A:>3> <0AA820, :>B>@K9 1C45B 2 

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

double IndBuffer1[],IndBuffer2[],IndBuffer3[];

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

int min_rates_total;

//---- 1JO2;5=85 AB@8=3>2 4;O B5:AB>2KE <5B>:

string daily_price_name,weekly_price_name,monthly_price_name;

string daily_text_name,weekly_text_name,monthly_text_name;

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//----

   ObjectDelete(0,daily_price_name);

   ObjectDelete(0,weekly_price_name);

   ObjectDelete(0,monthly_price_name);

   ObjectDelete(0,daily_text_name);

   ObjectDelete(0,weekly_text_name);

   ObjectDelete(0,monthly_text_name);

//----

   ChartRedraw(0);

  }

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

//| Custom indicator initialization function                         | 

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

void OnInit()

  {

//---- =8F80;870F8O ?5@5<5==KE =0G0;0 >BAGQB0 40==KE 

   min_rates_total=2;

//---- =8F80;870F8O AB@8=3>2

   daily_price_name=SirName+" upper price lable";

   weekly_price_name=SirName+" middle price lable";

   monthly_price_name=SirName+" lower price lable";

   daily_text_name=SirName+" upper text lable";

   weekly_text_name=SirName+" middle text lable";

   monthly_text_name=SirName+" lower text lable";



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

   SetIndexBuffer(0,IndBuffer1,INDICATOR_DATA);

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

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

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

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

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

   ArraySetAsSeries(IndBuffer1,true);



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

   SetIndexBuffer(1,IndBuffer2,INDICATOR_DATA);

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

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);

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

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);

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

   ArraySetAsSeries(IndBuffer2,true);



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

   SetIndexBuffer(2,IndBuffer3,INDICATOR_DATA);

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

   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);

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

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);

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

   ArraySetAsSeries(IndBuffer3,true);



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

   IndicatorSetString(INDICATOR_SHORTNAME,"Waddah_Attar_Pivot");



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

  }

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

//| 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[],

                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 @0AGQB0

   if(rates_total<min_rates_total) return(0);



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

   double PP,iClose[2],iHigh[2],iLow[2];

//---- 1JO2;5=85 F5;KE ?5@5<5==KE 8 ?>;CG5=85 C65 ?>AG8B0==KE 10@>2

   int limit,bar;

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

   ArraySetAsSeries(time,true);



//---- @0AGQB 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; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2

     }

   else

     {

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

     }



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

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

     {

      if(!CopyClose(Symbol(),PERIOD_D1,time[bar],2,iClose)) return(prev_calculated);

      if(!CopyLow(Symbol(),PERIOD_D1,time[bar],2,iLow)) return(prev_calculated);

      if(!CopyHigh(Symbol(),PERIOD_D1,time[bar],2,iHigh)) return(prev_calculated);

      //---- 

      PP=(iHigh[0]+iLow[0]+iClose[0])/3;

      IndBuffer1[bar]=PP;

      //---- 

      if(!CopyClose(Symbol(),PERIOD_W1,time[bar],2,iClose)) return(prev_calculated);

      if(!CopyLow(Symbol(),PERIOD_W1,time[bar],2,iLow)) return(prev_calculated);

      if(!CopyHigh(Symbol(),PERIOD_W1,time[bar],2,iHigh)) return(prev_calculated);

      //---- 

      PP=(iHigh[0]+iLow[0]+iClose[0])/3;

      IndBuffer2[bar]=PP;

      //---- 

      if(!CopyClose(Symbol(),PERIOD_MN1,time[bar],2,iClose)) return(prev_calculated);

      if(!CopyLow(Symbol(),PERIOD_MN1,time[bar],2,iLow)) return(prev_calculated);

      if(!CopyHigh(Symbol(),PERIOD_MN1,time[bar],2,iHigh)) return(prev_calculated);

      //---- 

      PP=(iHigh[0]+iLow[0]+iClose[0])/3;

      IndBuffer3[bar]=PP;

     }

//----

   SetRightPrice(0,daily_price_name,0,time[0],IndBuffer1[0],indicator_color1);

   SetRightPrice(0,weekly_price_name,0,time[0],IndBuffer2[0],indicator_color2);

   SetRightPrice(0,monthly_price_name,0,time[0],IndBuffer3[0],indicator_color3);

//----  

   SetText(0,daily_text_name,0,"Daily Pivot",time[10],IndBuffer1[0],indicator_color1);

   SetText(0,weekly_text_name,0,"Weekly Pivot",time[10],IndBuffer2[0],indicator_color2);

   SetText(0,monthly_text_name,0,"Monthly Pivot",time[10],IndBuffer3[0],indicator_color3);

//----     

   ChartRedraw(0);

   return(rates_total);

  }

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

//| calc lwma atr                                      |

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

double calc_atr(int index,const double  &h[],const double  &l[],const double  &c[])

  {

//--- 

   return(MathMax(h[index],c[index-1])-MathMin(l[index],c[index-1]));

//--- 

  }

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

//|  CreateText creation                                             |

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

void CreateText(long chart_id,// chart ID

                      string   name,              // object name

                      int      nwin,              // window index

                      string   txt,               // text

                      datetime time,              // price level time

                      double   price,             // price level

                      color    Color              // Text color

                      )

//---- 

  {

//----

   ObjectCreate(chart_id,name,OBJ_TEXT,nwin,time,price);

   ObjectSetString(chart_id,name,OBJPROP_TEXT,txt);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,true);

   ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,1);

//----

  }

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

//|  SetText reinstallation                                          |

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

void SetText(long chart_id,// chart ID

                   string   name,              // object name

                   int      nwin,              // window index

                   string   txt,               // text

                   datetime time,              // price level time

                   double   price,             // price level

                   color    Color              // Text color

                   )

//---- 

  {

//----

   if(ObjectFind(chart_id,name)==-1) CreateText(chart_id,name,nwin,txt,time,price,Color);

   else 

    {

     ObjectMove(chart_id,name,0,time,price);

     ObjectSetString(chart_id,name,OBJPROP_TEXT,txt);

    }

//----

  }

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

//|  RightPrice creation                                             |

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

void CreateRightPrice(long chart_id,// chart ID

                      string   name,              // object name

                      int      nwin,              // window index

                      datetime time,              // price level time

                      double   price,             // price level

                      color    Color              // Text color

                      )

//---- 

  {

//----

   ObjectCreate(chart_id,name,OBJ_ARROW_RIGHT_PRICE,nwin,time,price);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,true);

   ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,2);

//----

  }

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

//|  RightPrice reinstallation                                       |

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

void SetRightPrice(long chart_id,// chart ID

                   string   name,              // object name

                   int      nwin,              // window index

                   datetime time,              // price level time

                   double   price,             // price level

                   color    Color              // Text color

                   )

//---- 

  {

//----

   if(ObjectFind(chart_id,name)==-1) CreateRightPrice(chart_id,name,nwin,time,price,Color);

   else ObjectMove(chart_id,name,0,time,price);

//----

  }

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

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