A strategy built from blocks on a canvas, without code, on every plan. The blocks compile to the engine's own strategy format, the same one Pine compiles to, so a blocks strategy backtests, optimizes over its parameters, runs on the server and on the native core, and exports to TradingView, MetaTrader 5 and cTrader like any other.
Starting one
Open Build, press the plus in the Strategies rail and choose Blocks canvas. A new blocks strategy starts as a moving average cross: two parameters, two averages, two crossings, a Buy and a Sell. Change it, or delete the blocks and start over.
The canvas
- Blocks come from the + at the top left of the canvas, in groups, with a search on top that finds a block by its name or what it does. Click one, or reach it with the arrow keys and press Enter, to place it in the middle of the canvas, or drag it to where it should go. With Shift held the list stays open for the next one.
- Wires go from an output on the right of a block to an input on the left of another. A round port carries a number, a square one a condition and a diamond a position size, and a wire only joins two of the same kind. An input takes one wire; a new one replaces the old.
- Settings of the block you select are on the right. An input with a setting of its own, a period or a threshold, uses the setting until a wire comes in.
- Delete a block or a wire with the Delete key, or with Delete block.
- Save keeps the strategy with every block where you left it.
How it runs
Compiling starts at the actions, Buy, Sell, the orders at a price, Cancel orders, Close position and Close part, and follows the wires back. Every bar, each block computes its value from the blocks wired into it; then the actions run in the order you placed them, and an action whose condition is true acts, with the engine weighing them the way it weighs a Python strategy's signals. A block that no action reads is left out and marked.
- Parameter blocks are what the optimizer sweeps, with the range you give.
- A period, a number of bars, has to be known before the run: a number, a parameter, or arithmetic on them. The block says so if it is wired to something that moves every bar.
- Every indicator is the engine's own, computed exactly as
ctx.smaand the others compute it for a Python strategy. A value an indicator does not have yet is empty, and a comparison with an empty value is false. - Session and Weekdays read the bar's opening time in UTC, with no daylight saving.
Orders at a price
Buy at price and Sell at price rest an order at the price wired into them instead of entering at the next open. Order picks the kind: a Limit buys at the price or lower and sells at it or higher, a pullback; a Stop buys once the market trades at the price or higher and sells at it or lower, a breakout.
- The order rests from the next bar until it fills, its Rests for bars run out (0 keeps it until it fills), a Cancel orders block takes it back, or another order of its OCO group fills.
- Without an Order name each block rests one order under its own name and moves it to the new price on every bar its condition holds. Give it a name to cancel it from a Cancel orders block; left empty there, every order goes.
- A fill opens a position with the stop and target measured from the fill price, or turns one the other way around. Holding the same way, the order waits.
- Export prints them for TradingView, MetaTrader 5 and cTrader, and Code shows them in Rust and Pine.
A stop that moves
Buy, Sell, Buy at price and Sell at price can move their stop once the position is open. Both are off until you pick a unit.
- Trail in and Trail: the stop follows the best price since the entry at this distance, and only toward profit. Wire an ATR distance into the Trail input for a trail that follows volatility.
- Trail starts in profit: the trail waits until the position is this far in profit; 0 starts it at the entry, standing the trail's distance behind the fill.
- Break even in and Break even at: once the position is this far in profit, the stop moves to the entry, plus Lock past the entry.
The stop is the best of the one set, the trail and break even. Each part of a bar is checked against the stop as it stood and then moves it, from the bar after the entry. Export prints a trail for TradingView, MetaTrader 5 and cTrader, and break even for MetaTrader 5 and cTrader: TradingView has no break even of its own, so a strategy with one does not export there. Code shows both in Rust.
Position size
Without a size an entry trades the run's lot size. A Position size block, in the Risk group, wired into the Size input of Buy, Sell or an order at a price, sizes it instead; one block can size several entries.
- Size in picks the kind: Risk, % of balance, what the stop loses if it is hit, which needs a stop on the entry; Lots; Units of the instrument; Cash in the account's currency; or Value, % of balance.
- Amount is the number, or wire a Parameter into it to sweep it.
- The size is measured on the bar the entry is decided on, with the balance after that bar. A size that comes to nothing places nothing.
Closing part of a position
Close part closes part of the open position while its condition is true: a share in percent, lots or units. As much as is open or more closes all of it. Each part is a trade of its own in the results, with the position's id and entry; the rest keeps its stop, target and moving stop.
The spread
Spread, among the sources, is the ask less the bid at the bar's close, in pips or in price, now or a number of bars ago. Wire it into a comparison for a spread filter, or into any input a price goes into. Data without an ask side reads the average spread of the symbol, set on your own symbol; without one the run says so and stops.
The position and the bid and ask
Position, among the sources, is what the engine holds once the bar's orders have filled: Open, whether a position is open, its Side (1 long, -1 short, 0 flat), its Entry, its Stop and the Bars held, 1 on the bar it filled. An order of this bar changes it from the next bar. Entry and stop have no value while flat, and the stop none without one. Price also gives the bar's bid and ask, bid open to ask close, which have no value on data without them. The MetaTrader 5 and cTrader exports read the platform's own position and the quotes the expert advisor or the cBot sees; TradingView reads its own position but has no stop to read and no bid or ask, so its export is refused at the block that asks for them.
Grids and baskets
The Baskets group trades many positions at once, on a hedging account: a long and a short beside each other, each with its own target. A basket is the positions of one side with one Label, grid say. A canvas with one of these blocks runs that way; Buy, Sell, Close position and Position, which trade the one position of a netting account, are then marked on the canvas.
- Open position opens a position of a basket now, at the close's quote: lots, a stop and a target in pips, at most so many open, and a cooldown in bars that every block of its label shares.
- Grid order adds to a basket once the price has gone the Step against its newest position: up to Most orders, only while the newest is in loss if you like, the step growing by order or on the last orders. Wire an Online ML chance into Turn chance and the step widens when a turn is unlikely. Ordered says whether it ordered on this bar, to keep the other side from ordering too.
- Lot steps gives the next order's lots: the first order's, then times the factor for every order past the ones that keep them.
- Basket target sets one target for the whole basket: the average entry, the target per order spread over its lots, the commission and an extra. Wire a condition into Arm trailing and while it holds the target comes off and trails instead, closing the basket a set distance back from its best price.
- Drawdown pause closes every position when the open loss reaches a percent of the balance and gives Paused for the days you set.
- Basket and Account read what is open as it is when read: a rule below an order sees that order. Basket can also read the basket as the bar's rules began.
- News window blocks the minutes around economic releases by impact, currencies and kinds: rate decisions, jobs reports, consumer prices. Days off is a list of days and periods. Weekly regime says whether the week trends up, down, is volatile or ranging, from the daily closes before it. Online ML learns bar by bar how likely the price moves a number of ATRs up or down.
Orders of the Baskets group act at once, on the bar they are decided on, as a cTrader cBot's or a MetaTrader expert advisor's do.
Custom blocks
Several blocks can become one block of your own, like a few lines of code become a function.
- Select the blocks (drag a box around them, or Shift and click) and press Make a custom block. Name it, pick a colour and an icon, and choose what it shows: its Inputs, its Outputs and the Settings of the blocks inside, each under a label of your own. The wires into and out of the selection are chosen already, so the strategy stays as it was. A Parameter inside is a setting of the block and stays a parameter the optimizer sweeps; a second copy of the block numbers its parameters on (
fast_2). - It goes into My blocks at the top of the + list and is placed like any block. A custom block can hold other custom blocks, but never itself.
- Double click it, or press Edit inside, to change its inside, with the way back at the top left of the canvas. Save block keeps it as its next version.
- A strategy keeps the version it was built with. When My blocks has a newer one, Updates on the canvas and Update to version on the block take it on, for this strategy only. Deleting a block from My blocks changes no strategy.
- The menu beside a block in My blocks renames, duplicates, exports it as a file to share, or deletes it; the arrow beside My blocks imports a file.
When the strategy runs, a custom block is the blocks inside it: the same document, backtest and export as if they were placed one by one.
Problems
A block with something wrong is marked on the canvas, and Problems on the right lists each one; click it to go to the block. Validate also asks the engine, and whatever it finds is put on the block it is about. A strategy with a problem does not run.
Code
Code at the top right of the canvas shows what the blocks compile to, and Blocks in the same place goes back. It has four tabs: the strategy as Python, as Rust and as Pine, each printed by the engine, and the document itself. Python says everything the blocks do. Open in Python editor makes a new Python strategy from it and opens it, to carry on in code; the blocks stay as they are. Where Rust or Pine cannot say a block yet, the tab says which. Export in the toolbar prints it for TradingView, MetaTrader 5 or cTrader, exactly as it backtests here.
Terminal series
Series, among the sources, is a series of the Terminal as it was known at the bar: the newest value released by then, empty before. Its search finds a series by name or id. It runs on this computer only, and the exports refuse it by its name (see Terminal).
Not yet
The Baskets group, News window, Days off, Weekly regime and Online ML run on the Python engine and do not export to TradingView, MetaTrader 5 or cTrader yet; Code says so where it would print them.