All,
I'm probably missing yet another fundamental EFS concept/best practice, but I noticed that sometimes when I pass a series created via efsInternal as the source to some of the built-in studies, I get a 1 bar lag effect.
I created the following script to help flush out the problem. When you run it I would expect each ema() output series to produce the exact same result, which means there should be 3 lines exactly on top of each other. Unfortunately, in the ema() case the outputSeries2 lags by one bar. I tried substituting ema with other studies. sma, and cci both lag. rsi and stochK don't lag. roc and moneyFlow seem to work with inputSeries0 but may or may not work with the other input series depending on the formula you pass them. I'm sure the remaining studies are hit or miss as well.
So why do the ema and some of the other studies lag in outputSeries2 whereas some don't? And what should I do to stop any of them from lagging?
And as an aside, why in the ema() case is outputSeries1 a constant value when the formula is set to "ohlc4()"? I "fixed" this problem by whimsically setting the formula to "getSeries(ohlc4(), 0)". Also, why can either formula be used if you change ema to rsi?
Thanks,
Jeff
I'm probably missing yet another fundamental EFS concept/best practice, but I noticed that sometimes when I pass a series created via efsInternal as the source to some of the built-in studies, I get a 1 bar lag effect.
I created the following script to help flush out the problem. When you run it I would expect each ema() output series to produce the exact same result, which means there should be 3 lines exactly on top of each other. Unfortunately, in the ema() case the outputSeries2 lags by one bar. I tried substituting ema with other studies. sma, and cci both lag. rsi and stochK don't lag. roc and moneyFlow seem to work with inputSeries0 but may or may not work with the other input series depending on the formula you pass them. I'm sure the remaining studies are hit or miss as well.
So why do the ema and some of the other studies lag in outputSeries2 whereas some don't? And what should I do to stop any of them from lagging?
And as an aside, why in the ema() case is outputSeries1 a constant value when the formula is set to "ohlc4()"? I "fixed" this problem by whimsically setting the formula to "getSeries(ohlc4(), 0)". Also, why can either formula be used if you change ema to rsi?
Thanks,
Jeff
Code:
function preMain() { setDefaultBarFgColor(Color.blue, 0); setDefaultBarFgColor(Color.green, 1); setDefaultBarFgColor(Color.red, 2); } var formula = "getSeries(ohlc4(), 0)"; // Why does this way work? // var formula = "ohlc4()"; // And sometimes this doesn't work? // var formula = "stochK(9, 1, 1, ohlc4())"; var inputSeries0 = null; var inputSeries1 = null; var inputSeries2 = null; var outputSeries0 = null; var outputSeries1 = null; var outputSeries2 = null; var fullyInitialized = false; function main() { if (!fullyInitialized) { if (inputSeries0 == null) inputSeries0 = eval(formula); if (inputSeries1 == null) inputSeries1 = efsInternal("regurgitate", inputSeries0); if (inputSeries2 == null) inputSeries2 = efsInternal("hardCoded"); if (outputSeries0 == null) outputSeries0 = ema(5, inputSeries0); if (outputSeries1 == null) outputSeries1 = ema(5, inputSeries1); if (outputSeries2 == null) outputSeries2 = ema(5, inputSeries2); fullyInitialized = true; } return [outputSeries0.getValue(0), outputSeries1.getValue(0), outputSeries2.getValue(0)]; } function regurgitate(aSeries) { return aSeries; } function hardCoded() { return eval(formula); }
Comment