1
Views
0
Downloads
0
Favorites
Waddah_Attar_Pivot_V2
ÿþ//+------------------------------------------------------------------+
//| Waddah_Attar_Pivot_V2.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 Pivot 1 |
//+----------------------------------------------+
//---- >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= @>7>2K9 F25B
#property indicator_color1 clrMagenta
//---- ;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 4
#property indicator_width1 4
//---- >B>1@065=85 <5B:8 8=48:0B>@0
#property indicator_label1 "Pivot 1"
//+----------------------------------------------+
//| 0@0<5B@K >B@8A>2:8 Pivot 2 |
//+----------------------------------------------+
//---- >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= >@0=652K9 F25B
#property indicator_color2 clrOrange
//---- ;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 "Pivot 2"
//+----------------------------------------------+
//| 0@0<5B@K >B@8A>2:8 Pivot 3 |
//+----------------------------------------------+
//---- >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= 3>;C1>9 F25B
#property indicator_color3 clrDodgerBlue
//---- ;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 4
#property indicator_width3 4
//---- >B>1@065=85 <5B:8 8=48:0B>@0
#property indicator_label3 "Pivot 3"
//+----------------------------------------------+
//| %+ " + " |
//+----------------------------------------------+
input string SirName="Waddah_Attar_Pivot_V2"; // 5@20O G0ABL 8<5=8 3@0D8G5A:8E >1J5:B>2
input ENUM_TIMEFRAMES TimeFrame1=PERIOD_D1; // 5@8>4 3@0D8:0 8=48:0B>@0 (B09<D@59<) 1
input ENUM_TIMEFRAMES TimeFrame2=PERIOD_H4; // 5@8>4 3@0D8:0 8=48:0B>@0 (B09<D@59<) 2
input ENUM_TIMEFRAMES TimeFrame3=PERIOD_H1; // 5@8>4 3@0D8:0 8=48:0B>@0 (B09<D@59<) 3
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 price_name1,price_name2,price_name3;
string text_name1,text_name2,text_name3;
string name1,name2,name3;
//+------------------------------------------------------------------+
//| >;CG5=85 B09<D@59<0 2 2845 AB@>:8 |
//+------------------------------------------------------------------+
string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
{return(StringSubstr(EnumToString(timeframe),7,-1));}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//----
ObjectDelete(0,price_name1);
ObjectDelete(0,price_name2);
ObjectDelete(0,price_name3);
ObjectDelete(0,text_name1);
ObjectDelete(0,text_name2);
ObjectDelete(0,text_name3);
//----
ChartRedraw(0);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- =8F80;870F8O ?5@5<5==KE =0G0;0 >BAGQB0 40==KE
min_rates_total=2;
//---- =8F80;870F8O AB@8=3>2
price_name1=SirName+" upper price lable";
price_name2=SirName+" middle price lable";
price_name3=SirName+" lower price lable";
text_name1=SirName+" upper text lable";
text_name2=SirName+" middle text lable";
text_name3=SirName+" lower text lable";
name1="Pivot "+GetStringTimeframe(TimeFrame1);
name2="Pivot "+GetStringTimeframe(TimeFrame2);
name3="Pivot "+GetStringTimeframe(TimeFrame3);
//--- ?@>25@:0 ?5@8>4>2 3@0D8:>2 =0 :>@@5:B=>ABL
if(!TimeFramesCheck(name1,TimeFrame1)) return(INIT_FAILED);
if(!TimeFramesCheck(name2,TimeFrame2)) return(INIT_FAILED);
if(!TimeFramesCheck(name3,TimeFrame3)) return(INIT_FAILED);
//---- ?@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);
//---- A>740=85 <5B>: 4;O >B>1@065=8O 2 :=5 40==KE
PlotIndexSetString(0,PLOT_LABEL,name1);
//---- 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);
//---- A>740=85 <5B>: 4;O >B>1@065=8O 2 :=5 40==KE
PlotIndexSetString(1,PLOT_LABEL,name2);
//---- 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);
//---- A>740=85 <5B>: 4;O >B>1@065=8O 2 :=5 40==KE
PlotIndexSetString(2,PLOT_LABEL,name3);
//---- 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_V2");
//--- >?@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 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 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(),TimeFrame1,time[bar],2,iClose)) return(prev_calculated);
if(!CopyLow(Symbol(),TimeFrame1,time[bar],2,iLow)) return(prev_calculated);
if(!CopyHigh(Symbol(),TimeFrame1,time[bar],2,iHigh)) return(prev_calculated);
//----
IndBuffer1[bar]=(iHigh[0]+iLow[0]+iClose[0])/3;
//----
if(!CopyClose(Symbol(),TimeFrame2,time[bar],2,iClose)) return(prev_calculated);
if(!CopyLow(Symbol(),TimeFrame2,time[bar],2,iLow)) return(prev_calculated);
if(!CopyHigh(Symbol(),TimeFrame2,time[bar],2,iHigh)) return(prev_calculated);
//----
IndBuffer2[bar]=(iHigh[0]+iLow[0]+iClose[0])/3;
//----
if(!CopyClose(Symbol(),TimeFrame3,time[bar],2,iClose)) return(prev_calculated);
if(!CopyLow(Symbol(),TimeFrame3,time[bar],2,iLow)) return(prev_calculated);
if(!CopyHigh(Symbol(),TimeFrame3,time[bar],2,iHigh)) return(prev_calculated);
//----
IndBuffer3[bar]=(iHigh[0]+iLow[0]+iClose[0])/3;
}
//----
SetRightPrice(0,price_name1,0,time[0],IndBuffer1[0],indicator_color1);
SetRightPrice(0,price_name2,0,time[0],IndBuffer2[0],indicator_color2);
SetRightPrice(0,price_name3,0,time[0],IndBuffer3[0],indicator_color3);
//----
SetText(0,text_name1,0,name1,time[10],IndBuffer1[0],indicator_color1);
SetText(0,text_name2,0,name2,time[10],IndBuffer2[0],indicator_color2);
SetText(0,text_name3,0,name3,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);
//----
}
//+------------------------------------------------------------------+
//| TimeFramesCheck() |
//+------------------------------------------------------------------+
bool TimeFramesCheck(string IndName,
ENUM_TIMEFRAMES TFrame) //5@8>4 3@0D8:0 8=48:0B>@0 (B09<D@59<)
{
//--- ?@>25@:0 ?5@8>4>2 3@0D8:>2 =0 :>@@5:B=>ABL
if(TFrame<Period() && TFrame!=PERIOD_CURRENT)
{
Print("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!");
Print("!;54C5B 87<5=8BL 2E>4=K5 ?0@0<5B@K 8=48:0B>@0!");
return(false);
}
//---
return(true);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---