-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChartPanorama.mq5
60 lines (53 loc) · 2.25 KB
/
ChartPanorama.mq5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//+------------------------------------------------------------------+
//| ChartPanorama.mq5 |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#include <MQL5Book/Periods.mqh>
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
// exact size of price scale is undocumented, use rule of thumb
const int scale = 60;
// calculate total height, including gutters between windows
const int w = (int)ChartGetInteger(0, CHART_WINDOWS_TOTAL);
int height = 0;
int gutter = 0;
for(int i = 0; i < w; ++i)
{
if(i == 1)
{
gutter = (int)ChartGetInteger(0, CHART_WINDOW_YDISTANCE, i) - height;
}
height += (int)ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS, i);
}
Print("Gutter=", gutter, ", total=", gutter * (w - 1));
height += gutter * (w - 1);
Print("Height=", height);
// calculate total width, based on pixel per bar size,
// also including shift and price scale
const int shift = (int)(ChartGetInteger(0, CHART_SHIFT) ?
ChartGetDouble(0, CHART_SHIFT_SIZE) * ChartGetInteger(0, CHART_WIDTH_IN_PIXELS) / 100 : 0);
Print("Shift=", shift);
const int pixelPerBar = (int)MathRound(1.0 * ChartGetInteger(0, CHART_WIDTH_IN_PIXELS)
/ ChartGetInteger(0, CHART_WIDTH_IN_BARS));
const int width = (int)ChartGetInteger(0, CHART_FIRST_VISIBLE_BAR) * pixelPerBar + scale + shift;
Print("Width=", width);
// write the image file
const string filename = _Symbol + "-" + PeriodToString() + "-panorama.png";
if(ChartScreenShot(0, filename, width, height, ALIGN_LEFT))
{
Print("File saved: ", filename);
}
}
//+------------------------------------------------------------------+
/*
Gutter=2, total=2
Height=440
Shift=74
Width=2086
File saved: XAUUSD-H1-panorama.png
*/
//+------------------------------------------------------------------+