PeriodSeperator_edited_by_tc_v1.1mm
Download scriptThe Period Separator script is designed to enhance the visual organization of your trading charts by automatically placing vertical lines at specific time intervals. Instead of you having to manually identify when a new session, hour, or significant time block begins, this tool acts as a structural guide, helping you clearly distinguish between different periods of market activity.
Core Functionality
The primary purpose of this script is to provide "visual anchors." By drawing vertical lines at predetermined times, it allows traders to see at a glance when one time period ends and another begins. This is particularly useful for identifying recurring market patterns or session shifts.
How it Adapts to Different Timeframes
The logic is built to recognize different types of time divisions based on the specific settings you choose:
- Short-Term Intervals: For smaller timeframes (like 15-minute charts), the script identifies and marks every quarter-hour increment (0, 15, 30, and 45 minutes).
- Half-Hour Tracking: When set to a 30-minute timeframe, it places markers exactly every 30 minutes.
- Hourly & Daily Markers: The script includes logic to identify the start of full hours. It specifically looks for major transitions, such as the start of the day or specific significant hours.
- Extended Timeframes: It contains specialized logic for much larger blocks of time, including:
- Daily markers (at midnight).
- Weekly markers (specifically identifying the start of the week).
- Monthly and Yearly milestones.
- Custom Interval Mode: There is a unique "Interval" mode where you can set the script to mark time at custom-defined recurring minutes, provided they are under one hour.
Visual Customization
Beyond just finding the time, the script allows you to control how these separators appear on your screen so they don't clutter your workspace:
- Color: You can choose the specific color of the vertical lines to suit your chart's theme.
- Style & Weight: You can toggle between solid, dashed, or dotted lines and adjust how thick or thin the lines appear.
- Background Placement: You can choose whether the lines appear on the main foreground or are tucked into the background of the chart.
Technical Behavior
When you apply the script, it scans your historical price data. It identifies every instance where the time matches the criteria defined by the settings (e.g., "Is this the 4:00 PM mark?" or "Is this the start of a new day?"). Once a match is found, it draws a permanent vertical line at that specific moment on your chart. When you remove the script, it is programmed to clean up and delete those lines automatically to keep your chart tidy.
//+------------------------------------------------------------------+
//| Period Seperator.mq4 |
//| lucidlamp@gmail.com |
//+------------------------------------------------------------------+
//mod.trendchaser FF
#property link "lucidlamp@gmail.com"
#property indicator_chart_window
extern int tf=60;
extern int start_minute=0;
extern int interval=15;
int interval2=0;
extern color LineColor = DarkOliveGreen;
extern int LineStyle = 2;
extern int LineWidth = 1;
extern bool ObjOnBckgrnd = true;
extern int xObjScreens = 1;
extern string inputs="15 30 60 240(H4) 1440D 10080W 43200MN";
extern string inputs2="one year is 518400";
extern string inputs3="set tf to 0 to use interval";
extern string inputs4="interval only works under 60 minutes";
int iMinute1=00; // I use 12 as it corresponds with 8am EST, when the metals get active.
int iMinute2=00;
int iMinute3=00;
int iMinute4=00;
int iSecond=00;
int x=0;
double minutes = 0;
string name;
int init()
{
interval2=start_minute;
}
int deinit()
{
for(int z=1;z<=x;z++)
{
ObjectDelete(name + z);
}
}
int start()
{
int iIndicatorCounted=IndicatorCounted();
if(iIndicatorCounted<0)
{
return(-1);
}
int iLimit=Bars-iIndicatorCounted;
name = "Time" +tf +interval;
for(int i=iLimit;i>=0;i--)
{
if(i > WindowBarsPerChart()+1*xObjScreens) continue;
if(tf==15&&TimeMinute(Time[i])==0)
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==15&&TimeMinute(Time[i])==15)
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==15&&TimeMinute(Time[i])==30)
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==15&&TimeMinute(Time[i])==45)
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==30&&TimeMinute(Time[i])==0)
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==30&&TimeMinute(Time[i])==30)
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==60&&TimeMinute(Time[i])==iMinute1 && TimeSeconds(Time[i])==iSecond)
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==240&&TimeMinute(Time[i])==0&&TimeHour(Time[i])==0)
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==240&&TimeMinute(Time[i])==0&&TimeHour(Time[i])==4)
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==240&&TimeMinute(Time[i])==0&&TimeHour(Time[i])==8)
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==240&&TimeMinute(Time[i])==0&&TimeHour(Time[i])==12)
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==240&&TimeMinute(Time[i])==0&&TimeHour(Time[i])==16)
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==240&&TimeMinute(Time[i])==0&&TimeHour(Time[i])==20)
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==1440&&TimeHour(Time[i])==0&&TimeMinute(Time[i])==0 )
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==10080&&TimeDayOfWeek(Time[i])==1&&TimeMinute(Time[i])==0 &&TimeHour(Time[i])==0 )
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==43200&&TimeDay(Time[i])==1&&TimeMinute(Time[i])==0 &&TimeHour(Time[i])==0 )
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==518400&&TimeMonth(Time[i])==1&&TimeDayOfYear(Time[i])<=10 )
{
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+tf*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==0&&TimeMinute(Time[i])==interval2 )
{
interval2=interval2+interval;
x++;
ObjectCreate(name + x,OBJ_VLINE,0,Time[i]+interval2*60,High[i]);
ObjectSet(name + x,OBJPROP_COLOR,LineColor); // Color value to set/get object color.
ObjectSet(name + x,OBJPROP_STYLE,LineStyle); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style.
ObjectSet(name + x,OBJPROP_WIDTH,LineWidth); // Integer value to set/get object line width. Can be from 1 to 5.
ObjectSet(name + x,OBJPROP_BACK,ObjOnBckgrnd); // Boolean value to set/get background drawing flag for object. (for example "true" will hide the value at the bottom of the chart.)
}
if(tf==0&&interval2>59 ){interval2=start_minute;
}
}
}
Comments