Ticker Trail_v1
Download scriptThis script functions as a specialized tracking tool designed to monitor and visualize price movements on a dedicated sub-window within your trading platform. It focuses on capturing the historical "path" of price changes and projecting a boundary based on user-defined parameters.
Core Functionality
1. Historical Data Reconstruction Upon initialization, the script performs a deep scan of recent market history (specifically looking at 1-minute candles). Rather than just plotting every single tick, it identifies significant price transitions—such as moves from "Open" to "High," "Low," or "Close." It organizes these movements into a chronological sequence, allowing you to see the historical progression of the asset's price action in a streamlined format.
2. The "Trail" Logic The script calculates a dynamic buffer known as a "Trail." You can customize the distance of this trail through the settings. For every price point recorded, the script calculates an upper and lower boundary:
- It determines a zone around the current price based on your specified "Trail" value.
- This creates a visual representation of volatility or a "buffer zone" surrounding the price movement.
3. Real-Time Tracking Once the historical data is loaded, the script shifts into real-time monitoring. It watches every new price update (tick) from the market:
- Price Filtering: It only records a new data point when the price actually changes, ensuring the display remains clean and relevant.
- Dynamic Updating: As new prices arrive, it pushes the old data forward in the sequence, updating the "Trail" boundaries automatically to match the latest market movement.
4. Visual Output The tool provides a dual-layer visualization in a separate window:
- Primary Line: Represents the actual price path (the "Ticker").
- Secondary Line: Represents the calculated "Trail" boundary.
- Live Reference: The script also places a horizontal reference line on your main chart to indicate the current bid price, allowing you to quickly compare the real-time market position against the historical trail data shown in the sub-window.
Summary for the User
In simple terms, this tool takes the complex history of price fluctuations and simplifies it into a "pathway." It shows you where the price has been and creates a consistent visual boundary (the trail) around that path. It helps traders visualize the relationship between price movement and a set distance, providing a cleaner perspective on price flow than a standard chart might offer.
// Ticker Trail.mq4
// Èíäèêàòîð
#property copyright "mandorr@gmail.com"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Gray
#property indicator_width1 1
#property indicator_style1 0
#property indicator_color2 Gray
#property indicator_width2 2
#property indicator_style2 0
extern int Trail=10; // Òðàë
extern int BarsCount=1000; // Êîëè÷åñòâî îòîáðàæàåìûõ áàðîâ
double buffer0[];
double buffer1[];
int tickers[];
int trails[];
int ticker;
int trail;
int price_prev;
int win_index;
string obj_name;
string win_name;
void init() {
SetIndexBuffer(0,buffer0);
SetIndexBuffer(1,buffer1);
SetIndexLabel(0,"Value");
SetIndexLabel(1,"Trail");
SetIndexDrawBegin(0,0);
SetIndexDrawBegin(1,0);
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
price_prev=0;
ticker=0;
trail=MathMax(1,Trail);
win_name="Ticker Trail ("+trail+")";
}
void deinit() {
ObjectsDeleteAll(win_index);
}
void start() {
int i, price;
if (ticker==0) {
Clean();
Setup();
}
price=MathRound(Bid/Point);
if (price==0) {return;}
if (price==price_prev) {return;}
price_prev=price;
ticker++;
if (ticker>BarsCount) {ticker=BarsCount;}
else {
ArrayResize(tickers,ticker);
ArrayResize(trails,ticker);
}
if (ticker>1) {
for (i=ticker-1; i>0; i--) {
tickers[i]=tickers[i-1];
trails[i]=trails[i-1];
}
tickers[0]=price;
}
if (trails[0]<price-trail) {trails[0]=price-trail;}
if (trails[0]>price+trail) {trails[0]=price+trail;}
for (i=0; i<ticker; i++) {
buffer0[i]=tickers[i]*Point;
buffer1[i]=trails[i]*Point;
}
buffer0[ticker]=0.0;
buffer1[ticker]=0.0;
IndicatorShortName(win_name);
win_index=WindowFind(win_name);
obj_name="Win"+win_index+"_Bid";
if (ObjectFind(obj_name)!=win_index) {
ObjectCreate(obj_name,OBJ_HLINE,win_index,Time[0],Bid);
}
ObjectSet(obj_name,OBJPROP_PRICE1,Bid);
ObjectSet(obj_name,OBJPROP_STYLE,DRAW_LINE);
ObjectSet(obj_name,OBJPROP_WIDTH,1);
ObjectSet(obj_name,OBJPROP_COLOR,Silver);
}
// î÷èñòèòü ãðàôèê
void Clean() {
for (int i=0; i<=BarsCount; i++) {
buffer0[i]=0.0;
buffer1[i]=0.0;
}
IndicatorShortName(win_name);
win_index=WindowFind(win_name);
ObjectsDeleteAll(win_index);
}
// Èñïîëüçîâàíèå ïîñëåäîâàòåëüíîñòè òèêîâ èç OHL ìèíóòíîãî ãðàôèêà
void Setup() {
int i, j, k, total, value_prev, value[4];
double open, high, low, median;
// íà÷àëüíîå çíà÷åíèå
ticker++;
ArrayResize(tickers,ticker);
ArrayResize(trails,ticker);
total=BarsCount; if (total>iBars(NULL,PERIOD_M1)) {total=iBars(NULL,PERIOD_M1);}
open=iOpen(NULL,PERIOD_M1,total-1);
value[0]=MathRound(open/Point);
tickers[0]=value[0];
trails[0]=value[0];
value_prev=0;
// Ýìóëÿöèÿ ïîñëåäîâàòåëüíîñòè òèêîâ èç OHL ìèíóòíîãî ãðàôèêà
for (i=total-1; i>=0; i--) {
open=iOpen(NULL,PERIOD_M1,i);
high=iHigh(NULL,PERIOD_M1,i);
low =iLow (NULL,PERIOD_M1,i);
median=0.5*(high+low);
value[0]=MathRound(open/Point);
value[1]=MathRound(high/Point);
value[2]=MathRound(low /Point);
value[3]=0;
if (open<median) {
// Ïîìåíÿòü ïîñëåäîâàòåëüíîñòü ñ OHL íà OLH
value[3]=value[1];
value[1]=value[2];
value[2]=value[3];
}
for (k=0; k<=2; k++) {
if (value[k]==value_prev) {continue;}
value_prev=value[k];
ticker++;
if (ticker>BarsCount) {ticker=BarsCount;}
else {
ArrayResize(tickers,ticker);
ArrayResize(trails,ticker);
}
if (ticker>1) {
for (j=ticker-1; j>0; j--) {
tickers[j]=tickers[j-1];
trails[j]=trails[j-1];
}
tickers[0]=value[k];
}
if (trails[0]<value[k]-trail) {trails[0]=value[k]-trail;}
if (trails[0]>value[k]+trail) {trails[0]=value[k]+trail;}
}
}
for (i=0; i<ticker; i++) {
buffer0[i]=tickers[i]*Point;
buffer1[i]=trails[i]*Point;
}
buffer0[ticker]=0.0;
buffer1[ticker]=0.0;
IndicatorShortName(win_name);
RefreshRates();
price_prev=value_prev;
}
// End
Comments