Market Watch Cleaner
Download scriptIf you have ever felt overwhelmed by a cluttered trading platform filled with dozens of currency pairs, commodities, and indices—many of which you don't trade or are currently too expensive to enter—this script is designed to streamline your workspace. It acts as an automated housekeeping tool for your Market Watch window, filtering out the noise so you can focus only on the most viable opportunities.
How the Script Works
The script follows a logical three-step process to clean up your interface:
1. Universal Visibility First, the script begins by making every available instrument visible in your Market Watch. This ensures that it has a complete overview of everything provided by your broker before it starts the cleaning process.
2. Filtering Out Non-Tradable Assets Next, it scans your entire list to identify assets that are not currently open for trading (for example, instruments restricted by your account type or those currently closed by the broker). It automatically hides these from your view, ensuring that you only see symbols where you actually have the ability to execute a trade.
3. Filtering by Cost Efficiency (Spread Control) The final and most practical step is the "Spread Filter." Every financial instrument has a "spread"—the difference between the buy and sell price. High spreads can make trading expensive or unprofitable.
- You can set a specific maximum spread limit (for example, 20).
- The script checks every remaining tradable instrument against this limit.
- If an instrument’s spread is higher than your chosen number, the script hides it from your view.
The Final Result
Once the script finishes running, your Market Watch is transformed into a curated list. It will only display:
- Instruments that are actually tradable on your account.
- Instruments that fall within your preferred price-efficiency range.
At the end of the process, the tool provides a summary report in the log, telling you exactly how many items were kept visible, how many were hidden because they aren't tradable, and how many were removed due to high costs. This allows for a much cleaner, more professional trading environment where your most relevant options are always front and center.
//+------------------------------------------------------------------+
//| MarketWatchCleaner.mq4 |
//| Jay Davis |
//| https://www.tidyneat.com |
//+------------------------------------------------------------------+
#property copyright "Link to Jay Davis' profile."
#property link "https://www.mql5.com/en/users/johnthe"
#property version "1.00"
#property description "This script removes all instruments with spread higher than the specified maximum requested and it also removes all non-trade enabled instruments from Market Watch, which allows you to concentrate on items you may want to trade without all the clutter."
#property strict
#property script_show_inputs
//--- input parameters
input int MaximumSpread=20;//Max spread to in show Market Watch.
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
ShowAllInstrumentsInMarketWatch(TotalInstruments());
RemoveUnTradableInstruments();
RemoveHighSpreadInstruments();
Print("Market Watch now contains ", VisibleInstruments(), " visible elements, ",
TotalTradableInstruments() - VisibleInstruments(), " tradable hidden elements, and ",
TotalInstruments() - TotalTradableInstruments(), " elements where trade is not allowed." );
Print("Thanks for using my script", " \nhttps://www.mql5.com/en/users/johnthe");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ShowAllInstrumentsInMarketWatch(int totalInstruments)
{
for(int i=0; i<=totalInstruments; i++)
{
SymbolSelect(SymbolName(i,false),true);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int TotalInstruments()
{
return SymbolsTotal(false)-1;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int VisibleInstruments()
{
return SymbolsTotal(true)-1;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int TotalTradableInstruments()
{
int count = 0;
for(int i=0; i<=TotalInstruments(); i++)
{
ENUM_SYMBOL_TRADE_MODE
mode=(ENUM_SYMBOL_TRADE_MODE)
SymbolInfoInteger(SymbolName(i,false),SYMBOL_TRADE_MODE);
if((mode == SYMBOL_TRADE_MODE_FULL))
{
count++;
}
}
return count;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void RemoveUnTradableInstruments()
{
for(int i=0; i<=TotalInstruments(); i++)
{
ENUM_SYMBOL_TRADE_MODE
mode=(ENUM_SYMBOL_TRADE_MODE)
SymbolInfoInteger(SymbolName(i,false),SYMBOL_TRADE_MODE);
if((mode != SYMBOL_TRADE_MODE_FULL))
{
SymbolSelect(SymbolName(i,false),false);
Print("Removed ",SymbolName(i,false)," ",
EnumToString(mode));
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void RemoveHighSpreadInstruments()
{
for(int i=0; i<=TotalInstruments(); i++)
{
long spread=SymbolInfoInteger(SymbolName(i,false),SYMBOL_SPREAD);
if(spread>MaximumSpread)
{
if(SymbolSelect(SymbolName(i,false),false))
{
Print("Removed ",SymbolName(i,false)," with high spread of ",spread);
}
else
{
Print("Failed to remove ",SymbolName(i,false));
Sleep(100);
Print("RefreshingRates ...",RefreshRates());
if(SymbolSelect(SymbolName(i,false),false))
{
Print("Successfully Removed ",SymbolName(i,false)," with high spread of ",spread);
}else {
Print("Failed again after rates refresh, Please apply to a different chart!");
}
}
}
}
}
//+------------------------------------------------------------------+
Comments