Navigation: Realtest Script Language > Syntax Element Details >







General-Purpose Functions


Calculate the value of tomorrow's close that would cause an indicator to reach a specific level


TargetPrice(expression, value, range {50})


expression - an indicator formula

value - the desired return value of the indicator

range {50} - today's close plus/minus this percentage sets the range of prices to try

Return Value

The price that, if it were tomorrow's close, would come nearest to producing the desired indicator value.


This function uses binary search logic to govern an iterative process:

temporarily coerce tomorrow's OHLC values to a specific value in the data (adding an extra bar at the end if needed)

call the indicator function with a one-bar lookahead offset e.g. MA(C, 20)[-1]

narrow the search range based on whether the result was too low or too high

The optional range argument lets you control how wide a range to allow. For example if today's close was 100 and the default 50% range is used, it will start with the range 50 to 150 and narrow it from there. If the required price is outside the range, the result will be the range boundary, not the correct price.

For a quick test of how this works, compare TargetPrice(RSI(2), 50) to RRSI(2, 50) -- the results will be the same (or very close).

(RRSI is much faster than TargetPrice because it can calculate the needed price deterministically. TargetPrice is meant for use with other indicators that don't support a deterministic reverse version, e.g. CRSI.)

The expression passed to TargetPrice should not be a reference to a Data array containing a previously-calculated indicator. The iterative search process requires multiple recalculations of the indicator while searching for the needed price. Data items are not recalculated for this purpose.

It is NOT recommended to use TargetPrice within a Data Section formula. It is best suited for use in an EntryLimit or ExitLimit formula, where it will only be evaluated for each setup or open position respectively, not for every bar of every stock in the universe. This is not a speedy function, especially when used with long-lookback indicators.




Copyright © 2020-2023 Systematic Solutions, LLC