ÿþ
#property version "1.00"
#property strict
#property description "Shows daily percentage change value (yesterday's close to current bid)."
#property description "You can set hourly shift for day start."
#property description "Can also show weekly and monthly price changes."
#property indicator_chart_window
#property indicator_plots 0
input int Time_Shift = 0;
input bool Show_Weekly = true;
input bool Show_Monthly = true;
input int Font_Size = 8;
input int Arrow_Size = 10;
input color Up_Color = clrGreen;
input string Up_Arrow = "p";
input color Down_Color = clrRed;
input string Down_Arrow = "q";
input color No_Mvt_Color = clrBlue;
input int X_Position_Text = 21;
input int Y_Position_Text = 20;
input ENUM_BASE_CORNER Corner_Position_Text = CORNER_LEFT_LOWER;
input int X_Position_Arrow = 5;
input int Y_Position_Arrow = 20;
input ENUM_BASE_CORNER Corner_Position_Arrow = CORNER_LEFT_LOWER;
input int X_Position_Text_W = 21;
input int Y_Position_Text_W = 35;
input ENUM_BASE_CORNER Corner_Position_Text_W = CORNER_LEFT_LOWER;
input int X_Position_Arrow_W = 5;
input int Y_Position_Arrow_W = 35;
input ENUM_BASE_CORNER Corner_Position_Arrow_W = CORNER_LEFT_LOWER;
input int X_Position_Text_M = 21;
input int Y_Position_Text_M = 50;
input ENUM_BASE_CORNER Corner_Position_Text_M = CORNER_LEFT_LOWER;
input int X_Position_Arrow_M = 5;
input int Y_Position_Arrow_M = 50;
input ENUM_BASE_CORNER Corner_Position_Arrow_M = CORNER_LEFT_LOWER;
input string Text_Object = "DailyChange";
input string Arrow_Object = "ArrowChange";
input string Text_Object_W = "WeeklyChange";
input string Arrow_Object_W = "ArrowChange_W";
input string Text_Object_M = "MonthlyChange";
input string Arrow_Object_M = "ArrowChange_M";
int OnInit()
{
if ((Time_Shift > 12) || (Time_Shift < -12))
{
Alert("Time shift should be between -12 and 12.");
return(INIT_FAILED);
}
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
ObjectDelete(0, Text_Object);
ObjectDelete(0, Arrow_Object);
ObjectDelete(0, Text_Object_W);
ObjectDelete(0, Arrow_Object_W);
ObjectDelete(0, Text_Object_M);
ObjectDelete(0, Arrow_Object_M);
ChartRedraw();
}
int OnCalculate(const int rates_total,
const int prev_calculated,
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[])
{
double PercChange, DailyClose = -1;
string PerChg;
if (Time_Shift == 0)
{
double CloseDaily[];
if (CopyClose(Symbol(), PERIOD_D1, 1, 1, CloseDaily) != 1) return(0);
DailyClose = CloseDaily[0];
}
else
{
double CloseHourly[];
datetime TimeHourly[];
MqlDateTime datetime_str;
if (CopyClose(Symbol(), PERIOD_H1, 0, 25, CloseHourly) != 25) return(0);
if (CopyTime(Symbol(), PERIOD_H1, 0, 25, TimeHourly) != 25) return(0);
TimeToStruct(TimeHourly[24] + Time_Shift * 3600, datetime_str);
int current_img_day = datetime_str.day_of_year;
for (int i = 23; i >= 0; i--)
{
TimeToStruct(TimeHourly[i] + Time_Shift * 3600, datetime_str);
if (datetime_str.day_of_year != current_img_day)
{
DailyClose = CloseHourly[i];
break;
}
}
}
PercChange = ((SymbolInfoDouble(Symbol(), SYMBOL_BID) - DailyClose) / DailyClose) * 100;
PerChg = "Daily Change: " + DoubleToString(PercChange, 2) + "%";
ShowObjects(PercChange,
PerChg,
Text_Object,
Arrow_Object,
Corner_Position_Text,
X_Position_Text,
Y_Position_Text,
Corner_Position_Arrow,
X_Position_Arrow,
Y_Position_Arrow);
if (Show_Weekly)
{
double CloseWeekly[];
if (CopyClose(Symbol(), PERIOD_W1, 1, 1, CloseWeekly) != 1) return(0);
double WeeklyClose = CloseWeekly[0];
PercChange = ((SymbolInfoDouble(Symbol(), SYMBOL_BID) - WeeklyClose) / WeeklyClose) * 100;
PerChg = "Weekly Change: " + DoubleToString(PercChange, 2) + "%";
ShowObjects(PercChange,
PerChg,
Text_Object_W,
Arrow_Object_W,
Corner_Position_Text_W,
X_Position_Text_W,
Y_Position_Text_W,
Corner_Position_Arrow_W,
X_Position_Arrow_W,
Y_Position_Arrow_W);
}
if (Show_Monthly)
{
double MonthlyClose = -1;
if (Time_Shift == 0)
{
double CloseMonthly[];
if (CopyClose(Symbol(), PERIOD_MN1, 1, 1, CloseMonthly) != 1) return(0);
MonthlyClose = CloseMonthly[0];
}
else
{
double CloseHourly[];
datetime TimeHourly[];
MqlDateTime datetime_str;
if (CopyClose(Symbol(), PERIOD_H1, 0, 31 * 24 + 1, CloseHourly) != 31 * 24 + 1) return(0);
if (CopyTime(Symbol(), PERIOD_H1, 0, 31 * 24 + 1, TimeHourly) != 31 * 24 + 1) return(0);
TimeToStruct(TimeHourly[31 * 24] + Time_Shift * 3600, datetime_str);
int current_img_month = datetime_str.mon;
for (int i = 31 * 24; i >= 0; i--)
{
TimeToStruct(TimeHourly[i] + Time_Shift * 3600, datetime_str);
if (datetime_str.mon != current_img_month)
{
MonthlyClose = CloseHourly[i];
break;
}
}
}
PercChange = ((SymbolInfoDouble(Symbol(), SYMBOL_BID) - MonthlyClose) / MonthlyClose) * 100;
PerChg = "Monthly Change: " + DoubleToString(PercChange, 2) + "%";
ShowObjects(PercChange,
PerChg,
Text_Object_M,
Arrow_Object_M,
Corner_Position_Text_M,
X_Position_Text_M,
Y_Position_Text_M,
Corner_Position_Arrow_M,
X_Position_Arrow_M,
Y_Position_Arrow_M);
}
return(rates_total);
}
void ShowObjects(double PercChange,
string PerChg,
string text_obj,
string arrow_obj,
ENUM_BASE_CORNER corner_pos_text,
int x_pos_text,
int y_pos_text,
ENUM_BASE_CORNER corner_pos_arrow,
int x_pos_arrow,
int y_pos_arrow)
{
string Arrow = "";
color Obj_Color = No_Mvt_Color;
if (PercChange > 0)
{
Arrow = Up_Arrow;
Obj_Color = Up_Color;
}
else if (PercChange < 0)
{
Arrow = Down_Arrow;
Obj_Color = Down_Color;
}
if (ObjectFind(0, text_obj) < 0)
{
ObjectCreate(0, text_obj, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, text_obj, OBJPROP_CORNER, corner_pos_text);
ObjectSetInteger(0, text_obj, OBJPROP_XDISTANCE, x_pos_text);
ObjectSetInteger(0, text_obj, OBJPROP_YDISTANCE, y_pos_text);
ObjectSetInteger(0, text_obj, OBJPROP_FONTSIZE, Font_Size);
ObjectSetString(0, text_obj, OBJPROP_FONT, "Verdana");
}
ObjectSetInteger(0, text_obj, OBJPROP_COLOR, Obj_Color);
ObjectSetString(0, text_obj, OBJPROP_TEXT, PerChg);
if (ObjectFind(0, arrow_obj) < 0)
{
ObjectCreate(0, arrow_obj, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, arrow_obj, OBJPROP_CORNER, corner_pos_arrow);
ObjectSetInteger(0, arrow_obj, OBJPROP_XDISTANCE, x_pos_arrow);
ObjectSetInteger(0, arrow_obj, OBJPROP_YDISTANCE, y_pos_arrow);
ObjectSetInteger(0, arrow_obj, OBJPROP_FONTSIZE, Font_Size);
ObjectSetString(0, arrow_obj, OBJPROP_FONT, "Wingdings 3");
}
ObjectSetInteger(0, arrow_obj, OBJPROP_COLOR, Obj_Color);
ObjectSetString(0, arrow_obj, OBJPROP_TEXT, Arrow);
}
Comments