I have a simple function that draws a daily open line for that day and then also for that week but once i change the timeframe of the function for monthly it just stops working Heres the daily :
void CreateOpenLine(int barsBack)
{
// Set up necessary variablesdatetime start_time, end_time;
double open_price;
string line_name;
int i;
datetime previous_time = 0;
// Loop through the chart's barsfor(i = 0; i < barsBack ; i++)
{
// Get the start time of the current bar
start_time = iTime(Symbol(), PERIOD_D1, i);
open_price = iOpen(Symbol(), PERIOD_D1, i);
// Check if this is the first bar of the dayif(TimeDay(start_time) != TimeDay(previous_time))
{
// set the start_time to the begining of the day
start_time = start_time - (start_time % 86400);
end_time = start_time + 86400;
// Create a unique name for the line
line_name = "Open Line Daily " + IntegerToString(i)+IntegerToString(ObjectsTotal(0,0, OBJ_TREND) + 1);
// Draw the lineif(!ObjectCreate(line_name, OBJ_TREND, 0, start_time, open_price, end_time, open_price))
{
// Print an error message if the line could not be createdPrint("Error creating open line: ", GetLastError());
}
else
{
ObjectSetInteger(0,line_name,OBJPROP_COLOR,OpenLineColorDaily);
ObjectSetInteger(0,line_name,OBJPROP_WIDTH,OpenLineWeightDaily);
ObjectSetInteger(0,line_name,OBJPROP_STYLE,OpenLineDailyStyle);
ObjectSetInteger(0,line_name,OBJPROP_SELECTABLE,true);
ObjectSetInteger(0,line_name,OBJPROP_RAY,false);
}
}
// Store the current bar's time for the next iteration
previous_time = start_time;
}
}
The weekly
void CreateOpenLineWeekly(int barsBack)
{
// Set up necessary variablesdatetime start_time, end_time;
double open_price;
string line_name;
int i;
datetime previous_time = 0;
// Loop through the chart's barsfor(i = 0; i < barsBack ; i++)
{
// Get the start time of the current bar
start_time = iTime(Symbol(), PERIOD_W1, i);
open_price = iOpen(Symbol(), PERIOD_W1, i);
// Check if this is the first bar of the dayif(TimeDay(start_time) != TimeDay(previous_time))
{
// set the start_time to the begining of the day
start_time = start_time;
end_time = start_time + 604800;
// Create a unique name for the line
line_name = "Open Line Weekly" + IntegerToString(i)+IntegerToString(ObjectsTotal(0,0, OBJ_TREND) + 1);
// Draw the lineif(!ObjectCreate(line_name, OBJ_TREND, 0, start_time, open_price, end_time, open_price))
{
// Print an error message if the line could not be createdPrint("Error creating open line: ", GetLastError());
}
else
{
ObjectSetInteger(0,line_name,OBJPROP_COLOR,OpenLineColorWeekly);
ObjectSetInteger(0,line_name,OBJPROP_WIDTH,OpenLineWeightWeekly);
ObjectSetInteger(0,line_name,OBJPROP_STYLE,OpenLineWeeklyStyle);
ObjectSetInteger(0,line_name,OBJPROP_SELECTABLE,true);
ObjectSetInteger(0,line_name,OBJPROP_RAY,false);
}
}
// Store the current bar's time for the next iteration
previous_time = start_time;
}
}
Here is the monthly where it just stops working :
void CreateOpenLineMonthly(int barsBack)
{
// Set up necessary variablesdatetime start_time, end_time;
double open_price;
string line_name;
int i;
datetime previous_time = 0;
end_time = 0;
// Loop through the chart's barsfor(i = 0; i < barsBack ; i++)
{
// Get the start time of the current bar
start_time = iTime(Symbol(), PERIOD_MN1, i);
open_price = iOpen(Symbol(), PERIOD_MN1, i);
// Check if this is the first bar of the dayif(TimeDay(start_time) != TimeDay(previous_time))
{
// set the start_time to the begining of the day
start_time = start_time;
if(Month() == 1)
{
end_time = start_time + 2678400;
}
elseif(Month() == 2)
{
end_time = start_time + 2419200;
}
elseif(Month() == 3)
{
end_time = start_time + 2678400;
}
elseif(Month() == 4)
{
end_time = start_time + 2592000;
}
elseif(Month() == 5)
{
end_time = start_time + 2678400;
}
elseif(Month() == 6)
{
end_time = start_time + 2592000;
}
elseif(Month() == 7)
{
end_time = start_time + 2678400;
}
elseif(Month() == 8)
{
end_time = start_time + 2592000;
}
// Create a unique name for the line
line_name = "Open Line Monthly " + IntegerToString(i)+IntegerToString(ObjectsTotal(0,0, OBJ_TREND) + 1);
// Draw the lineif(!ObjectCreate(line_name, OBJ_TREND, 0, start_time, open_price, end_time, open_price))
{
// Print an error message if the line could not be createdPrint("Error creating open line: ", GetLastError());
}
else
{
ObjectSetInteger(0,line_name,OBJPROP_COLOR,OpenLineColorMonthly);
ObjectSetInteger(0,line_name,OBJPROP_WIDTH,OpenLineWeightMonthly);
ObjectSetInteger(0,line_name,OBJPROP_STYLE,OpenLineMonthlyStyle);
ObjectSetInteger(0,line_name,OBJPROP_SELECTABLE,true);
ObjectSetInteger(0,line_name,OBJPROP_RAY,false);
}
}
// Store the current bar's time for the next iteration
previous_time = start_time;
}
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Heres the daily :
The weekly
Here is the monthly where it just stops working :
I call the function like this :