two lines_v1
Download scriptThis script is designed to automatically organize your trading charts by marking specific times of the day with visual boundaries. It acts as an automated time-marker tool that helps traders clearly identify key opening and closing periods without having to manually draw lines on every single day.
Core Functionality
The primary purpose of this tool is to scan your price history and place vertical lines on the chart at two specific moments each day: a designated "Open Time" and a designated "Close Time." By doing this, it creates a clear visual "window" for traders to focus on.
How It Works
- Customizable Schedule: You can define exactly when your trading session begins and ends by setting the hours and minutes in the settings. For example, if you only trade during a specific afternoon window, you can tell the script to mark those exact moments.
- Automatic History Mapping: The script looks back through your chart's history (up to a limit of 500 bars). It identifies every day in the past and places the markers accordingly.
- Visual Identification:
- The Open Time is marked with a Blue vertical line, signaling the start of your period of interest.
- The Close Time is marked with a Red vertical line, signaling the end of that period.
- Persistent Display: The script checks if a line already exists for a specific time before drawing it. This ensures that the chart remains clean and that lines are only placed once per designated time slot.
Practical Benefit
For a trader, this tool eliminates the repetitive task of manually drawing session boundaries. It provides an immediate visual reference for "active" trading zones versus "inactive" zones, helping you stay disciplined with your trading schedule and ensuring you can quickly see where your specific market hours begin and end across any historical date on your chart.
//+------------------------------------------------------------------+
//| two lines.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//| Made/Modified by Alejandro Galindo |
//| |
//| |
//| if this work/modification is helpful to you |
//| send me a PayPal donation to ag@elcactus.com |
//| any help is apreciated :) |
//| Thanks. |
//+-------------------------------------------------------------------+
#property copyright "Copyright © 2005. Alejandro Galindo"
#property link "http://tradingstuff.pisem.net"
#property indicator_chart_window
extern int OpenTimeHr=9;
extern int OpenTimeMin=30;
extern int CloseTimeHr=14;
extern int CloseTimeMin=30;
extern int CountBars=500;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int shift, NumBars=500;
double CloseTime,OpenTime;
if (Bars<CountBars) { NumBars=Bars-1; } else { NumBars=CountBars; }
for (shift=Bars-1;shift>=0;shift--) {
OpenTime=StrToTime(TimeDay(Time[shift])+" "+OpenTimeHr+":"+OpenTimeMin);
CloseTime=StrToTime(TimeDay(Time[shift])+" "+CloseTimeHr+":"+CloseTimeMin);
if (TimeHour(Time[shift])== OpenTimeHr && TimeMinute(Time[shift])==OpenTimeMin) {
if(ObjectFind("OpenTime"+shift) != 0)
{
ObjectCreate("OpenTime"+shift, OBJ_VLINE, 0, Time[shift], 0);
ObjectSet("OpenTime"+shift, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("OpenTime"+shift, OBJPROP_COLOR, Blue);
}
}
if (TimeHour(Time[shift])== CloseTimeHr && TimeMinute(Time[shift])==CloseTimeMin) {
if(ObjectFind("CloseTime"+shift) != 0)
{
ObjectCreate("CloseTime"+shift, OBJ_VLINE, 0, Time[shift], 0);
ObjectSet("CloseTime"+shift, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("CloseTime"+shift, OBJPROP_COLOR, Red);
}
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments