Ticker
Download scriptThis tool functions as a specialized visual tracker designed to monitor and smooth out price movements on a trading chart. Rather than looking at the standard price candles, it translates raw market data into a distinct "Ticker" value that helps traders visualize trends more clearly.
Core Logic and Functionality
Data Collection and Storage The script tracks the market price as it changes in real-time. It stores a specific history of these prices (up to 1,000 data points by default) into an internal memory bank. Every time the price moves, the tool updates its records, shifting older values aside to make room for the newest information.
The Moving Average Calculation The primary purpose of this script is to calculate a "Signal Line." It does this using a Simple Moving Average (SMA). The logic works as follows:
- The tool looks back at a specific number of recent price points (defined by the user, defaulting to 10).
- It calculates the average value of these points.
- This average is then plotted as a separate line on your screen.
Visual Representation The tool provides two distinct visual layers:
- The Value Line: This represents the actual price data converted into a readable format.
- The Signal Line: This is the smoothed moving average. It helps filter out "noise" or minor price fluctuations, allowing you to see the broader direction of the market.
How it Behaves in Real-Time
The script is designed to be efficient; it only performs new calculations when a change in the market price actually occurs. Once enough data has been collected to satisfy the required period (e.g., 10 previous price points), the Signal Line begins to appear. As new prices come in, both lines move forward dynamically, providing a continuous stream of information regarding current price levels and their smoothed trends.
// Ticker.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 Red
#property indicator_width2 1
#property indicator_style2 2
extern int PeriodSMA=10; // Ïåðèîä ñèãíàëüíîé ëèíèè
extern int CountBars=1000; // Êîëè÷åñòâî îòîáðàæàåìûõ áàðîâ
int count;
int price;
int price_prev;
double period;
double ticker[100]; // áóôåð òèêîâ
double signal[100]; // áóôåð ñèãíàëüíîé ëèíèè
double buffer0[];
double buffer1[];
void init()
{
SetIndexBuffer(0,buffer0);
SetIndexLabel(0,"Value");
SetIndexDrawBegin(0,0);
SetIndexBuffer(1,buffer1);
SetIndexLabel(1,"Signal");
SetIndexDrawBegin(1,0);
count=ArrayResize(ticker,CountBars);
count=ArrayResize(signal,CountBars);
count=0;
ArrayInitialize(signal,EMPTY_VALUE); // EMPTY_VALUE=+2147483647
price_prev=0;
period=MathMax(1,PeriodSMA);
}
void start()
{
int i;
double sum;
price=MathRound(Bid/Point);
if (price_prev==0)
{
count=0;
price_prev=price;
ticker[0]=price*Point;
buffer0[0]=ticker[0];
IndicatorShortName("Ticker ("+count+") SMA ("+DoubleToStr(period,0)+")");
return;
}
if (price==price_prev) return;
price_prev=price;
for (i=count; i>=0; i--)
{
ticker[i+1]=ticker[i];
signal[i+1]=signal[i];
}
ticker[0]=price*Point;
if (count<CountBars-1) count++;
if (count>=period-1)
{
sum=0;
for (i=0; i<=period-1; i++) sum+=ticker[i];
signal[0]=sum/period;
}
for (i=0; i<=count; i++)
{
buffer0[i]=ticker[i];
buffer1[i]=signal[i];
}
IndicatorShortName("Ticker ("+count+") SMA ("+DoubleToStr(period,0)+")");
}
Comments