Soon available

Not on the Chrome Web Store yet

ProRealCode Studio is on its way. As soon as it is published, this button will take you straight to its Chrome Web Store page.

Chapter 18 · Part IV — Alerts and strategies

Run a strategy over the past. Read what it would have done.

A code that places orders is a strategy. Studio plays it over every bar the chart holds, marks each trade on the candles and puts the numbers in a window of their own. This chapter runs one, reads its results, and says what those results are worth.

A daily EUR/USD chart in dark mode with a strategy's trades: green up arrows under the candles where it bought, red crosses where positions were closed, and dotted lines joining each entry to its exit, plus the strategy's dashed moving average.
A strategy's trades on the chart: arrows where it bought, crosses where it closed, a dotted line for each trade. This capture was taken with the platform in dark mode.
  1. 01Write and run a strategy One order in the code.
  2. 02Find it in Strategies The list of codes that place orders.
  3. 03Open the results The window, band by band.
  4. 04Read the tiles Nine figures, one per tile.
  5. 05Check the orders and the chart Every trade, filtered, then on the candles.
  6. 06Set the account Capital, lot size, spread.
Before you startYou can run a code on the chart (chapter 02). The order instructions themselves, BUY, SELL, SET STOP and the others, are listed in chapter 23. Here you use a four-line example.
ProRealCode StudioUser guide · Chapter 18
01 · Task · Write and run a strategy

One order in the code, and it becomes a strategy.

The example the Strategies window shows while no strategy is on the chart.

1IF NOT LongOnMarket AND close CROSSES OVER Average[20](close) THEN2  BUY 1 SHARES AT MARKET3ENDIF4SET STOP %LOSS 2

Line 1 asks two questions: no long position open yet, and the close crossing above its 20-bar average.

Line 2 buys one unit when both are true. Any of BUY, SELL, SELLSHORT or EXITSHORT makes a code a strategy.

Line 4 places a stop 2 % under the entry price of every position.

  1. Type the four lines into a new code, then click “Run”.Studio plays the strategy over every bar of the chart and draws its trades on the candles.
  2. Save it under a name of your own (chapter 02).The name is the one the results window will show.

When an order is filled

The code is read once, when a candle closes. The order it places is filled at the opening price of the next candle, never at the close it was decided on.

Close: the code decides “BUY”Open: the order is filled signal candlenext candleentry arrow, under the candle
Illustration. Between the two prices, the market may have moved. That gap is part of every result in this chapter.
ProRealCode StudioUser guide · Chapter 18
02 · Task · Find it in Strategies

Every code that places orders gets a row of its own.

The Strategies window: the Run strategies in realtime switch, off, with its two lines of explanation, then the row of the strategy Code 1 with a bin, Optimize, a chart icon and a run triangle, the line EURUSD · 1d · backtest only, and P&L 0.00, trades 187. 1 2 3 4 5 6 7
The Strategies window with one strategy, run over 2,981 daily bars of EUR/USD.
  1. “Run strategies in realtime”. Off: the strategy only runs on the past. Chapter 19 turns it on.
  2. The strategy's name, as saved.
  3. The bin takes the strategy off the chart. Its code stays in the editor.
  4. “Optimize” tries ranges of its settings (chapter 20).
  5. The chart icon opens the results window (task 3). The triangle after it arms the strategy for real time (chapter 19).
  6. Instrument, timeframe and state: “backtest only” while it is not armed.
  7. “P&L” and “trades”: the result so far and the number of closed trades. “open” appears when a position is still running.
  1. Click the Strategies icon on the rail: a candle with a small triangle in it. The “Strategies” row of the ƒ launcher does the same.The window lists every strategy on the chart. The same list is in the Codes window, under ON CHART.
  2. Click the chart icon of your strategy.The results window opens, and the run joins “Completed runs”, at the bottom of this list.
ProRealCode StudioUser guide · Chapter 18
03 · Task · Open the results

The verdict first, then the curve that led to it.

The top of the Backtest results window for Code 1: the chips Backtest and #1, the edit, run again, settings and Optimize buttons; the Runs strip with run #1; the chips EURUSD, 1d, 2,981 bars, 2015-04-29 to 2026-10-21, Balance 10000, Lot 1, Spread none, Period whole history; Net profit total 0.00 with its Read sentence; the equity curve with its drawdown shaded in red. 1 2 3 4 5 6 7
The top of the results window. One unit of EUR/USD per trade: each gain or loss is a fraction of a unit, so every amount here prints as 0.00. Task 6 sets a lot size.
  1. “Backtest” and “#1”. The kind of run, and its number in this session. Click the number to find the run in “Completed runs”.
  2. The buttons: the pencil opens the code, the circular arrow runs it again on the settings shown, the gear opens the Backtest preferences, “Optimize” leads to chapter 20.
  3. “Runs”. Every run of this session, newest first. “Compare with” appears beside it once there are two runs.
  4. What the run was measured on. Click “Balance”, “Lot”, “Spread” or “Period” to change it for this strategy only; an empty field falls back on the preferences.
  5. “Net profit · total”: closed trades plus the position still open, in money and in percent of the starting balance.
  6. “Read:” the same run in one sentence: trades, share won, profit factor, worst drawdown, and whether it made money.
  7. The curve. Black: the equity, open position included. Grey: the balance, closed trades only. Red shading: the drop from the last high.
Results last as long as the tabThe session keeps up to 40 runs, each as it was when recorded: editing the code later does not change an old run. Closing or reloading the ProRealTime tab clears them all.
ProRealCode StudioUser guide · Chapter 18
04 · Task · Read the tiles

Nine tiles answer the question the total cannot.

