Скачать MetaTrader 5
Авторизуйтесь или зарегистрируйтесь, чтобы добавить комментарий
Подключи MQL5 Cloud Network. Миллионы трейдеров ждут этого!
Forex Trader
114237
Forex Trader 2006.02.19 23:42 
/*[[
Name := Pivot Ex
Author := Santa Claus
Link := http://www.metaquotes.net/
Separate Window := No
First Color := LightCyan
First Draw Type := Symbol
First Symbol := 233
Use Second Data := Yes
Second Color := Red
Second Draw Type := Symbol
Second Symbol := 86
]]*/

SetLoopCount(0);

//input parameters

//defines how many sessions back in history calculate pivots.
// note: more sessions - longer takes to calculate.
Input : SessionsToShow(5); //0 - all sessions

//when to calculate pivots
//- this is an hour when pivots are calculated
//(pivots are calculated based on prev candle close)
// 7 is midnight am EST - calculates pivots based on previous candles
// 8 is 1 am EST - calculates pivots based on close at 00:59
Input : CalculatePivotHour (8);

//if set to 1 - it displays OHLC and pivot values
Input : ShowComment(0);

//calculate weekly pivots - if set to '1' the indicator will show weekly pivots
Input : Weekly(0);

//calculate monthly pivots - if set to '1' the indicator will show monthly pivots
Input : Monthly(0);


//
//sessions times (cable session by default)
//

//if set to '1', will display symbols at the beginning and end of a session
Input : ShowSessions(1);
//beginning hour of a session
Input : sessionOpenHour(10); //24h PST
//end hour of a session
Input : sessionCloseHour(17); //7am pst

//
//aux parameters
//

//pivot colors
var : color_pivot(Gray);
var : color_pivot_R(Gray);
var : color_pivot_RM(Gray);
var : color_pivot_S(Gray);
var : color_pivot_SM(Gray);
//var : color_pivot(LightBlue);
//var : color_pivot_R(LightGreen);
//var : color_pivot_RM(LightGreen);
//var : color_pivot_S(Pink);
//var : color_pivot_SM(Pink);

//pivot line styles
/*var : style_pivot(STYLE_DASH);
var : style_pivot_R(STYLE_DASH);
var : style_pivot_RM(STYLE_DOT);
var : style_pivot_S(STYLE_DASH);
var : style_pivot_SM(STYLE_DOT);
*/
var : style_pivot(STYLE_SOLID);
var : style_pivot_R(STYLE_SOLID);
var : style_pivot_RM(STYLE_SOLID);
var : style_pivot_S(STYLE_SOLID);
var : style_pivot_SM(STYLE_SOLID);

//pivot line width
var : width_pivot(2);
var : width_pivot_R(1);
var : width_pivot_RM(1);
var : width_pivot_S(1);
var : width_pivot_SM(1);

//pivot line style
var : trendline_offset(11000);

//weekly pivot style
if (Weekly == 1) then
{
width_pivot = 2;
width_pivot_R = 2;
width_pivot_RM = 2;
width_pivot_S = 2;
width_pivot_SM = 2;
trendline_offset = 59000;
};

//monthly pivot style
if (Monthly == 1) then
{
width_pivot = 3;
width_pivot_R = 3;
width_pivot_RM = 3;
width_pivot_S = 3;
width_pivot_SM = 3;
trendline_offset = 200000;
};



//pivots
var: P(0),S(0),R(0),S0.5(0),R0.5(0),S1(0),R1(0),S1.5(0),R1.5(0),S2(0),R2(0),S2.5(0),R2.5(0),S3(0),R3(0) ;

var : CurrentHour(0),
PreviousHour(0);

var : yesterday_low(0),
yesterday_high(0),
yesterday_open(0),
yesterday_close(0);

// loop from first bar to current bar (with shift=0)
var : shift(0);
var : ShiftOffset(0);
var : SessionOffset(0);
ShiftOffset = Bars - 1;

if (SessionsToShow > 0) then { SessionOffset = SessionsToShow; }

//if not all sessions -> shift just N sessions back
if (SessionOffset > 0) Then
{
if (Monthly == 1) Then {
SessionOffset = SessionOffset * 31;
}
else if (Weekly == 1) Then {
SessionOffset = SessionOffset * 7;
}
ShiftOffset = (SessionOffset * 1440)/Period;
if (ShiftOffset > Bars - 1) Then ShiftOffset = Bars - 1;
}

//initialize HLOC
yesterday_low = Low[Bars-1];
yesterday_high = High[Bars-1];
yesterday_open = Open[Bars-1];
yesterday_close = Close[Bars-1];

var : range (0);

var : CurrentDate(0);
var : PivotPrefix(0);
//loop from offset to current bar and draw pivots
For shift=ShiftOffset Downto 0 Begin

CurrentHour = Timehour(Time[shift]);

//calculate pivots if time
if (CurrentHour == CalculatePivotHour and PreviousHour <> CalculatePivotHour and
(TimeDay(Time[shift]) == 1 or (Monthly <> 1 and (Weekly <> 1 or TimeDayOfWeek(Time[shift]) == 2)))) Then Begin

//TimeToStrEx doesn't work - doing custom
CurrentDate = NumberToStr( TimeYear(Time[shift]), 0 ) + NumberToStr( TimeMonth(Time[shift]), 0) + NumberToStr( TimeDay(Time[shift]), 0);
if (Weekly == 1) then {
//this is to give different name to weekly pivots
PivotPrefix = CurrentDate + NumberToStr(weekly, 0);
}
else {
PivotPrefix = CurrentDate;
}

