A spread filter needs a threshold, and most people guess it. The Market Watch spread you see while writing code is the daytime spread. The spread at rollover, before major news, or in the thin hour after the US close can be several times wider. A short script that reads the tick history and groups the spread by hour of day gives you real numbers to put into the filter and into the tester settings.
What the script does
Reads the most recent bid and ask changes with CopyTicks and COPY_TICKS_INFO. Passing 0 as the start time asks for the latest ticks, so no date math is needed.
Converts each tick's spread to points.
Groups the ticks by hour in broker server time and prints the tick count, average spread and maximum spread for each hour.
The script
#property script_show_inputs
input int MaxTicks = 1000000; // most recent ticks to read
void OnStart() { MqlTick ticks[]; // from = 0 means "the most recent MaxTicks ticks" int n = CopyTicks(_Symbol, ticks, COPY_TICKS_INFO, 0, MaxTicks); if(n <= 0) {…