Need Friday Breakout indicator ( Friday open, high, low ) Lines extended till next Friday also attached code
#property indicator_chart_window
extern int CountDays = 5;
datetime time1;
datetime time2;
double Friday_open, close, Friday_high, Friday_low;
double B, S, dev;
double pstyle, mstyle, cstyle;
int shift, num;
void ObjDel()
{
for (; num <= CountDays; num++)
{
ObjectDelete("Open[" + num + "]");
ObjectDelete("C_Buy[" + num + "]");
ObjectDelete("C_Sell[" + num + "]");
}
}
void PlotLine(string name, double value, double line_color, double style)
{
if (shift == -1) // Check if it's an extended line for Thursday
{
// Extend the line until Thursday by setting time2 to the end of Thursday
datetime thursdayTime = iTime(NULL, PERIOD_D1, shift) + PERIOD_D1 * 60 * 3;
ObjectCreate(name, OBJ_TREND, 0, time1, value, thursdayTime, value);
}
else
{
ObjectCreate(name, OBJ_TREND, 0, time1, value, time2, value);
}
ObjectSet(name, OBJPROP_WIDTH, 3);
ObjectSet(name, OBJPROP_STYLE, style);
ObjectSet(name, OBJPROP_RAY, false);
ObjectSet(name, OBJPROP_BACK, true);
ObjectSet(name, OBJPROP_COLOR, line_color);
}
int init()
{
return (0);
}
int deinit()
{
ObjDel();
Comment("");
return (0);
}
int start()
{
ObjDel();
num = 0;
for (shift = CountDays - 1; shift >= -1; shift--) // Extend the loop to shift = -1
{
if (shift == -1)
{
time1 = Time[0] - PERIOD_D1 * 60 * 7; // Set time1 to 7 days before current bar's time
time2 = Time[0] + Period() * 2; // Set time2 to 2 bars ahead of the current bar
}
else
{
time1 = iTime(NULL, PERIOD_D1, shift);
time2 = iTime(NULL, PERIOD_D1, shift - 1);
}
Friday_open = iOpen(NULL, PERIOD_D1, shift);
Friday_high = iHigh(NULL, PERIOD_D1, shift);
Friday_low = iLow(NULL, PERIOD_D1, shift);
dev = (Friday_open + 100);
B = Friday_high; //open + 100;
S = Friday_low; //open - 100;
int dayOfWeek = TimeDayOfWeek(time1);
bool isCurrentDay = (time1 >= Time[0]) && (time1 < Time[0] + Period());
if ((dayOfWeek == 5 && !isCurrentDay) || (dayOfWeek == 0 && shift == -1)) // Check if it's Friday (not the current day) or Sunday (extended day)
{
pstyle = STYLE_DASH;
mstyle = STYLE_SOLID;
cstyle = STYLE_DASHDOT;
num = shift;
PlotLine("Friday_Open[" + num + "]", Friday_open, Yellow, pstyle);
PlotLine("C_Buy[" + num + "]", B, Red, cstyle);
PlotLine("C_Sell[" + num + "]", S, Lime, cstyle);
}
}
return (0);
}
#property indicator_chart_window
extern int CountDays = 5;
datetime time1;
datetime time2;
double Friday_open, close, Friday_high, Friday_low;
double B, S, dev;
double pstyle, mstyle, cstyle;
int shift, num;
void ObjDel()
{
for (; num <= CountDays; num++)
{
ObjectDelete("Open[" + num + "]");
ObjectDelete("C_Buy[" + num + "]");
ObjectDelete("C_Sell[" + num + "]");
}
}
void PlotLine(string name, double value, double line_color, double style)
{
if (shift == -1) // Check if it's an extended line for Thursday
{
// Extend the line until Thursday by setting time2 to the end of Thursday
datetime thursdayTime = iTime(NULL, PERIOD_D1, shift) + PERIOD_D1 * 60 * 3;
ObjectCreate(name, OBJ_TREND, 0, time1, value, thursdayTime, value);
}
else
{
ObjectCreate(name, OBJ_TREND, 0, time1, value, time2, value);
}
ObjectSet(name, OBJPROP_WIDTH, 3);
ObjectSet(name, OBJPROP_STYLE, style);
ObjectSet(name, OBJPROP_RAY, false);
ObjectSet(name, OBJPROP_BACK, true);
ObjectSet(name, OBJPROP_COLOR, line_color);
}
int init()
{
return (0);
}
int deinit()
{
ObjDel();
Comment("");
return (0);
}
int start()
{
ObjDel();
num = 0;
for (shift = CountDays - 1; shift >= -1; shift--) // Extend the loop to shift = -1
{
if (shift == -1)
{
time1 = Time[0] - PERIOD_D1 * 60 * 7; // Set time1 to 7 days before current bar's time
time2 = Time[0] + Period() * 2; // Set time2 to 2 bars ahead of the current bar
}
else
{
time1 = iTime(NULL, PERIOD_D1, shift);
time2 = iTime(NULL, PERIOD_D1, shift - 1);
}
Friday_open = iOpen(NULL, PERIOD_D1, shift);
Friday_high = iHigh(NULL, PERIOD_D1, shift);
Friday_low = iLow(NULL, PERIOD_D1, shift);
dev = (Friday_open + 100);
B = Friday_high; //open + 100;
S = Friday_low; //open - 100;
int dayOfWeek = TimeDayOfWeek(time1);
bool isCurrentDay = (time1 >= Time[0]) && (time1 < Time[0] + Period());
if ((dayOfWeek == 5 && !isCurrentDay) || (dayOfWeek == 0 && shift == -1)) // Check if it's Friday (not the current day) or Sunday (extended day)
{
pstyle = STYLE_DASH;
mstyle = STYLE_SOLID;
cstyle = STYLE_DASHDOT;
num = shift;
PlotLine("Friday_Open[" + num + "]", Friday_open, Yellow, pstyle);
PlotLine("C_Buy[" + num + "]", B, Red, cstyle);
PlotLine("C_Sell[" + num + "]", S, Lime, cstyle);
}
}
return (0);
}