range = yesterday_high - yesterday_low;

MoveObject(PivotPreFix + "V" ,OBJ_VLINE, Time[shift], P, time[shift], P, color_pivot, 1, 1);
SetObjectText(PivotPreFix + "V.txt", NumberToStr(range, 4), "Arial", 8, color_pivot );
MoveObject(PivotPreFix + "V.txt", OBJ_TEXT, Time[shift], High[shift] + 0.001, Time[shift], High[shift] + 0.001, white);

P = (yesterday_high + yesterday_low + yesterday_close) / 3; // + yesterday_open) / 4;

R1 = (2*P)-yesterday_low;
S1 = (2*P)-yesterday_high;

R2 = P+(yesterday_high - yesterday_low);
S2 = P-(yesterday_high - yesterday_low);

R3 = (2*P)+(yesterday_high-(2*yesterday_low));
S3 = (2*P)-((2* yesterday_high)-yesterday_low);

R0.5=(P+R1)/2;
S0.5=(P+S1)/2;

R1.5=(R1+R2)/2;
S1.5=(S1+S2)/2;

R2.5=(R2+R3)/2;
S2.5=(S2+S3)/2;

if (ShowComment == 1) Then Begin
Comment(
"Open= ",yesterday_open,
"\nHigh= ",yesterday_high,
"\nLow= ",yesterday_low,
"\nClose= ",yesterday_close,
"\n R3.0= ",R3,
"\n R2.5= ",R2.5,
"\n R2.0= ",R2,
"\n R1.5= ",R1.5,
"\n R1.0= ",R1,
"\n R0.5= ",R0.5,
"\nPivot= ",P,
"\n S0.5= ",S0.5,
"\n S1.0= ",S1,
"\n S1.5= ",S1.5,
"\n S2.0= ",S2,
"\n S2.5= ",S2.5,
"\n S3.0= ",S3);
End;

MoveObject(PivotPrefix + "P", OBJ_TRENDLINE, Time[shift], P, time[shift] + trendline_offset, P, color_pivot, width_pivot, style_pivot);
MoveObject(PivotPrefix + "R0.5", OBJ_TRENDLINE, Time[shift], R0.5, time[shift] + trendline_offset, R0.5, color_pivot_RM, width_pivot_RM, style_pivot_RM);
MoveObject(PivotPrefix + "R1", OBJ_TRENDLINE, Time[shift], R1, time[shift] + trendline_offset, R1, color_pivot_R, width_pivot_R, style_pivot_R);
MoveObject(PivotPrefix + "R1.5", OBJ_TRENDLINE, Time[shift], R1.5, time[shift] + trendline_offset, R1.5, color_pivot_RM, width_pivot_RM, style_pivot_RM);
MoveObject(PivotPrefix + "R2", OBJ_TRENDLINE, Time[shift], R2, time[shift] + trendline_offset, R2, color_pivot_R, width_pivot_R, style_pivot_R);
MoveObject(PivotPrefix + "R2.5", OBJ_TRENDLINE, Time[shift], R2.5, time[shift] + trendline_offset, R2.5, color_pivot_RM, width_pivot_RM, style_pivot_RM);
MoveObject(PivotPrefix + "R3", OBJ_TRENDLINE, Time[shift], R3, time[shift] + trendline_offset, R3, color_pivot_R, width_pivot_R, style_pivot_R);
MoveObject(PivotPrefix + "S0.5", OBJ_TRENDLINE, Time[shift], S0.5, time[shift] + trendline_offset, S0.5, color_pivot_SM, width_pivot_SM, style_pivot_SM);
MoveObject(PivotPrefix + "S1", OBJ_TRENDLINE, Time[shift], S1, time[shift] + trendline_offset, S1, color_pivot_S, width_pivot_S, style_pivot_S);
MoveObject(PivotPrefix + "S1.5", OBJ_TRENDLINE, Time[shift], S1.5, time[shift] + trendline_offset, S1.5, color_pivot_SM, width_pivot_SM, style_pivot_SM);
MoveObject(PivotPrefix + "S2", OBJ_TRENDLINE, Time[shift], S2, time[shift] + trendline_offset, S2, color_pivot_S, width_pivot_S, style_pivot_S);
MoveObject(PivotPrefix + "S2.5", OBJ_TRENDLINE, Time[shift], S2.5, time[shift] + trendline_offset, S2.5, color_pivot_SM, width_pivot_SM, style_pivot_SM);
MoveObject(PivotPrefix + "S3", OBJ_TRENDLINE, Time[shift], S3, time[shift] + trendline_offset, S3, color_pivot_S, width_pivot_S, style_pivot_S);

//set open for next session
yesterday_open = Open[shift];
yesterday_low = Low[shift];
yesterday_high = High[shift];

End;

yesterday_close = Close[shift];
if (yesterday_low > Low[shift]) Then yesterday_low = Low[shift];
if (yesterday_high < High[shift]) Then yesterday_high = High[shift];

if (ShowSessions == 1) Then Begin
//session open
if (CurrentHour == sessionOpenHour and PreviousHour <> sessionOpenHour) Then Begin
SetIndexValue(shift, Low[shift] - 0.5 * (High[shift] - Low[shift] ));
End;

//session close
if (CurrentHour <> sessionCloseHour and PreviousHour == sessionCloseHour) Then Begin
SetIndexValue2(shift, Low[shift] - 0.5 * (High[shift] - Low[shift]));
End;
End;

PreviousHour = CurrentHour;

End;
/
Авторизуйтесь или зарегистрируйтесь, чтобы добавить комментарий