STik
Download scriptThis script is designed to provide a visual representation of historical market activity by tracking and storing precise price data over time. Unlike standard indicators that only show what is currently visible on your screen, this tool maintains a persistent memory of price movements, allowing for a deeper analysis of past trends.
Data Collection and Persistence
The core logic of the script revolves around a continuous recording system. Every time the market moves (a "tick"), the tool captures the current price and the exact time it occurred.
To ensure that your data isn't lost when you close your trading platform, the script includes an automated filing system:
- Saving: When you close the software, the script automatically saves the accumulated history into local binary files.
- Loading: Every time you restart the software, it retrieves that saved history so you can continue exactly where you left off.
- Maintenance: The script includes a "freshness" check. If it detects that the loaded data is significantly outdated, it will clear the old archive and start a new one to ensure accuracy.
Analysis Logic
Once the data is loaded, the script performs a specific analysis on the history:
- Price Mapping: It traverses through the recorded history to identify specific price points.
- Trend Detection: The logic looks for repetitive patterns where prices match previous entries in the history.
- Visual Markers: When the script identifies these significant historical coordinates, it draws vertical markers (dotted lines) on your chart. These markers help highlight key levels or "points of interest" that have occurred in the past.
User Customization and Behavior
The tool allows for specific control over how much data is displayed at once via a user-defined chart range. Additionally, it features an automated "reset" behavior; the script is programmed to refresh its state at the start of each new hour, ensuring that the visual workspace remains organized and relevant to the current trading session.
In summary, this is a historical tracking tool that archives price data into permanent files and uses that archive to plot significant past market levels onto your current view.
//+------------------------------------------------------------------+
//| STik.mq4 |
//| sem |
//| http:// |
//+------------------------------------------------------------------+
#property copyright "sem"
#property link "http://"
#property indicator_separate_window
#property indicator_buffers 1
extern datetime Start = 0;
extern int TikChart = 350;
double ExtMapBuffer1[];
int mass1[120960,2];
bool tim;
int tickCounter;
int Handle1;
int Handle2;
int init()
{
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(0,DRAW_LINE,EMPTY,2,White);
ArrayInitialize(mass1,0);
IndicatorShortName("STik");
FileOpenn();
tickk();
return(0);
}
int start()
{
int temp;
mass1[tickCounter,0] = Bid * MathPow(10,Digits);
mass1[tickCounter,1] = TimeCurrent();
temp = tickCounter;
if (Start > 0)
{while (mass1[temp,1] > Start){temp = LoopRevers(temp);}
OutChart(temp);}
else OutChart(tickCounter);
if (tim && TimeMinute(TimeCurrent()) == 0) deinit();
if (TimeMinute(TimeCurrent()) > 0) tim = true;
tickCounter = Loop(tickCounter);
return(0);
}
void OutChart(int temp)
{
double a,b;
int c,d,h = 0;
int g = WindowFind("STik");
string l;
ObjectsDeleteAll(g,OBJ_VLINE);
for(int i = 0;i < TikChart;i++)
{ExtMapBuffer1[i] = mass1[temp,0] / MathPow(10,Digits);
while (d >= 2){temp = LoopRevers(temp);
if (mass1[temp,0] != mass1[LoopRevers(temp),0]) d = 0;}
if (mass1[temp,0] == mass1[LoopRevers(temp),0])d++;
else d = 0;
int t = LoopRevers(temp);
if (mass1[temp,1] < StrToTime(TimeToStr(Time[h])))
{l = TimeToStr(mass1[LoopRevers(temp),1],TIME_DATE|TIME_SECONDS);
l = StringConcatenate("PT ",l);
ObjectCreate(l,OBJ_VLINE,g,Time[i],mass1[LoopRevers(temp),0]);
ObjectSet(l,OBJPROP_STYLE,STYLE_DOT);
ObjectSet(l,OBJPROP_COLOR,Gold);
while (mass1[LoopRevers(t),1] < StrToTime(TimeToStr(Time[h]))) h = h + 1;}
temp = LoopRevers(temp);
if (mass1[temp,0] == 0) i = TikChart + 1;}
return(0);
}
int Loop(int a)
{a++;
if (a >= ArrayRange(mass1,0)) a = 0;
return(a);}
int LoopRevers(int a)
{a--;
if (a < 0)
a = ArrayRange(mass1,0)-1;
return(a);}
int tickk()
{int a;
static int b;
static int c;
a = GetTickCount();
if (a<b) c = (4294967296-b) + a;
else c = a-b;
if (b == 0) c = 0;
b = a;
return(c);}
void FileOpenn()
{
int a = 0,b = 0,size = ArraySize(mass1);
Handle1 = FileOpen("mass.bin",FILE_BIN|FILE_READ);a = GetLastError();
Handle2 = FileOpen("var.bin",FILE_BIN|FILE_READ);b = GetLastError();
if (Handle1 < 0 || Handle2 < 0)
{Print(" îòñóòñòâóþò ôàéëû àðõèâîâ!!. îøèáêà ïî ìàññèâó ¹ ",a," ïî èíäåêñó ¹ ",b);
ArrayInitialize(mass1,0);
tickCounter = 0;}
else
{FileReadArray(Handle1,mass1,0,size);
tickCounter = FileReadInteger(Handle2,LONG_VALUE);
FileClose(Handle1);
FileClose(Handle2);
if (mass1[LoopRevers(tickCounter),1] < TimeLocal() - 691200)
{Print(" äàííûå óñòàðåëè, íà÷èíàþ âåäåíèå àðõèâîâ çàíîâî.");
FileDelete("mass.bin");
FileDelete("var.bin");
ArrayInitialize(mass1,0);
tickCounter = 0;}}
return(0);
}
int deinit()
{
int size= ArraySize(mass1);
Handle1 = FileOpen("mass.bin",FILE_BIN|FILE_WRITE);
Handle2 = FileOpen("var.bin",FILE_BIN|FILE_WRITE);
FileWriteArray(Handle1,mass1,0,size);
FileWriteInteger(Handle2,tickCounter,LONG_VALUE);
FileClose(Handle1);
FileClose(Handle2);
tim = false;
return(0);
}
Comments