SnapShotI
Download scriptThis tool is designed to automate the process of capturing visual records of your trading charts. Instead of manually taking screenshots every time a new price candle forms or at specific intervals, this script handles the photography automatically, ensuring you have a consistent visual history of your market analysis.
Core Functionality
The primary purpose of the script is to identify specific moments in time—based on the formation of new "bars" or candles—and capture a high-quality image of the current chart window. It is built to be "set and forget," running in the background to document price action as it unfolds.
Key Logic Components
- Timing and Frequency: The script allows you to define how often captures occur. You can set it to take a screenshot every time a new bar appears, or customize the frequency to take multiple shots within a single bar period. It also features a "delay" mechanism, which allows the capture to happen a few ticks after a new bar starts, ensuring the visual layout has settled.
- Automated File Management: Every time a screenshot is triggered, the script automatically generates a unique filename. It organizes these files by using the specific currency symbol, the timeframe (e.g., 1-hour, 15-minute), and a precise timestamp including the year, month, day, hour, minute, and second. This prevents files from overwriting each other and makes it easy to organize your historical data.
- Visual Feedback: When active, the tool provides a status label on your chart screen. This serves as a confirmation that the script is running correctly and displays your current configuration settings. The script is smart enough to briefly hide this label during the actual capture process to ensure the text doesn't appear in your saved images.
- Clean Integration: The logic is designed to be non-intrusive. It monitors the passage of time and the transition of candles, performing its tasks silently in the background without interfering with your active trading movements or other indicators.
//+------------------------------------------------------------------+
//| SnapShotI.mq4 |
//| Copyright © 2006, MQLService |
//| http://www.mqlservice.com |
//| $Id: //depot/mt4files/experts/indicators/SnapShotI.mq4#6 $
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MQLService"
#property link "http://www.mqlservice.com"
#include <stdlib.mqh>
#property indicator_chart_window
extern int DelayTicks = 1; // Delay so many ticks after new bar
extern int ShotsPerBar = 1; // How many screen shots per bar
extern bool ShowLabel = true; // Displays text in down left corner
#define LABEL "SnapShotILabel"
int init()
{
ShowLabel();
return(0);
}
int deinit()
{
HideLabel();
return(0);
}
void ShowLabel()
{
if(!ShowLabel) return;
if(!ObjectCreate(LABEL, OBJ_LABEL, 0, 0, 0))
Print("Error: can't create label object! ", ErrorDescription(GetLastError()));
ObjectSet(LABEL, OBJPROP_CORNER, 2);
ObjectSet(LABEL, OBJPROP_XDISTANCE, 4);
ObjectSet(LABEL, OBJPROP_YDISTANCE, 2);
ObjectSetText(LABEL, "SnapShotI is active ("+DelayTicks+","+ShotsPerBar+")", 8, "Arial", Yellow);
}
void HideLabel()
{
if(!ShowLabel) return;
if(!ObjectDelete(LABEL))
Print("Error deleting label: ", ErrorDescription(GetLastError()));
}
int start(){
static datetime last_bar;
static int DoShot = -1;
static int old_phase = 3000000;
if(ShotsPerBar > 0)
int shot_interval = MathRound((60*Period())/ShotsPerBar);
else
shot_interval = 60*Period();
int phase = MathFloor((CurTime()-Time[0])/shot_interval);
if(Time[0] != last_bar){
last_bar = Time[0];
DoShot = DelayTicks;
}else if(phase > old_phase)
MakeScreenShot("i");
old_phase = phase;
if(DoShot == 0) MakeScreenShot();
if(DoShot >= 0) DoShot -= 1;
return(0);
}
string al0(int number, int digits){
// add leading zeros that the resulting string has 'digits' length.
string result;
result = DoubleToStr(number, 0);
while(StringLen(result)<digits) result = "0"+result;
return(result);
}
void MakeScreenShot(string sx=""){
static int no=0;
no++;
string fn = "SnapShot"+Symbol()+Period()+"\\"+Year()+"-"+al0(Month(),2)+"-"+al0(Day(),2)+" "+
al0(Hour(),2)+"_"+al0(Minute(),2)+"_"+al0(Seconds(),2)+" "+no+sx+".gif";
HideLabel();
if(!ScreenShot(fn,640,480)) Print("ScreenShot error: ", ErrorDescription(GetLastError()));
ShowLabel();
}
//+---- Programmed by Michal Rutka -----------------------------------------+
Comments