Hoping someone can point me in the right direction.
I trade index pairs, for example long Nasdaq / short Dow, with the positions sized for balanced notional exposure. My entry signals are based on the ratio (Nasdaq ÷ Dow) moving a certain number of standard deviations away from its mean.
I know ProRealTime doesn’t allow backtesting on calculated instruments, so I’m looking for another way to do this.
Is it possible to use a CALL function (or something similar) to reference a second instrument within a ProBacktest strategy and generate signals that way?
If not, is there another approach I’m missing?
If this isn’t something that can be explained easily, I’d also be happy to pay an experienced ProRealTime developer to help build it.
I’m afraid there is no such possibility currently, for automated trading.
But, you can create a screener that refers multiple instruments in order to generate “signals” while the platform is opened.
Below is an example:
// ============================================================
// Pairs Screener: Nasdaq / Dow ratio Z-score
// Run this screener on a watchlist that contains the Nasdaq
// index ticker. The Dow is fetched as the reference leg.
//
// Signals:
// Z >= +threshold → ratio stretched HIGH → Long Dow / Short Nasdaq
// Z <= -threshold → ratio stretched LOW → Long Nasdaq / Short Dow
// ============================================================
// ---------- user parameters ----------
RatioPeriod = 20 // look-back for mean & std-dev of ratio
ZThreshold = 2.0 // number of standard deviations to flag
// ---------- reference leg: fetch Dow close ----------
// Replace "INDEX" and "DJIA" with the exact market name and
// ticker shown in your PRT platform for the Dow Jones index.
EQUITYFRAME("INDEX","DJIA")
DowClose = close
EQUITYFRAME(default)
// ---------- this instrument: Nasdaq close ----------
NasClose = close
// ---------- ratio & Z-score ----------
Ratio = NasClose / DowClose
RatioMA = Average[RatioPeriod](Ratio)
RatioSTD = STD[RatioPeriod](Ratio)
// Guard against zero std-dev on flat / insufficient data
IF RatioSTD > 0 THEN
ZScore = (Ratio - RatioMA) / RatioSTD
ELSE
ZScore = 0
ENDIF
// ---------- directional signals ----------
LongNasdaq = ZScore <= -ZThreshold // ratio cheap → buy Nasdaq, sell Dow
LongDow = ZScore >= ZThreshold // ratio rich → buy Dow, sell Nasdaq
Triggered = LongNasdaq OR LongDow
// ---------- screener output ----------
SCREENER[Triggered](ZScore AS "Z-Score", Ratio AS "NAS/Dow Ratio", RatioMA AS "Ratio Mean", RatioSTD AS "Ratio StdDev")
Logic
- The ratio (Nasdaq ÷ Dow) is computed bar by bar. Its rolling mean and standard deviation are calculated over RatioPeriod bars (default 20).
- The Z-score measures how many standard deviations the current ratio sits away from that mean.
- A positive Z means Nasdaq has outrun the Dow recently; a negative Z means the Dow has outrun Nasdaq.
- The screener fires when |Z| reaches ZThreshold (default 2.0), i.e. the spread is statistically stretched and likely to mean-revert.
The four columns it outputs are:
- Z-Score — the raw signal value, tells you direction and magnitude.
- NAS/Dow Ratio — the current ratio level.
- Ratio Mean — the rolling average of the ratio over your look-back.
- Ratio StdDev — the rolling standard deviation; useful to see whether the ratio is unusually quiet or volatile.
Setup steps
- Create a watchlist containing your Nasdaq index ticker (e.g. NAS100 or US-TECH100, whatever your broker calls it).
- In the EQUITYFRAME call, replace “INDEX” and “DJIA” with the exact market name and ticker that appear in PRT for the Dow.
- Run the screener on that watchlist at whatever timeframe you trade (daily, hourly, etc.).
- When the screener fires, Z-Score tells you the direction: negative Z → Long Nasdaq / Short Dow; positive Z → Long Dow / Short Nasdaq.
It might be too complicated for your need though, but with the exact description of your signals building we could change/improve the above code, let us know! 😉