Outliers, stock splits, price anomalies
PriceJump
An unusual price deviation in historical or live price data was detected. Automatically set by calling a price or
contractUpdate function; sensitivity can be set with
the Outlier variable. PriceJump can be evaluated in scripts
for handling outliers and stock splits or merges. Afterwards reset it to 0 for 'arming' it for the next price
deviation.
0 - No price anomaly since the last
reset.
1 - Outlier detected, see below.
2..10
- Stock split by the given factor detected, f.i. 4 for a
1:4
stock split.
-2..-10
- Stock merge by the given factor detected, f.i. -4 for a
4:1
stock merge.
Type:
int
Outlier
Sensitivity factor of the outlier detection for historical and for live prices (default = 1.1+2*sqrt(BarPeriod/1440)).
All outliers above the given factor or below its reciprocal are suppressed with
a 0.0001 EMA factor. For instance, Outlier = 1.15; suppresses all outliers that deviate from the last price by more than 15%
in any direction.
PriceJump is set to 1 when an outlier was detected.
Negative ask-bid spreads are also suppressed. Set Outlier to 0 for not
detecting splits, outliers, and negative spreads; set it to between 1
and 2 for detecting them; set it to above
2 for high volatility assets and for treating splits as outliers.
Type:
var
NumOutliers
Number of outliers and price jumps detected so far in historical or live data
(Zorro 2.42 or above). Can be reset to 0 for starting a new count.
Type:
int
Remarks:
- Some assets, such as cryptocurrencies or penny stocks, have a high volatility. The
default outlier sensitivity factor is relatively insensitive for not being
triggered by those assets, but could be further increased or entirely disabled when
necessary.
- Historical candles from online sources are usually already split and dividend adjusted, but
options data (.t8) and live or historical data from brokers
or exchanges are not.
- How to handle stock splits in live data depends on
the script and on the broker. Some variables and
series must be adjusted after a split is detected, others can remain unchanged.
Open trades should be adjusted in the same way as the broker handles them. If the
broker adjusts volume and prices, the script should do the same.
When prices are adjusted, stop, trail, and profit limits must be as well.
For adjusting a price, divide it by PriceJump;
for adjusting a volume, multiply with PriceJump. If
the broker API does not automatically update asset parameters, margin cost
and rollover fees might alsoi require adjustment.
- Scripts that don't explicitely handle stock splits should suspend trading after detecting a split, and only resume trading after
a period equivalent to LookBack
has passed. Open trades of the split asset should be
cancelled by script and closed manually.
- Trading systems should not be started immediately when a stock split was
detected in the lookback period. Let at least LookBack
bars pass after a
stock split before the first trade. Otherwise the split can invalidate the initial values of indicators.
- Stock splits are not harmful to the Z systems.
Example:
function run()
{
...
Outlier = 1.05; // detect and suppress price deviations by more than 5%
PriceJump = 0; // in case it was set before
price();
if(PriceJump >= 2) { // stock split detected
printf("\nStock split %i:1 - manually close all open contracts!",PriceJump);
for(open_trades) cancelTrade(ThisTrade); // clear the open trade list
PriceJump = 0;
setf(TradeMode,PHANTOM); // suspend further trading
}
...
}
See also:
tick, TickTime,
price
► latest version online