Block reference
Each block behaves the same in the exported EA and in the Strategy Tester. Numeric settings can be linked to inputs. Distances are in pips: on 5- and 3-digit quotes one pip is 10 points.
The palette groups blocks by what you are trying to do, from When to enter to Advanced. Search it by name. Several palette entries are the same block with its settings filled in, listed under that block below.
Blocks that only make sense on a live chart (chart objects, buttons, files, e-mails, web requests, custom indicators and custom code) run in the exported EA; the Strategy Tester logs them instead.
When to enter
Condition (If A vs B)
Compares a left operand with a right one (an indicator, a price or a fixed value) on the chosen timeframe and bar shift. YES when the comparison holds, NO otherwise.
- Operators: greater/less than, greater/less or equal, equals.
- Crosses above: A was at or below B one bar earlier and is above it now. Crosses below is the mirror.
- Indicators: RSI, EMA, SMA, ATR and CCI (with their period); Bollinger bands (2.0 deviations); Envelopes (0.25%); Keltner lower band (EMA − 1.5 × ATR(14)); VWAP band; MACD main and signal (12, 26, 9); Stochastic %K (5, 3, 3). The Timeframe setting reads them on another timeframe.
- More indicators, grouped in the operand list: trend (SMMA, LWMA, DEMA, TEMA, AMA, VIDYA, FRAMA, Parabolic SAR, ADX with +DI/−DI and Wilder’s ADX, Alligator, Ichimoku, MACD histogram); oscillators (Stochastic signal, Momentum, Williams’ %R, DeMarker, RVI, Awesome and Accelerator oscillators, Bulls and Bears Power, TRIX); volatility (standard deviation); market structure (Donchian channel, pivot points with R1–R3 and S1–S3, Fibonacci retracements from 23.6% to 78.6%, Fractals, swing highs and lows); volume (MFI, OBV, Accumulation/Distribution, Chaikin oscillator, Force Index). Indicators MetaTrader 4 doesn’t have are calculated by the exported EA itself, the same way as in the backtest. Swing highs and lows are a ZigZag that never repaints: a point only counts once the bars after it confirm it.
- Volume: VWAP (session), the volume-weighted average of the typical price since midnight server time; Volume (ticks); and Volume average over the period. They read the last closed bar, because a bar’s volume is only known when it closes. The old Lower band (typical price) is a band, not a VWAP.
- Session levels: previous day high / low, previous week high / low (weeks start on Sunday) and Asian session high / low (today’s 00:00–08:00 server-time range once 08:00 has passed, before that the previous day’s). They read 0 until the history reaches them, for example on a backtest’s first day.
- Besides indicators and prices, an operand can be an account or market value (balance, equity, free margin, open profit, open positions, Ask, Bid, spread, hour, minute, weekday) or one of your variables.
Crossover (Above/Below)
Detects a cross between two lines on closed bars: YES on the bar where the left line crosses above (or below) the right one, NO on every other bar.
Indicator rising
Passes when the indicator went up on each of the last N closed bars (each value above the one before). Up to 10 bars.
Indicator falling
Passes when the indicator went down on each of the last N closed bars (each value below the one before). Up to 10 bars.
Indicator within range
Passes while the indicator, on the chosen bar shift, is between the minimum and the maximum (both included).
Bull / bear candle
Passes when the candle at the shift (1 = last closed) closed up (bull) or down (bear), with a body of at least the given pips.
Palette entries: Bull candle · Bear candle
Candles in a row
Passes when the last N closed candles all closed in the chosen direction.
Palette entries: Bulls in a row · Bears in a row
Candle pattern
Looks for a pattern on the last closed candle: pin bar (a wick of at least 60% of the range), doji (a body of at most 10% of the range), or, with the candle before it, engulfing, inside bar or outside bar.
Palette entries: Bullish pin bar · Bearish pin bar · Bullish engulfing · Bearish engulfing
Impulse candle
Passes when the last closed candle’s body, in the chosen direction, is the factor times the average body of the candles before it. Needs that many candles of history.
Palette entries: Impulse up · Impulse down
Fast move
Passes when the Bid has moved the given pips up (or down) within the last seconds. It keeps the Bid of each tick it runs on, so wire it where it runs on every tick.
Palette entries: Fast move up · Fast move down
New high / low
Passes when the Bid is above the highest high (or below the lowest low) of the last N closed bars.
Palette entries: New high · New low
Volume spike
Passes when the last closed bar’s tick volume is at least the factor (1.5×) times the average volume of the bars before it (20 by default). Useful to confirm a breakout or a crossover. Forex volume is tick volume: the number of price changes, not traded lots.
Opening range
Builds the range from a start time (08:00 server time by default) for a number of minutes (15), then passes when price breaks above its high, below its low, or stays inside it. A margin in pips filters false breaks, a maximum width skips wide ranges, and an until time stops the signal later in the day. It passes on every tick while true: add Once a day or Trades today for one trade per day.
Palette entries: Opening range breakout ↑ · Opening range breakout ↓ · Asian range breakout ↑ · Asian range breakout ↓ · London open breakout ↑ · London open breakout ↓ · New York open breakout ↑ · New York open breakout ↓
Opening gap
Compares today’s daily open with yesterday’s close. Pick the direction (up, down or both) and a minimum size in % or pips, with an optional maximum. Only gaps not yet filled stops once price comes back to yesterday’s close. Gaps mostly appear on markets that close each day (stocks, indices); 24-hour forex rarely gaps except after weekends.
Palette entries: Gap up · Gap down
Liquidity sweep
Passes when the last closed bar went beyond a level and closed back inside it: above the level and closed below it (High), or below it and closed above (Low). Levels: yesterday’s high or low, last week’s, the Asian session’s (00:00–08:00 server time) or the highest high / lowest low of the bars before it. ‘Min pips beyond’ ignores small pokes. Often used to fade stop hunts: a high swept, then sell.
Palette entries: Sweep of yesterday’s high · Sweep of yesterday’s low · Sweep of the Asian high · Sweep of the Asian low
Market structure
Finds swing highs and lows on closed bars (a swing high is higher than the ‘strength’ bars on each side) and passes on the bar that closes beyond the last one. A close above the last swing high is a break of structure up while the trend is up (or not set yet), and a change of character up when the trend was down. Breaks down mirror it. Checks the last ‘look back’ bars, once per closed bar.
Palette entries: Break of structure ↑ · Break of structure ↓ · Change of character ↑ · Change of character ↓
Fair value gap
A three-candle imbalance: bullish when the third candle’s low is above the first candle’s high, bearish when its high is below the first candle’s low. ‘Just formed’ passes on the bar after the gap appears. ‘Price back inside’ passes while the Bid is inside a gap from the last ‘max age’ bars that later bars haven’t filled.
Palette entries: Bullish fair value gap · Bearish fair value gap · Back in a bullish gap · Back in a bearish gap
Near a round number
Passes when the Bid is within the given pips of a round level: a multiple of the step, for example every 50 pips (1.1000, 1.1050…).
MACD divergence
Bullish: the last closed bar makes a lower low than the lowest low of the lookback while MACD (12, 26, 9) makes a higher low below zero. Bearish is the mirror image with highs above zero.
Palette entries: Bullish MACD divergence · Bearish MACD divergence
Custom indicator
Reads an indicator from MetaTrader’s Indicators folder with iCustom: give its file name, its inputs in order, and the buffer to read (0 = first line; see the indicator’s Data Window). Has a value suits arrow indicators. Third-party indicators can’t run in QuantForge’s backtester, so there this block always takes NO; test it in MetaTrader’s Strategy Tester.
Palette entries: Custom indicator arrow · Custom indicator lines cross
When trading is allowed
Once Per Bar
Passes on the first tick of each new bar of the chosen timeframe. Each block keeps its own bar, so two of them both fire.
Time / Session Filter
Passes from the start hour up to (not including) the end hour, server time. A start after the end (22 → 2) is a session across midnight.
Time window (hh:mm)
Passes from the start time up to (not including) the end time, server time. A start after the end (22:00 → 02:00) crosses midnight.
Minutes filter
Passes from the start minute up to (not including) the end minute of every hour, server time. A start after the end wraps around the hour.
Weekday filter
Passes only on the ticked days of the week, server time.
Day of month filter
Passes from the start day to the end day of the month (both included), server time. A start after the end wraps around the month end.
Months filter
Passes from the start month to the end month (1–12, both included). A start after the end wraps around the new year.
Once an hour
Passes on the first tick it is reached in each server hour, then takes NO for the rest of that hour.
Once a day
Passes on the first tick it is reached in each server day, then takes NO until the next day.
Once per N minutes
Passes on the first tick it is reached in each N-minute period of the server clock (:00, :15, :30, :45 for 15).
Every N ticks
Passes on the first tick it is reached, then on every Nth tick after that; NO on the ticks in between.
Every N bars
Passes on the first tick of the first bar it sees, then of every Nth bar of the chosen timeframe; NO otherwise.
Max Spread Filter
Passes while the current spread is at most the maximum, in points. Put it before entries to skip wide spreads around news and rollover.
Account type
Passes only on the chosen kind of account. The Strategy Tester counts as a demo account.
Palette entries: Demo account · Real account
Running in the tester
Passes when the EA runs in the Strategy Tester (in QuantForge or in MetaTrader), not on a live chart.
Terminal connected
Passes while the terminal is connected to the broker’s server. Always true in backtests.
What’s open
Check Open Trades Count
Passes while this EA has at most the given number of open positions in that direction (pending orders not counted).
Count positions & orders
Counts this EA’s open positions, pending orders or both, in one direction or both, and passes when the count compares as set (for example ≥ 1, or ≤ 0 for “nothing open”).
Palette entries: Has a position · No position · Has a pending order · No pending order · Has a position or order · No position or order
Nothing nearby
Passes when no position (or pending order) of this EA has its open price within the given pips of the current Bid. Use it to avoid stacking trades at the same level.
Basket profit
Adds up the open profit of this EA’s positions (with swap) in money, in pips, or as a % of the balance, and compares it with the value.
How it went
Losing / winning streak
Passes when the last N closed trades of this EA all lost (or all won), commission and swap included.
Palette entries: Losing streak · Winning streak
Last closed trade
Checks the last closed trade of this EA: was it a buy or a sell, did it win or lose, was it closed by its stop loss or take profit. False when no trade has closed yet.
Palette entries: Last trade lost · Last trade won · Last trade hit SL · Last trade hit TP
Profit check
Compares closed profit (with swap and commission) with a value: the last trade, today since midnight server time, this week since Monday, or the average per trade.
Palette entries: Profit today · Profit this week · Profit of the last trade · Average profit per trade
Trades today
Compares the number of positions this EA opened today (server time) with a number, for example at most 3 a day.
Open trades
Buy Now (Market Order)
Opens a buy at the market price. The lot is fixed or sized from the risk % and the stop loss; SL and TP are in pips from the entry (0 uses 30 and 60).
Sell Now (Market Order)
Opens a sell at the market price. The lot is fixed or sized from the risk % and the stop loss; SL and TP are in pips from the entry (0 uses 30 and 60).
Pending Buy/Sell Stop
Places a stop or limit order the offset away from the current price. SL/TP are measured from the entry; 0 minutes means no expiry.
Palette entries: Buy pending order · Sell pending order
Pending order grid
Places a row of pending orders: the first at the first offset from the price, each next one a step further. Stop orders sit beyond the price, limit orders before it. SL/TP are in pips from each entry.
Palette entries: Buy order grid · Sell order grid
Scale in
Opens a new market order in the same direction as the chosen position, with its volume × the factor, and optionally the same SL and TP.
Manage trades
Move to Break-Even
When an open position reaches the trigger profit, moves its stop loss to the entry plus the lock pips, so the trade can no longer turn into a loss. It never loosens a stop.
Trailing Stop
Once an open position is the start distance in profit, moves its stop loss to follow the price at the trail distance, in steps of at least the step size. It never loosens a stop.
Group trailing stop
Treats each side’s positions as one: once the price is the start distance beyond their volume-weighted average price, every position’s SL follows the price at the trail distance. It never loosens a stop.
Group profit lock
Once the total open profit has reached the start amount, closes the positions when the profit falls the given amount below its highest point.
Modify stops
Sets SL and/or TP of the chosen positions at a distance in pips from their open price, removes them, or keeps them. A level that the price has already passed is left unchanged.
Close Trades
Closes this EA’s open positions in the chosen direction. Pending orders are left alone.
Palette entries: Close buys · Close sells · Close profitable trades · Close losing trades · Close the most profitable trade · Close the least profitable trade
Close part of a trade
Closes the given % of each chosen position, rounded down to the lot step. If what would remain is below the minimum lot, the whole position is closed.
Basket take-profit / stop-loss
Closes all of this EA’s positions (in the chosen direction) when their total profit reaches the take-profit or their total loss reaches the stop-loss. 0 turns either one off.
Delete pending orders
Deletes this EA’s pending orders of the chosen kind.
Trail pending orders
Moves this EA’s pending orders so they stay the given distance from the price as it moves away, in steps of at least the step size. SL and TP move with the order.
Risk & money
Risk % Lot Calculator
Sizes the orders placed after it on the same tick: risk % of equity over each order’s stop loss (or the default when it has none), kept between the min and max lot.
Daily Drawdown Guard
Compares equity with the balance at the start of the server day. At the limit it closes everything (if set) and takes the NO branch until the next day.
Daily equity target
Passes until today’s equity is the target % above the balance at the start of the server day, then takes NO until tomorrow.
Max open lots
Passes while this EA’s open volume is below the maximum lots.
Martingale / Grid Multiplier
Passes when no trade is open (the next order uses its own lot) or when the newest trade is the step in loss and fewer than the max orders are open; the next order then uses that trade’s lot × multiplier.
Logic & flow
Pass / Connector
Does nothing and passes straight on. Use it to join several branches into one, or to tidy the wiring.
All of (AND)
Waits until the flow has arrived through every wire that leads into it during the same tick, then continues once.
Any of (OR)
Continues on the first arrival during a tick and ignores the others, so the blocks after it run once per tick.
Random path
Takes the YES output the given % of the time, chosen at random, otherwise NO. The backtest uses a fixed random sequence, so runs repeat.
Switch blocks on / off
Turns other blocks of this tab off, on, or toggles them, by their numbers (for example 3, 7). A block that is off is skipped, together with everything after it.
Palette entries: Turn blocks off · Turn blocks on · Toggle blocks
Stop the EA
Removes the EA from the chart, after closing its positions if you choose. In the tester its blocks stop running and open positions keep their SL/TP until the end.
Variables, flags & counters
Set variable
Sets a variable to a value, or adds, subtracts, multiplies or divides it. Variables are created in the Inputs & Constants tab and keep their value between ticks.
Palette entries: Increase variable · Decrease variable
Formula
Calculates A op B (+, −, ×, ÷, minimum or maximum) and stores the result in a variable. A and B can be indicators, prices, account values, time, variables or numbers. Division by 0 gives 0.
Check variable
Compares a left operand with a right one (an indicator, a price or a fixed value) on the chosen timeframe and bar shift. YES when the comparison holds, NO otherwise.
Set flag
Stores a text under a flag’s name, for example ON / OFF or a mode name, to check later with Check flag.
Palette entries: Flag on · Flag off
Check flag
Compares a named flag with a text (equal or different). A flag that was never set is empty.
Palette entries: Flag is on
Counter
Counts every time the flow reaches this block, under the counter’s name. It passes the first time only, the first N times, or from the Nth time on. Reset counter starts it again.
Palette entries: Pass once · Pass N times · Pass after N times
Reset counter
Sets the named counter back to 0.
Alerts & output
Send Alert / Push
Sends the message as a terminal alert, a push notification, both, or only to the log.
Palette entries: Phone notification
Send email
Sends an email with SendMail. Set up email in MetaTrader (Tools > Options > Email) first. {symbol}, {bid}, {ask}, {balance}, {equity} and {time} are filled in.
Play sound
Plays a .wav file from the terminal’s Sounds folder.
Chart comment
Shows the text in the top-left corner of the chart, with {symbol}, {bid}… filled in. Each Chart comment replaces the previous one.
Log message
Writes the text to the Experts log (Print), with {symbol}, {bid}… filled in.
Web request
Sends a request with WebRequest, for example to a Telegram, Discord or your own webhook. Allow the URL in Tools > Options > Expert Advisors. It does not run in the Strategy Tester.
Write to file
Writes the text as a new line to a file in the terminal’s Files folder (MQL4/Files or MQL5/Files), appending or replacing the file.
Upload file (FTP)
Uploads a file from the Files folder with SendFTP. Set up FTP in Tools > Options > FTP first.
Set terminal variable
Sets a global variable of the terminal, which every EA and script on this computer can read. Useful to coordinate several EAs.
Check terminal variable
Compares a global variable of the terminal with a value. A variable that doesn’t exist reads as 0.
Chart drawing
Draw Arrow
Draws one arrow per bar on the chart, below the low (up/buy) or above the high (down/sell).
Draw line
Draws one line per block, moved each time it runs: a horizontal line at the Bid plus the offset, or a vertical line at the current bar.
Palette entries: Horizontal line · Vertical line
Draw text
Writes a text label above the current bar, one per bar, with {symbol}, {bid}… filled in.
Draw box
Draws a rectangle from the highest high to the lowest low of the last N bars. One box per block, moved each time.
Draw Fibonacci
Draws Fibonacci levels from the highest high to the lowest low of the last N bars. One per block, moved each time.
Delete chart objects
Deletes the chart objects whose names start with the prefix. QuantForge’s drawings start with QF_.
Chart screenshot
Saves a PNG picture of the chart in the terminal’s Files folder.
Apply chart template
Applies a saved chart template (.tpl) from the terminal’s templates folder.
Advanced
For each trade
Runs the blocks wired to YES once for each of your open positions (or pending orders), one after the other. Blocks inside the loop with “in loop” in their name act on that one trade. When the loop is done, the blocks wired to NO run once.
Palette entries: For each position · For each buy · For each sell · For each pending order
Trade in loop is…
Inside a For each loop: YES when the trade the loop is on matches (buy, sell, in profit, in loss, has or has no stop loss / take profit), otherwise NO.
Palette entries: Trade in loop is in profit · Trade in loop is in loss
Trade in loop: value
Inside a For each loop: compares a value of the current trade (profit in pips or money, minutes since it opened, lots, distance to its stop loss or take profit) with a number.
Palette entries: Trade in loop is older than
Act on trade in loop
Inside a For each loop: acts on the current trade only. Break-even moves the stop to the entry plus the pips; Set stop loss / take profit measure the pips from the entry (or the order price); Trail keeps the stop the pips behind the price; Close part closes the percent.
Palette entries: Close trade in loop · Break-even trade in loop · Trail trade in loop · Delete order in loop
Break loop
Inside a For each loop: stops the loop after the current trade; the remaining trades are skipped this time.
For each chart object
Runs the blocks wired to YES once for each object on the chart whose name starts with the prefix (empty = any name) and that has the chosen type, such as the lines you drew by hand. Blocks with “object in loop” in their name work on that object. The blocks wired to NO run once after the loop. The backtester has no chart objects, so there only NO runs.
Palette entries: For each horizontal line · For each trendline
Price vs object in loop
Inside a For each chart object loop: compares the Bid with the object’s price: a horizontal line’s level, or a trendline’s value on the current bar. Crossed up: the last closed bar was at or below the line and the price is now above it.
Palette entries: Price crossed object up · Price crossed object down
Act on object in loop
Inside a For each chart object loop: deletes the object, changes its colour, or sets its text.
Palette entries: Delete object in loop
Chart button
Draws a button in the top-left corner of the chart (x, y in pixels). YES once after each click, otherwise NO. The EA checks it on each tick. In the backtester it is never clicked.
Chart edit field
Draws a box on the chart where the trader can type a number, and puts that number into the variable each time the block runs (for example a lot size you change live). The backtester uses the starting value.
Custom MQL code
Inserts your own MQL lines into the EA exactly where the block runs. You can use the EA’s inputs and variables. It is compiled with the EA but not run in QuantForge’s backtester.