MQL5Book/Scripts/p5/ChartNavigate.mq5

25 lines
1.2 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:09:41 +02:00
//+------------------------------------------------------------------+
//| ChartNavigate.mq5 |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//| The script will shift current chart by specified number of bars |
//| in 'Shift' parameter relative to specified origin in Position. |
//+------------------------------------------------------------------+
#property script_show_inputs
input ENUM_CHART_POSITION Position = CHART_CURRENT_POS;
input int Shift = -1;
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
ChartSetInteger(0, CHART_AUTOSCROLL, false);
const int start = (int)ChartGetInteger(0, CHART_FIRST_VISIBLE_BAR);
ChartNavigate(0, Position, Shift);
const int stop = (int)ChartGetInteger(0, CHART_FIRST_VISIBLE_BAR);
Print("Moved by: ", stop - start, ", from ", start, " to ", stop);
}
//+------------------------------------------------------------------+