Nine tiles: Win rate 26.7% of 187 trades, Win / Loss 50W / 137L, Profit factor 0.84, Max drawdown 0.00, Trade P&L for the last 60 of 187 trades, Trades 187 with 187 long and 0 short, Average trade 0.00, Losing streak 16, In market 48 % with 1,429 of 2,981 bars in a position.
The tiles of the same run: 187 trades, 50 winners, 137 losers.
TileWhat it says
Win rate, Win / LossThe share of closed trades that made money, 26.7 % here, then the same split as a ring.
Profit factorMoney won divided by money lost. Under 1, the losers weigh more: 0.84 here. A dash when no trade lost.
Max drawdownThe worst fall of the equity from a high, in money and in percent of that high, with the date it bottomed.
Trade P&LOne bar per trade, up for a gain: the last 60 trades.
TradesClosed trades, split long and short, plus any position still open.
Average tradeThe mean result of a trade, with the best and the worst one.
Losing streakThe longest run of losing trades in a row, what it cost and when it ended.
In marketThe share of bars spent holding a position: 1,429 of 2,981, or 48 %.
  1. Change a setting of the strategy, then run it again with the circular arrow.A second run, #2, joins the strip.
  2. In “Compare with”, pick the first run.Its curve appears dashed beside the new one, and each tile shows the difference in its corner: green where this run does better, red where it does worse.
ProRealCode StudioUser guide · Chapter 18
05 · Task · Check the orders and the chart

When a figure surprises you, the trades explain it.

The orders list: filter chips All 187, Long 187, Short 0, Winners 50, Losers 137, order 185, Stop 2; then one row per trade with side long, quantity 1, entry bar, date, entry price, exit bar, exit price, P&L with a small bar, and the exit reason order.
The bottom of the results window: the filters, then one row per trade. Click a column title to sort on it.

The columns. SIDE and QTY: long or short, and the size. IN BAR, TIME and IN: the entry, as bar number, date and price. OUT BAR and OUT: the exit. P&L and EXIT: the result, and what closed the trade, “order” for an exit the code placed, “Stop” for its stop.

  1. Click a filter chip.Only those trades stay. Exit reasons get their own chips, “Stop 2” here.
  2. Click a trade.Its two marks light up on the chart. Click again to switch them off.

The marks on the chart

ArrowAn entry, just outside the candle: green when the order bought, red when it sold.
Dot and signAn exit: a small dot at the price it left at, and a sign for the reason. Take Profit and Stop Loss each have their own; any other close is a cross.
CaptionThe order and its price, BUY 1.0852 for instance, on the 60 most recent orders.
Dotted lineFrom entry to exit: green for a gain, red for a loss, grey for exactly nothing. The 400 most recent trades are drawn.
ProRealCode StudioUser guide · Chapter 18
06 · Task · Set the account

Same code, other account: set what one lot is worth.

Preferences on the Backtest tab, ACCOUNT section: Initial capital 10000, Lot size 1, Use the current spread switched on, each with its explanation; the CHART ANNOTATIONS heading below.
Preferences, tab “Backtest”: the account every run starts from.
  1. Open Preferences with the gear at the bottom of the rail, or with the gear of the results window, then the tab “Backtest”.
  2. Set “Initial capital” and “Lot size”.Every strategy on the chart runs again on the new values.
  3. To test one strategy on other values, use its chips in the results window instead (task 3).Those values win over the preferences, for that strategy only.
SettingAt firstEffect
Initial capital10000The starting balance. Percentages, net and drawdown, are measured against it.
Lot size1What one LOT means: BUY 2 LOTS opens 2 × this many units. Leave it at 1 unless you trade forex, where a standard lot is usually 100 000.
Use the current spreadonEach fill pays half the instrument's current spread: a buy at the ask, a sell at the bid. Off, fills are at the bar price.
Order labels on the chartonThe captions of task 5. The arrows stay either way.
Trade lines on the chartonThe dotted lines of task 5.
A Studio backtest is not a ProRealTime backtestStudio fills each order at the next candle's open and knows only the open, high, low and close of each bar. When a stop and a target both fall inside one bar, it takes the stop. ProRealTime settles that case on a smaller timeframe, so its figures for the same code can differ.
ProRealCode StudioUser guide · Chapter 18
Chapter 18 · In short

One order makes a strategy. One click shows what it did.

A code with BUY, SELL, SELLSHORT or EXITSHORT is a strategy. Studio runs it over the chart's history, fills each order at the next candle's open, and keeps every run of the session in the results window, where the tiles, the list of trades and the marks on the chart all describe the same trades.

Every amount reads 0.00. Is the run empty?

No. Count the trades. On forex, one unit per trade earns fractions of a unit: set the lot size, or buy more units in the code.

Why does ProRealTime give other figures for the same code?

The two backtests do not settle a bar in the same way when a stop and a target meet in it, and the spread may differ. Compare the trades, not only the total.

My old runs are gone.

Runs last as long as the ProRealTime tab. A reload clears them. Note the figures you want to keep.

The results window says “No run to show yet”.

Open a run from the Strategies window, with the chart icon of a strategy, or click a row of “Completed runs”.

The entry is not at the price of the signal candle. A bug?

No. The code decides at the close; the order fills at the next open. Between the two, the price moved.

Can I backtest only part of the history?

Yes. Click “Period” in the results window and set “From” and “To”, for this strategy only.

No investment advice. A backtest describes what a code would have done on past prices, under the assumptions listed in this chapter. It is not a forecast, not investment advice and not a recommendation to buy or sell anything. Past results do not predict future results.

Next

Chapter 19 · Strategies in real time

The same strategy, armed on the live chart: a sound and a signal at each fill, and no order sent anywhere.

ProRealCode StudioUser guide · Chapter 18
ProRealCode ProRealCode
Loading...