Most trade systems analyze the recent price curve with functions or indicators that introduce more or less lag. This means that trade signals are always late, which reduces the profit of a system. One way to minimize lag is using low-lag functions (for instance, higher-order lowpass filters instead of moving averages). Another way is predicting the signals before they actually occur. This is the purpose of the predict function that works by extrapolating signal curves into the future.
Type | Event to be predicted: CROSSOVER - crossing of Data over the zero line PEAK - Data peak VALLEY - Data valley +PARABOLIC - use parabolic instead of linear regression. |
Data | Data series to be predicted, with a minimum length of TimePeriod. |
TimePeriod | Number of Data points used for the prediction. Do not use more date than a typical 'swing' of the curve. |
Threshold | Prediction threshold, or 0 for no threshold. |
function run() { vars Prices = series(price()); var LP50 = LowPass(Prices,50); var LP150 = LowPass(Prices,150); var CO = predict(CROSSOVER,series(LP50-LP150),10,0.5*PIP); // predict crossover var CU = predict(CROSSOVER,series(LP150-LP50),10,0.5*PIP); // predict crossunder plot("LP50",LP50,0,RED); plot("LP150",LP150,0,BLUE); plot("CrossOver",CO,NEW,BLUE); plot("CrossUnder",CU,0,RED); }
// Trading with crossover vs. trading with prediction #define USE_PREDICT function run() { BarPeriod = 1440; asset("SPX500"); vars Osc = series(StochEhlers(series(price()),10,20,10)); #ifndef USE_PREDICT // use normal crossover if(crossOver(Osc,0.8)) enterShort(); if(crossUnder(Osc,0.2)) enterLong(); #else // use predicted crossover if(predict(CROSSOVER,series(Osc[0]-0.8),10,0.01) > -5) enterShort(); if(predict(CROSSOVER,series(0.2-Osc[0]),10,0.01) > -5) enterLong(); #endif }Examples of signal prediction can also be found in the Predict and Ehlers scripts.