(IsConnected)
Download scriptThis script is designed to act as an automated connectivity monitor for the MetaTrader platform. Its primary purpose is to track and record whether your trading connection is active or disconnected in real-time, providing you with a clear historical log of your system's uptime and downtime.
How it Works
The tool functions by continuously scanning your current connection status. Rather than just showing a simple "on" or "off" message, it monitors for the exact moment your status changes—transitioning from online to offline, or vice versa.
Whenever a change is detected, the script captures the precise local time of that event. It then creates a detailed entry in a dedicated text file.
Key Features
- Automated Logging: You don't need to manually record when your internet drops or when your connection resumes; the script handles this automatically.
- Detailed Timeline: When the status changes, the script "closes" the previous session by adding an end time and "opens" a new session with a start time. This allows you to see exactly how long each period of connectivity lasted.
- Real-Time Tracking: The system updates every second, ensuring that your logs remain accurate and up-to-date without lagging your platform.
- Clear Visual Feedback: The log entries are formatted to be easily readable, clearly distinguishing between "OnLine" and "OffLine" periods with timestamps.
- Session Summary: When you manually stop the script, it performs a final check to record the end time of your current status, ensuring that your very last session is accurately documented before closing the file.
Practical Use
This tool is highly useful for traders who need to audit their trading environment. By reviewing the generated text file, you can identify patterns in connectivity issues, verify your platform's stability during specific trading sessions, and maintain a professional record of your technical performance.
//+------------------------------------------------------------------+
//| (IsConnected).mq4 |
//| Copyright © 2005, komposter |
//| mailto:komposterius@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, komposter"
#property link "mailto:komposterius@mail.ru"
bool first = true;
bool Now_IsConnected = false;
bool Pre_IsConnected = true;
datetime Connect_Start = 0, Connect_Stop = 0;
int init() { start(); return(0); }
int start()
{
int handle = FileOpen( "_IsConnected.txt", FILE_WRITE | FILE_READ, " " );
FileSeek( handle, 0, SEEK_END );
FileWrite( handle, "- - - - - - - - - - - Expert initialized - - - - - - - - - -" );
while ( !IsStopped() )
{
Pre_IsConnected = Now_IsConnected;
Now_IsConnected = IsConnected();
if ( first ) { Pre_IsConnected = !Now_IsConnected; }
if ( Now_IsConnected != Pre_IsConnected )
{
if ( Now_IsConnected )
{
Connect_Start = LocalTime();
if ( !first )
{
FileSeek( handle, -55, SEEK_CUR );
FileWrite( handle, "- - - OffLine- - - " + TimeToStr( Connect_Stop, TIME_DATE ) + " " + TimeToStr( Connect_Stop, TIME_SECONDS ) + " - " + TimeToStr( Connect_Start, TIME_SECONDS ) );
}
if ( IsStopped() ) { break; }
FileWrite( handle, "+ + + OnLine + + + " + TimeToStr( Connect_Start, TIME_DATE ) + " " + TimeToStr( Connect_Start, TIME_SECONDS ) + " - " );
}
else
{
Connect_Stop = LocalTime();
if ( !first )
{
FileSeek( handle, -55, SEEK_CUR );
FileWrite( handle, "+ + + OnLine + + + " + TimeToStr( Connect_Start, TIME_DATE ) + " " + TimeToStr( Connect_Start, TIME_SECONDS ) + " - " + TimeToStr( Connect_Stop, TIME_SECONDS ) );
}
if ( IsStopped() ) { break; }
FileWrite( handle, "- - - OffLine- - - " + TimeToStr( Connect_Stop, TIME_DATE ) + " " + TimeToStr( Connect_Stop, TIME_SECONDS ) + " - " );
}
}
first = false;
FileFlush( handle );
Sleep(1000);
}
if ( Now_IsConnected )
{
FileSeek( handle, -55, SEEK_CUR );
FileWrite( handle, "+ + + OnLine + + + " + TimeToStr( Connect_Start, TIME_DATE ) + " " + TimeToStr( Connect_Start, TIME_SECONDS ) + " - " + TimeToStr( LocalTime(), TIME_SECONDS ) );
}
else
{
FileSeek( handle, -55, SEEK_CUR );
FileWrite( handle, "- - - OffLine- - - " + TimeToStr( Connect_Stop, TIME_DATE ) + " " + TimeToStr( Connect_Stop, TIME_SECONDS ) + " - " + TimeToStr( LocalTime(), TIME_SECONDS ) );
}
FileWrite( handle, "- - - - - - - - - - - Expert was stoped - - - - - - - - - - -\n" );
FileClose( handle );
return(0);
}
Comments