two lines
Download scriptThis script is designed as a visual aid for traders who need to identify specific sessions or timeframes on their trading charts automatically. Instead of requiring the user to manually draw lines to mark important times every day, this tool automates that process by scanning historical and current price data.
Core Functionality
The logic operates by constantly monitoring the "time stamps" of the candles on your chart. You can customize two specific time points: an Opening Time and a Closing Time. Once these are set, the script scans the chart's history to find every instance where those exact hours and minutes occur.
How it Works
- Automatic Marking: Whenever the script detects a candle that matches your "Open" time, it automatically places a solid Blue vertical line on the chart.
- Closing Markers: Whenever it detects a candle matching your "Close" time, it places a solid Red vertical line.
- Historical Coverage: The tool looks back through a set number of past bars (which you can define). This means when you load the indicator, it will retroactively draw these lines on previous days, providing a clear visual history of your trading windows.
- Efficiency: It includes a check to ensure that it only draws a line once for each specific time. This prevents the chart from becoming cluttered with multiple overlapping lines for the same moment in time.
Practical Use
For a non-technical user, this tool simplifies chart organization. It is ideal for traders who operate within specific windows—such as the London or New York sessions—allowing them to see exactly when a period begins and ends at a glance, ensuring they can focus on their strategy without manually measuring the clock.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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