Setka
Download scriptThis script is designed as a visual utility for the MetaTrader trading platform to help traders organize their charts by automatically generating a structured grid system. Instead of requiring a user to manually draw dozens of lines to mark specific times or price levels, this tool automates that process to create a consistent background "map" for technical analysis.
Core Functionality
The script operates on two primary dimensions: Time (Vertical Lines) and Price (Horizontal Lines).
1. Time Markers (Vertical Lines)
The tool scans through historical data to identify and mark significant trading sessions. It automatically places vertical lines at specific times of the day to highlight market activity:
- Daily Start: Marks the beginning of a new trading day.
- London Session: Specifically identifies the start of the London trading session.
- Weekly Start: Highlights the beginning of the trading week with a distinct color.
- Standard Markers: Places regular markers at other intervals to provide a consistent chronological flow.
The script uses dynamic coloring (such as Gold, Red, or Aqua) to distinguish these important milestones from standard time divisions, allowing traders to identify high-volatility periods at a glance.
2. Price Grid (Horizontal Lines)
In addition to the time markers, the script generates a dense horizontal grid across the chart. This creates a visual "ruler" for price action:
- Uniform Spacing: It calculates consistent increments to place horizontal lines across the price range.
- Visual Reference: These lines serve as a background guide, making it easier for traders to gauge price movements and identify support or resistance levels relative to the overall market structure.
Operational Logic
- Automatic Updates: The script is designed to be "smart" about how it calculates data. It monitors the chart's history and ensures that it only performs heavy calculations when new data arrives (i.e., when a new hour closes), preventing unnecessary strain on the computer's resources.
- Dynamic Scaling: It calculates the appropriate amount of historical data to display based on what is currently visible on your screen, ensuring the grid remains relevant regardless of how far back you scroll.
- Cleanup and Organization: Every time the script is reset or updated, it automatically clears old objects from the chart. This prevents "ghost lines" from cluttering your workspace and ensures that the visual grid always stays aligned with the current market data.
Summary for the User
Essentially, this tool transforms a blank trading chart into a structured workspace. It draws a comprehensive background "map" that highlights when major global markets open and provides a steady horizontal scale to help you visualize price movement more accurately.
//+------------------------------------------------------------------+
//| Setka.mq4 |
//| Ïðèâàëîâ Ñ.Â. |
//| Skype -> privalov-sv |
//+------------------------------------------------------------------+
#property copyright "Ïðèâàëîâ Ñ.Â."
#property link "Skype -> privalov-sv"
#property indicator_chart_window
datetime t;
color LineColor = DimGray;
int LineStyle = 4;
int LineWidth = 1;
bool LineOnBckgrnd = true;
string name_g="Setka_g_";
string name_v="Setka_v_";
int i,var,Shet,MinBars;
int prPeriod = PERIOD_H1;
int PreBars;
datetime BarTime;
int StartPos;
string mSymbol;
double vertikal;
bool flag=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
mSymbol = Symbol();
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
// óäàëÿþòñÿ âñå îáúåêòû ñ ãðàôèêà.
for (i=0;i<Shet;i++) {
ObjectDelete(name_g+DoubleToStr(i,0));
ObjectDelete(name_v+DoubleToStr(i,0));
}
return(0);
}
//+------------------------------------------------------------------+
//|ðàñ÷åòû ïðè èíèöèàëèçàöèè è ñáîÿõ |
//+------------------------------------------------------------------+
int Reset() {
MinBars = MathMin(iBars(mSymbol, prPeriod)-1,WindowBarsPerChart());
StartPos = MinBars;
PreBars = 0;
BarTime = 0;
flag = true;
// óäàëÿþòñÿ ñîçäàííûå îáúåêòû ñ ãðàôèêà.
for (i=0;i<Shet;i++) {
ObjectDelete(name_g+DoubleToStr(i,0));
ObjectDelete(name_v+DoubleToStr(i,0));
}
flag=true;
Shet=0; //ñáðàñûâàåì ñ÷åò÷èê ëèíèé
StartPos++;
return(StartPos);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
// Ðàáîòàåì òîëüêî ïî çàêîí÷èâøèìñÿ áàðàì
if (iBars(mSymbol, prPeriod) == PreBars) return(0);
// Ïðîâåðèì, äîñòàòî÷íî ëè áàðîâ íà ãðàôèêå
if (iBars(mSymbol, prPeriod) < MinBars) return(0);
// Åñëè íå áûëî äîêà÷êè èñòîðèè, îáñ÷èòûâàåì òîëüêî çàêîí÷èâøèéñÿ áàð
if (iBars(mSymbol, prPeriod)-PreBars == 1 && BarTime==iTime(mSymbol, prPeriod,1)) StartPos = 1;
// Èíà÷å ïåðåñ÷èòûâàåì çàäàííîå â ôóíêöèè Reset() êîëè÷åñòâî áàðîâ
else StartPos = Reset();
// Ìîäèôèöèðóåì êîíòðîëüíûå ïåðåìåííûå
PreBars = iBars(mSymbol, prPeriod);
BarTime = iTime(mSymbol, prPeriod,0);
// Öèêë ïî èñòîðèè
for (i=0; i<StartPos; i++) {
// àëãîðèòì ðàñ÷åòà .....
t=iTime(Symbol(),PERIOD_H1,0)+60*60*(i-StartPos+2);
var=TimeHour(t);
LineColor=DimGray;
if(var==0) LineColor=Aqua; // íà÷àëî ñóòîê
if(var==8) LineColor=Gold; // íà÷àëî Ëîíäîí
if(var==0 && TimeDayOfWeek(t)==1) LineColor=Red; // íà÷àëî íåäåëè
if(!ObjectCreate (name_g+DoubleToStr(Shet,0),OBJ_VLINE,0,t,0))
{
Print("error: íå ñîçäàí ãðàôè÷åñêèé îáúåêò name_g code #",GetLastError()," Symbol=", Symbol());
}
ObjectSet (name_g+DoubleToStr(Shet,0),OBJPROP_STYLE,LineStyle);
ObjectSet (name_g+DoubleToStr(Shet,0),OBJPROP_COLOR,LineColor);
ObjectSet (name_g+DoubleToStr(Shet,0),OBJPROP_WIDTH,LineWidth);
ObjectSet (name_g+DoubleToStr(Shet,0),OBJPROP_BACK, LineOnBckgrnd);
ObjectSet (name_g+DoubleToStr(Shet,0),OBJPROP_TIMEFRAMES,NULL);
Shet++;
} // pos=StartPos;pos>0;pos--)
// öèêë ïî âåðòèêàëè
if(flag) {
LineColor=DimGray;
for(i=0; i<3000; i++) {
Shet++;
vertikal=i*0.005; // øàã ñåòêè
if(!ObjectCreate (name_v+DoubleToStr(Shet,0),OBJ_HLINE,0,t,vertikal))
{
Print("error: íå ñîçäàí ãðàôè÷åñêèé îáúåêò name_v code #",GetLastError()," Symbol=", Symbol());
}
ObjectSet (name_v+DoubleToStr(Shet,0),OBJPROP_STYLE,LineStyle);
ObjectSet (name_v+DoubleToStr(Shet,0),OBJPROP_COLOR,LineColor);
ObjectSet (name_v+DoubleToStr(Shet,0),OBJPROP_WIDTH,LineWidth);
ObjectSet (name_v+DoubleToStr(Shet,0),OBJPROP_BACK, LineOnBckgrnd);
ObjectSet (name_v+DoubleToStr(Shet,0),OBJPROP_TIMEFRAMES,NULL);
}
flag=false;
}
return(0);
}
Comments