Second(s) timeframes on your MT5

ALkhalil78

Trader
Jan 5, 2026
11
3
9
48
this script converts the chart's ticks into any Second(s)timeframes !!!

the Script works only for XAUUSD, you can modify it to work with other pairs or other names of Gold pair.

Example custom periods:

S5
S10
S15
S20
S30
S45
S50

Once the Second(s) chart is generated, you can apply almost everything you normally use on regular charts:

✅ Templates ( .tpl )
✅ Indicators
✅ Expert Advisors
✅ Objects & drawings
✅ Trendlines
✅ Fibonacci tools
✅ Moving averages
✅ Oscillators
✅ Custom indicators
✅ Price action tools



Enjoy the Script !!

MQL5:
//+------------------------------------------------------------------+
//|                                              GoldSecondsMT5.mq5  |
//|                     MT5 Native Seconds Chart Generator            |
//|                     Custom Symbol Engine Version                  |
//+------------------------------------------------------------------+
#property strict
 
input string InpSourceSymbol = "XAUUSD";
input int    InpSeconds      = 10;
input bool   InpAutoOpen     = true;
 
string CustomSymbolName;
 
MqlRates CurrentBar;
 
datetime CurrentBarTime = 0;
 
long LastTickTimeMSC = 0;
 
//+------------------------------------------------------------------+
//| Expert initialization                                            |
//+------------------------------------------------------------------+
int OnInit()
{
   if(InpSeconds < 1)
   {
      Print("Seconds must be >= 1");
      return(INIT_FAILED);
   }
 
   CustomSymbolName = InpSourceSymbol + "_S" + IntegerToString(InpSeconds);
 
   Print("Creating custom symbol: ", CustomSymbolName);
 
   CreateCustomSymbol();
 
   OpenCustomChart();
 
   EventSetMillisecondTimer(50);
 
   return(INIT_SUCCEEDED);
}
 
//+------------------------------------------------------------------+
//| Expert deinitialization                                          |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   EventKillTimer();
}
 
//+------------------------------------------------------------------+
//| Millisecond timer                                                |
//+------------------------------------------------------------------+
void OnTimer()
{
   MqlTick tick;
 
   if(!SymbolInfoTick(InpSourceSymbol, tick))
      return;
 
   if(tick.time_msc == LastTickTimeMSC)
      return;
 
   LastTickTimeMSC = tick.time_msc;
 
   ProcessTick(tick);
}
 
//+------------------------------------------------------------------+
//| Process incoming tick                                            |
//+------------------------------------------------------------------+
void ProcessTick(MqlTick &tick)
{
   datetime bar_time =
      (datetime)((tick.time / InpSeconds) * InpSeconds);
 
   //--- First bar
   if(CurrentBarTime == 0)
   {
      StartNewBar(bar_time, tick);
      return;
   }
 
   //--- New candle
   if(bar_time > CurrentBarTime)
   {
      PushBarToCustomSymbol(CurrentBar);
 
      StartNewBar(bar_time, tick);
   }
   else
   {
      UpdateCurrentBar(tick);
   }
}
 
//+------------------------------------------------------------------+
//| Start new candle                                                 |
//+------------------------------------------------------------------+
void StartNewBar(datetime bar_time, MqlTick &tick)
{
   CurrentBarTime = bar_time;
 
   CurrentBar.time        = bar_time;
   CurrentBar.open        = tick.bid;
   CurrentBar.high        = tick.bid;
   CurrentBar.low         = tick.bid;
   CurrentBar.close       = tick.bid;
   CurrentBar.tick_volume = 1;
   CurrentBar.spread      = 0;
   CurrentBar.real_volume = 0;
}
 
//+------------------------------------------------------------------+
//| Update current candle                                            |
//+------------------------------------------------------------------+
void UpdateCurrentBar(MqlTick &tick)
{
   if(tick.bid > CurrentBar.high)
      CurrentBar.high = tick.bid;
 
   if(tick.bid < CurrentBar.low)
      CurrentBar.low = tick.bid;
 
   CurrentBar.close = tick.bid;
 
   CurrentBar.tick_volume++;
}
 
//+------------------------------------------------------------------+
//| Push candle to custom symbol                                     |
//+------------------------------------------------------------------+
void PushBarToCustomSymbol(MqlRates &bar)
{
   MqlRates rates[1];
 
   rates[0] = bar;
 
   if(!CustomRatesUpdate(CustomSymbolName, rates))
   {
      Print("CustomRatesUpdate failed. Error: ", GetLastError());
   }
}
 
//+------------------------------------------------------------------+
//| Create custom symbol                                             |
//+------------------------------------------------------------------+
void CreateCustomSymbol()
{
   //--- already exists
   if(SymbolSelect(CustomSymbolName, true))
   {
      Print("Custom symbol already exists.");
      return;
   }
 
   //--- create
   if(!CustomSymbolCreate(
      CustomSymbolName,
      "Custom",
      InpSourceSymbol))
   {
      Print("Failed creating custom symbol. Error: ", GetLastError());
      return;
   }
 
   //--- select
   SymbolSelect(CustomSymbolName, true);
 
   //--- synchronize properties
   CustomSymbolSetInteger(
      CustomSymbolName,
      SYMBOL_DIGITS,
      (int)SymbolInfoInteger(InpSourceSymbol, SYMBOL_DIGITS)
   );
 
   CustomSymbolSetDouble(
      CustomSymbolName,
      SYMBOL_POINT,
      SymbolInfoDouble(InpSourceSymbol, SYMBOL_POINT)
   );
 
   Print("Custom symbol created successfully.");
}
 
//+------------------------------------------------------------------+
//| Open custom chart                                                |
//+------------------------------------------------------------------+
void OpenCustomChart()
{
   if(!InpAutoOpen)
      return;
 
   long chart_id = ChartOpen(CustomSymbolName, PERIOD_M1);
 
   if(chart_id > 0)
   {
      Print("Custom chart opened.");
   }
   else
   {
      Print("Failed opening chart.");
   }
}
//+------------------------------------------------------------------+
 
Last edited by a moderator:
  • 👍
Reactions: Enivid
Could you modify this source code so it works for all instruments? For instance, I currently trade Gold, but the symbol is XAUUSDz rather than XAUUSD (without the 'z' suffix), and I am unable to open a chart with a one-second timeframe. If possible, please create versions for both MT4 and MT5.
 
Could you modify this source code so it works for all instruments? For instance, I currently trade Gold, but the symbol is XAUUSDz rather than XAUUSD (without the 'z' suffix), and I am unable to open a chart with a one-second timeframe. If possible, please create versions for both MT4 and MT5.
You can change the symbol name via input parameters. And the MT4 version can be found here: