#
.SYNOPSIS
Optimizes MetaTrader 5 template files (.tpl) by removing static objects.
.DESCRIPTION
When saving a template in MT5, all graphical objects (arrows, lines, boxes) are saved into the file.
This script removes all blocks to reduce file size and prevent "ghost" objects.
It also compacts excessive empty lines while preserving readability.
The script creates a new file with the '_mod.tpl' suffix for safety.
.PARAMETER Path
The file path(s) or folder path(s) to process.
Default is ".\MyTemplates".
Accepts multiple values (comma-separated).
.EXAMPLE
.\Clean-MT5Templates.ps1
Processes all .tpl files in the .\MyTemplates folder.
.EXAMPLE
.\Clean-MT5Templates.ps1 -Path "C:\MT5\Profiles\Templates\Strategy.tpl"
Processes a single file.
.EXAMPLE
.\Clean-MT5Templates.ps1 -Path "C:\Templates", "D:\Backup\Old.tpl"
Processes a folder and a specific file.
#>
param (
[string[]]$Path = @(".\MyTemplates")
)
function Remove-TplObjects {
param ([string]$FilePath)
try {
# Read all text
$content = [System.IO.File]::ReadAllText($FilePath)
# 1. Remove