Loading…

Per Symbol View State Saver

Switching a chart between symbols throughout the day usually means losing your place: the zoom level can reset, the visible bars snap back to "most recent", and any objects you had hidden reappear. This indicator remembers that view state per symbol and puts it back exactly as you left it. A symbol change on a chart does not modify a running indicator in place - it deinitialises the current instance and starts a brand-new one on the new symbol. Symbol() therefore never actually changes value within one instance's lifetime: OnDeinit() always sees the same symbol this particular instance was attached to the whole time, whatever triggered the deinit. That fact is what makes reliable per-symbol capture possible without guessing at "old" versus "new" symbol timing - state is simply written under the current symbol's name every time an instance ends, and read back by whichever instance starts next. Scroll position is stored as the calendar time of the leftmost visible bar, not a raw bar index. Bar counts are not comparable across symbols - different history depth, session hours and feed gaps mean "bar 500" on one symbol is not "the same moment" as bar 500 on another - so the saved time is converted back into a bar shift with iBarShift() specifically for whichever symbol is being restored. Chart-object visibility uses the OBJPROP_TIMEFRAMES property as a show/hide flag: an object hidden with OBJ_NO_PERIODS and one shown with OBJ_ALL_PERIODS (or any other flag combination) round-trip through this indicator unchanged. Only objects still present on the chart when you return to a symbol are touched - the indicator never recreates or deletes anyone else's drawings, only toggles the visibility flag on ones that already exist. Notes and limitations - State is stored per symbol in MQL4\Files\ (or MQL5\Files\ on the native MQL5 build)PerSymbolViewStateSaver_ <symbol>.csv, one file per symbol this indicator has ever seen on this chart. These files are plain sandboxed text and are not synced or shared with any other terminal. - Only ONE indicator instance's worth of state is kept per symbol - attaching it to two different charts on the same symbol at once means whichever one deinitialises last overwrites the other's saved file for that symbol. - Leaving InpObjectPrefixFilter blank tracks every object on the chart, including drawings created by other tools. Only the OBJPROP_TIMEFRAMES visibility flag is ever changed - objects are never created, moved or deleted by this indicator - but if you want it to only ever touch your own manual drawings or one specific tool's objects, set the prefix filter to match their naming convention. - Scroll restore depends on the target symbol's history already covering the saved time. On a symbol whose local history does not reach back that far (freshly added to Market Watch, thin broker history), the retry window eventually gives up and the chart is left at whatever bar it opened on, rather than restoring an unreachable position. - Zoom level (CHART_SCALE) is a whole-chart property; MetaTrader itself does not reset it automatically on a symbol change in most cases, so this indicator's zoom restore is mainly a safety net for the cases where it does get reset (e.g. after certain template or profile loads). - GlobalVariables are not used for this tool's storage - state needs to hold text (object names), which GlobalVariableSet cannot store (its values are always numeric), so a small CSV file per symbol is used instead.

Indicator · MT5 · v1.0 · Free

About Per Symbol View State Saver

Per Symbol View State Saver is an indicator for MetaTrader 5. It has 8 settings, such as Track zoom, Track scroll and Track object visibility. MQL source code included.

Files in the download: PerSymbolViewStateSaver.ex5, PerSymbolViewStateSaver.mq5, PerSymbolViewStateSaver.txt.

Settings

SettingDefaultWhat it does
Track zoomtrueSave/restore the chart zoom level (CHART_SCALE)
Track scrolltrueSave/restore the leftmost visible bar
Track object visibilitytrueSave/restore chart-object show/hide state
Object prefix filterOnly track objects whose name starts with this (blank = track every object)
Max objects200Safety cap on objects tracked per symbol
Save interval seconds15Periodic safety save, in addition to save-on-symbol-change
Restore retry seconds1Seconds between restore retries while history/objects are still loading
Restore retry limit10Give up restoring scroll position after this many retries

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Indicators.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: MT5 Indicator · MQL5 Source Code

MetaTrader 4 & 5 indicators · PolyMaria