Loading…

Ask Side Candle Store

Open[], High[], Low[], Close[] and every iOpen/iHigh/iLow/iClose call in MQL4 read bid-side history, always. That is fine for a sell-side study, but a buy order fills against the ASK, not the bid, and the spread between them is not constant - it widens around news releases and thins in quiet hours, and differs completely between a raw ECN feed and a fixed-spread retail feed. Any study of buy-side triggers computed against bid bars is subtly wrong: a buy-stop resting above the market, a buy-limit fill check, "did price genuinely reach the level this pending buy sits at" - the bid bar's high can sit comfortably below a level that the ask side genuinely traded through during a spread spike, and a bid-only backtest will silently record that buy-stop as never triggered when it really would have filled. This header fixes that by building real ask-side OHLC bars from ticks directly, independently of the terminal's own bid-only bar history. The caller registers one or more (symbol, period) series, then feeds each tick in - as an explicit ask price, or as bid+spread through the convenience wrapper - and the store accumulates open/high/low/close correctly, opening a new bar exactly when the tick's time crosses into a new period-aligned bucket (the same time%period bucketing convention MQL4's own bar history uses, so an ask-side bar's open time lines up with the bid-side bar covering the same window). Update() takes the tick's time and price explicitly rather than reading the predefined Ask/Bid variables itself - that keeps the store usable from a live OnTick handler, from a Script replaying a recorded tick history, or from synthetic test data, without hard-wiring it to only ever run inside a live EA's tick loop. Notes and limitations - This is a from-ticks accumulator, not a historical reconstruction. It only knows about bars built from ticks fed into it after RegisterSeries() was called - it cannot retroactively build ask-side history for a period before the EA/script started running, because MQL4 keeps no tick history with spread information built in. - UpdateFromBidSpread expects spreadInPrice in raw price units already converted from points (MarketInfo(symbol, MODE_SPREAD) * MarketInfo(symbol, MODE_POINT), or simply Ask - Bid on a live chart) - passing a raw points value produces bars with an implausibly tiny spread. - Bar rollover is driven purely by tick timing crossing a period boundary. If ticks stop arriving for longer than one period (a quiet market, a disconnected feed), no empty bar is synthesised for the gap - the next tick simply opens the bar for whichever period bucket it actually falls into, leaving a gap in openTime rather than a flat placeholder bar. This matches how MQL4's own bid-side history behaves during a genuine tick gap. - GetBar's shift indexing is a simple series-index into the stored array; it is not resynchronised against wall-clock "now" the way the terminal's own Bars/shift indexing is - if ticks stop arriving, shift 0 is simply the last bar that was actually built, however long ago that was.

Script · MT5 · v1.0 · Free

About Ask Side Candle Store

Ask Side Candle Store is a script for MetaTrader 5. It has 1 setting, such as Symbol. MQL source code included.

Files in the download: AskSideCandleStore.mq5.mqh, AskSideCandleStore.txt, AskSideCandleStoreDemo.ex5, AskSideCandleStoreDemo.mq5.

Settings

SettingDefaultWhat it does
SymbolEURUSD

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: News Trading · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria