forked from rosh/MQL5Book
60 lines
2.3 KiB
MQL5
60 lines
2.3 KiB
MQL5
//+------------------------------------------------------------------+
| |||
//| ChartPanorama.mq5 |
| |||
//| Copyright 2021, MetaQuotes Ltd. |
| |||
//| https://www.mql5.com |
| |||
//+------------------------------------------------------------------+
| |||
#include "..\..\Include\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
| |||
| |||
*/
| |||
//+------------------------------------------------------------------+
|