Skip to content
← Back to the research library
MQL5 SOURCE COLLECTION / Breakout

Intraday Volatility Breakout · v2

An expanded volatility-breakout variant with London/New York windows and an optional synthetic-volatility filter.

MT5 / MQL5Original sourceDependency required

H4 levels / session filters · Published 28 October 2026

Source inspectionLimited static review
MetaEditor compilationNot performed
Backtest / live recordNot supplied

How the source is structured

  1. Calculate breakout bands around the current H4 open using the previous H4 ATR.
  2. Check M1 opening-price crosses and enabled trend, session, gap-bias and volatility filters.
  3. Use ATR stops and a timed close; the default session selection is New York.

Default inputs

As supplied; these are not optimized or recommended settings.
ATR period / timeframe7 / H4
Breakout / stop multipliers1.2 / 0.6
Risk input / daily entry cap1% / 1
New York / London filtersOn / Off
Synthetic VIX filter / maximumOn / 5.0
Close hour / test broker offset22:00 server time / GMT+2
BEFORE YOU TEST

Source-review notes

These observations come from reading this uploaded version. They are not compiler output or a complete code audit. The download retains the source as supplied.

SOURCE LINES 88–95

The enabled-by-default VIX filter requires Synthetic_VIX. The source returns initialization failure when that indicator cannot be loaded.

SOURCE LINES 139–149

Session windows are fixed GMT hours and the test broker offset is an input. Daylight-saving changes are not modeled by these fixed windows.

SOURCE LINES 125, 291–305

OnTick ignores the indicator-update failure result. No performance evidence was included with this variant.

Dependencies

Synthetic_VIX custom indicator is referenced and was not supplied. Built-in ATR and SMA are also used.

Source & attribution

Source copyright: Tatiana Zyrianova. Header version: 1.10. Original author notices are retained. Link from original header ↗

Included in the Edge Quant source collection with existing notices preserved. Free download does not imply a new license grant.

Original filename: Intraday Volatility Breakout v.2.mq5
Encoding: UTF-16

Inspect the original source

The browser preview is decoded for reading; the download keeps the original file bytes.

Direct .mq5 file ↓
Expand full MQL5 source · 371 lines
//+------------------------------------------------------------------+//|                             Intraday Volatility Breakout v.2.mq5 |//|                                                Tatiana Zyrianova |//|                        https://www.mql5.com/en/users/mqldiligent |//+------------------------------------------------------------------+#property copyright "Tatiana Zyrianova"#property link      "https://www.mql5.com/en/users/mqldiligent"#property version   "1.10"// ---#include <Trade\AccountInfo.mqh>#include <Trade\SymbolInfo.mqh>#include <Trade\PositionInfo.mqh>#include <Trade\Trade.mqh>CAccountInfo   acc;CSymbolInfo    smb;CPositionInfo  psn;CTrade         trd;// ---input ENUM_TIMEFRAMES      Timeframe            = PERIOD_H4;   // Timeframeinput int                  ATRPeriod            = 7;           // ATR periodinput double               BreakoutMult         = 1.2;         // Breakout multiplierinput double               SLMult               = 0.6;         // SL multiplierinput double               FixLotSize           = 0.01;        // Fixed lot sizeinput double               RiskPerc             = 1.0;         // Risk % (0-disabled)input int                  MaxTrdPerDay         = 1;           // Maximum trades per dayinput int                  ClsHour              = 22;          // Position closing hour (broker time)input bool                 TradeLondonSession   = false;       // Trade London (08:00–17:00 GMT)input bool                 TradeNewYorkSession  = true;        // Trade NY (13:00–22:00 GMT)input bool                 OvernightGapBias     = false;       // Overnight gap biasinput bool                 ElevatedVolFilt      = false;       // Elevated volatility filterinput bool                 VIXatOpenFilt        = true;        // VIX at Open Filterinput double               MaxVixVal            = 5.0;         // Max VIX valueinput bool                 TrendFilt            = true;        // Trend filterinput int                  MAPeriod             = 50;          // SMA periodinput int                  Magic                = 18036;       // Magic numberinput int                  BrokerGMT            = 2;           // Broker GMT (for testing)// ---ulong ord_ticket;int NmbBuy, NmbSell;double SL, Lot;datetime LastTimeInd, LastTime;bool Testing, Optimization;int ATR_h, MA_h, VIX_h;double ATR_Val[], MA_Val[], VIX_Val[];//+------------------------------------------------------------------+//| Expert initialization function                                   |//+------------------------------------------------------------------+int OnInit(){   // ---   if (Timeframe == PERIOD_H6 || Timeframe == PERIOD_H8) return(INIT_PARAMETERS_INCORRECT);      // ---   if (!smb.Name(_Symbol)) return(INIT_FAILED);   smb.Refresh();      // ---   trd.SetExpertMagicNumber(Magic);      // ---   Testing = MQLInfoInteger(MQL_TESTER);   Optimization = MQLInfoInteger(MQL_OPTIMIZATION);   LastTimeInd = iTime(smb.Name(), Timeframe, 1);      // ---   ATR_h = iATR(smb.Name(), Timeframe, ATRPeriod);   if (ATR_h == INVALID_HANDLE)   {      Print("Error creating ATR handle!");      return(INIT_FAILED);   }      if (TrendFilt && MAPeriod > 0)   {      MA_h = iMA(smb.Name(), Timeframe, MAPeriod, 0, MODE_SMA, PRICE_CLOSE);      if (MA_h == INVALID_HANDLE)      {         Print("Error creating MA handle!");         return(INIT_FAILED);      }   }      if (VIXatOpenFilt)   {      VIX_h = iCustom(smb.Name(), Timeframe, "Synthetic_VIX");      if (VIX_h == INVALID_HANDLE)      {         Print("Error creating VIX handle!");         return(INIT_FAILED);      }   }      // ---   ArraySetAsSeries(ATR_Val, true);   ArraySetAsSeries(MA_Val, true);   ArraySetAsSeries(VIX_Val, true);      return(INIT_SUCCEEDED);}//+------------------------------------------------------------------+//| Expert deinitialization function                                 |//+------------------------------------------------------------------+void OnDeinit(const int reason){   // ---   IndicatorRelease(ATR_h);   if (TrendFilt && MAPeriod > 0) IndicatorRelease(MA_h);   if (VIXatOpenFilt) IndicatorRelease(VIX_h);}//+------------------------------------------------------------------+//| Expert tick function                                             |//+------------------------------------------------------------------+void OnTick(){   // ---   smb.RefreshRates();   CountTrades();      // ---   UpdatingIndVal();   datetime CurrTime = TimeCurrent();      // ---   if (NmbBuy+NmbSell > 0)   {      datetime ClsTime = StartDayByTime(CurrTime)+ClsHour*3600;      CloseAllPos(smb.Name(), Magic, WRONG_VALUE, ClsTime);      CountTrades();   }      // ---   if (NmbBuy+NmbSell == 0)   {      datetime CurrTimeGMT = TimeGMT();      if (Testing) CurrTimeGMT = CurrTimeGMT-BrokerGMT*3600;      datetime StartDayGMT = StartDayByTime(CurrTimeGMT);            datetime StartTimeLondon = StartDayGMT+8*3600;      datetime EndTimeLondon   = StartDayGMT+17*3600;            datetime StartTimeNY = StartDayGMT+13*3600;      datetime EndTimeNY   = StartDayGMT+22*3600;            if ((!TradeLondonSession && !TradeNewYorkSession) || (TradeLondonSession && TimeCheck(CurrTimeGMT, StartTimeLondon, EndTimeLondon)) || (TradeNewYorkSession && TimeCheck(CurrTimeGMT, StartTimeNY, EndTimeNY)))      {         if (LastTime == 0 || iBarShift(smb.Name(), PERIOD_M1, LastTime) > 0)         {            if (NmbHistDayTrd(StartDayByTime(CurrTime)) < MaxTrdPerDay)            {               double Open0 = iOpen(smb.Name(), Timeframe, 0);               double DnLvl = Open0 - ATR_Val[1]*BreakoutMult;               double UpLvl = Open0 + ATR_Val[1]*BreakoutMult;                              if (SignalBuy(UpLvl))               {                  SL = NormalizeDouble(smb.Ask()-ATR_Val[1]*SLMult, smb.Digits());                                    if (RiskPerc <= 0) Lot = NL(FixLotSize);                  else Lot = NL(GetLot(acc.Balance(), RiskPerc, int((smb.Ask()-SL)/smb.Point())));                  if (CheckMoneyForTrade(ORDER_TYPE_BUY, Lot, smb.Ask()))                  {                     if (trd.Buy(Lot, smb.Name(), smb.Ask(), SL, 0))                     {                        ord_ticket = trd.ResultOrder();                        if (ord_ticket > 0)                        {                           NmbBuy++;                           LastTime = TimeCurrent();                        }                        else Print("Error #"+IntegerToString(GetLastError())+" occurred while opening an order.");                     }                     else Print("Error #"+IntegerToString(GetLastError())+" occurred while opening an order.");                  }                  else Print("Not enough funds to open an order with a lot size of "+DoubleToString(Lot, 2)+".");               }               if (SignalSell(DnLvl))               {                  SL = NormalizeDouble(smb.Bid()+ATR_Val[1]*SLMult, smb.Digits());                                    if (RiskPerc <= 0) Lot = NL(FixLotSize);                  else Lot = NL(GetLot(acc.Balance(), RiskPerc, int((SL-smb.Bid())/smb.Point())));                  if (CheckMoneyForTrade(ORDER_TYPE_SELL, Lot, smb.Bid()))                  {                     if (trd.Sell(Lot, smb.Name(), smb.Bid(), SL, 0))                     {                        ord_ticket = trd.ResultOrder();                        if (ord_ticket > 0)                        {                           NmbSell++;                           LastTime = TimeCurrent();                        }                        else Print("Error #"+IntegerToString(GetLastError())+" occurred while opening an order.");                     }                     else Print("Error #"+IntegerToString(GetLastError())+" occurred while opening an order.");                  }                  else Print("Not enough funds to open an order with a lot size of "+DoubleToString(Lot, 2)+".");               }            }         }      }   }}//+------------------------------------------------------------------+void CountTrades(){   NmbBuy = 0; NmbSell = 0;   for (int i=PositionsTotal()-1; i>=0; i--)   {      if (psn.SelectByIndex(i) && psn.Symbol() == smb.Name() && psn.Magic() == Magic)      {         if (psn.PositionType() == POSITION_TYPE_BUY)  NmbBuy++;         if (psn.PositionType() == POSITION_TYPE_SELL) NmbSell++;      }   }}//+------------------------------------------------------------------+void CloseAllPos(string symbol = "", int magic = -1, ENUM_POSITION_TYPE pos_type = WRONG_VALUE, datetime clstime = 0){   datetime CurrTime = TimeCurrent();   for (int i=PositionsTotal()-1; i>=0; i--)   {      if (psn.SelectByIndex(i) && (symbol == "" || psn.Symbol() == symbol) && (magic == -1 || psn.Magic() == magic) && (pos_type == WRONG_VALUE || psn.PositionType() == pos_type))      {         if (clstime == 0 || (CurrTime >= clstime && psn.Time() < clstime) || iBarShift(smb.Name(), PERIOD_D1, psn.Time()) > 0)         {            trd.PositionClose(psn.Ticket());         }      }   }}//+------------------------------------------------------------------+bool SignalBuy(double lvl){   if (iOpen(smb.Name(), PERIOD_M1, 0) >= lvl && iOpen(smb.Name(), PERIOD_M1, 1) < lvl)   {      if (!TrendFilt || MAPeriod <= 0 || smb.Bid() >= MA_Val[1])      {         if (!OvernightGapBias || iOpen(smb.Name(), PERIOD_D1, 0) >= iClose(smb.Name(), PERIOD_D1, 1))         {            double prev_day_size = iHigh(smb.Name(), Timeframe, 1)-iLow(smb.Name(), Timeframe, 1);            if (!ElevatedVolFilt || prev_day_size > ATR_Val[1])            {               if (VIXatOpenFilt)               {                  if (CopyBuffer(VIX_h, 0, 0, 2, VIX_Val) != 2 || ArraySize(VIX_Val) != 2)                  {                     Print("Error receiving data from the VIX indicator.");                     return(false);                  }               }               if (!VIXatOpenFilt || VIX_Val[0] < MaxVixVal) return(true);            }         }      }   }   return(false);}//+------------------------------------------------------------------+bool SignalSell(double lvl){   if (iOpen(smb.Name(), PERIOD_M1, 0) <= lvl && iOpen(smb.Name(), PERIOD_M1, 1) > lvl)   {      if (!TrendFilt || MAPeriod <= 0 || smb.Bid() <= MA_Val[1])      {         if (!OvernightGapBias || iOpen(smb.Name(), PERIOD_D1, 0) <= iClose(smb.Name(), PERIOD_D1, 1))         {            double prev_day_size = iHigh(smb.Name(), Timeframe, 1)-iLow(smb.Name(), Timeframe, 1);            if (!ElevatedVolFilt || prev_day_size > ATR_Val[1])            {               if (VIXatOpenFilt)               {                  if (CopyBuffer(VIX_h, 0, 0, 2, VIX_Val) != 2 || ArraySize(VIX_Val) != 2)                  {                     Print("Error receiving data from the VIX indicator.");                     return(false);                  }               }               if (!VIXatOpenFilt || VIX_Val[0] < MaxVixVal) return(true);            }         }      }   }   return(false);}//+------------------------------------------------------------------+bool UpdatingIndVal(){   if (LastTimeInd == 0 || iBarShift(smb.Name(), Timeframe, LastTimeInd) > 0)   {      int buff_size = 2;      if (CopyBuffer(ATR_h, 0, 0, buff_size, ATR_Val) != buff_size || ArraySize(ATR_Val) != buff_size) return(false);      if (TrendFilt && MAPeriod > 0)      {         if (CopyBuffer(MA_h, 0, 0, buff_size, MA_Val) != buff_size || ArraySize(MA_Val) != buff_size) return(false);      }            LastTimeInd = TimeCurrent();   }      return(true);}//+------------------------------------------------------------------+double NL(double lot){   return(MathMin(MathMax(MathRound(lot/smb.LotsStep())*smb.LotsStep(),smb.LotsMin()),smb.LotsMax()));}//+------------------------------------------------------------------+double GetLot(double free, double risk, int sl = 0){   if (sl <= 0 || smb.TickValue() <= 0) return(free/1000*smb.LotsMin()*risk);   return((free*risk/100)/(sl*(smb.Point()*smb.TickValue()/smb.TickSize())));}//+------------------------------------------------------------------+bool CheckMoneyForTrade(ENUM_ORDER_TYPE type,double volume,double price){   double margin = 0;   double marginFree = acc.FreeMargin();      if (!OrderCalcMargin(type,smb.Name(),volume,price,margin))      return false;      if (margin > marginFree)      return false;      return true;}//+------------------------------------------------------------------+int NmbHistDayTrd(datetime daystarttime){   int nmb = 0;   ulong deal_ticket = 0;      HistorySelect(daystarttime,TimeCurrent());      int total = HistoryDealsTotal();   for (int i=0; i<total; i++)   {      if ((deal_ticket=HistoryDealGetTicket(i)) == 0) continue;            long deal_type = HistoryDealGetInteger(deal_ticket,DEAL_TYPE);      if (deal_type != DEAL_TYPE_BUY && deal_type != DEAL_TYPE_SELL) continue;            string deal_symbol = HistoryDealGetString(deal_ticket, DEAL_SYMBOL);      long deal_entry = HistoryDealGetInteger(deal_ticket, DEAL_ENTRY);      long deal_magic = HistoryDealGetInteger(deal_ticket, DEAL_MAGIC);            if (deal_symbol == smb.Name() && deal_magic == Magic && deal_entry == DEAL_ENTRY_IN) nmb++;   }      return(nmb);}//+------------------------------------------------------------------+datetime StartDayByTime(datetime currtime){   datetime StartTime = 0;   MqlDateTime str1;   if (TimeToStruct(currtime, str1)) StartTime = currtime-(str1.hour*3600+str1.min*60+str1.sec);   return(StartTime);}//+------------------------------------------------------------------+bool TimeCheck(datetime currtime, datetime starttime, datetime stoptime){   if ((starttime < stoptime && currtime >= starttime && currtime < stoptime) || (starttime >= stoptime && (currtime >= starttime || currtime < stoptime))) return(true);   return(false);}//+------------------------------------------------------------------+

SHA-256: 2966a5269b9f32c17337205e1288b72b15a9c821300ecd2bcd2d2b244c1b6464

Educational source material, not investment advice. No profitability, execution quality or live-readiness claim is made for this upload.