I suppose I wanted to delay this as long as possible, but I need to get a deeper understanding of why this happens.
I am using an EFS developed by TSS as an input into one of my systems. I have successfully written all the code to get the variables from the TSS EFS into my own EFS, so that is not a problem.
When my own EFS is loaded, it processes bars in the past, and I print out the value for my input from TSS. I get value X. When the EFS catches up to the runs in current bar, I request the same value from the EFS study only on the first tick of the new bar, and I get a TOTALLY different value.
This was driving me crazy, so I really thought about why this was happening, and I think the answer is clear, but anyone who reads this I would appreciate a stamp of approval.
Take the following EFS by TSS for instance:
/************************************************** *****************
Description : This Indicator plots Ergotic_TSI indicator
Provided By : Developed by TS Support, LLC for eSignal. (c) Copyright 2002
************************************************** ******************/
function preMain()
{
setStudyTitle("Ergotic_TSI");
setCursorLabelName("ErgTSI", 0);
setCursorLabelName("SigLin", 1);
setCursorLabelName("ZeroLine", 2);
setDefaultBarFgColor(Color.fushcia, 0);
setDefaultBarFgColor(Color.grey, 1);
setDefaultBarFgColor(Color.cyan, 2);
}
var XA1_1 = 0.0;
var XA2_1 = 0.0;
var XA3_1 = 0.0;
var aXA1_1 = 0.0;
var aXA2_1 = 0.0;
var aXA3_1 = 0.0;
var XA_1 = 0.0;
function main(sPrice, r, s, u, ZeroLine, SmthLen)
{
if (sPrice == null) sPrice = "Close";
if (r == null) r = 4;
if (s == null) s = 8;
if (u == null) u = 6;
if (ZeroLine == null) ZeroLine = 0;
if (SmthLen == null) SmthLen = 3;
var Price = getValue(sPrice, 0, -2);
var vPrice = Price[0] - Price[1];
var FactorR = 2 / (r + 1);
var FactorS = 2 / (s + 1);
var FactorU = 2 / (u + 1);
var XA1 = FactorR * vPrice + (1 - FactorR) * XA1_1;
var XA2 = FactorS * XA1 + (1 - FactorS) * XA2_1;
var XA3 = FactorU * XA2 + (1 - FactorU) * XA3_1;
vPrice = Math.abs(Price[0] - Price[1]);
var aXA1 = FactorR * vPrice + (1 - FactorR) * aXA1_1;
var aXA2 = FactorS * aXA1 + (1 - FactorS) * aXA2_1;
var aXA3 = FactorU * aXA2 + (1 - FactorU) * aXA3_1;
var Val1 = 100 * XA3;
var Val2 = aXA3;
var TSI = 0.0;
if (Val2 != 0) TSI = Val1 / Val2;
else TSI = 0.0;
var Factor = 2 / (SmthLen + 1);
var XA = Factor * TSI + (1 - Factor) * XA_1;
if (getBarState() == BARSTATE_NEWBAR)
{
XA1_1 = XA1;
XA2_1 = XA2;
XA3_1 = XA3;
aXA1_1 = aXA1;
aXA2_1 = aXA2;
aXA3_1 = aXA3;
XA_1 = XA;
}
return new Array(TSI, XA, ZeroLine);
}
Some of the code in this I just cross off to computation, and I am not going into extreme depth on it, but the essentials for price in terms of high, low, open and close are computed on the full bar once it is formed. Meaning, that on the last possible tick of a bar. In this manner, the EFS has all the data to compute a return value for that bar based on all possible data points that made that bar.
When I write an EFS, I can only react to that signal, on the very first tick of the NEXT bar, so I coded my EFS to reflect this, and only process signals on the next bar, and as an error, I was calling the value from my TSS EFS on the very FIRST tick of the NEW bar. The first tick of the new bar has identical values for open, close, high and low. It is no wonder why my values were so off compared to backtesting and real-time results.
Am I correct in this assumption?
I have since corrected my EFS and will be able to fully test on Monday's market. I will post my findings then.
Regards,
Thomas.
I am using an EFS developed by TSS as an input into one of my systems. I have successfully written all the code to get the variables from the TSS EFS into my own EFS, so that is not a problem.
When my own EFS is loaded, it processes bars in the past, and I print out the value for my input from TSS. I get value X. When the EFS catches up to the runs in current bar, I request the same value from the EFS study only on the first tick of the new bar, and I get a TOTALLY different value.
This was driving me crazy, so I really thought about why this was happening, and I think the answer is clear, but anyone who reads this I would appreciate a stamp of approval.
Take the following EFS by TSS for instance:
/************************************************** *****************
Description : This Indicator plots Ergotic_TSI indicator
Provided By : Developed by TS Support, LLC for eSignal. (c) Copyright 2002
************************************************** ******************/
function preMain()
{
setStudyTitle("Ergotic_TSI");
setCursorLabelName("ErgTSI", 0);
setCursorLabelName("SigLin", 1);
setCursorLabelName("ZeroLine", 2);
setDefaultBarFgColor(Color.fushcia, 0);
setDefaultBarFgColor(Color.grey, 1);
setDefaultBarFgColor(Color.cyan, 2);
}
var XA1_1 = 0.0;
var XA2_1 = 0.0;
var XA3_1 = 0.0;
var aXA1_1 = 0.0;
var aXA2_1 = 0.0;
var aXA3_1 = 0.0;
var XA_1 = 0.0;
function main(sPrice, r, s, u, ZeroLine, SmthLen)
{
if (sPrice == null) sPrice = "Close";
if (r == null) r = 4;
if (s == null) s = 8;
if (u == null) u = 6;
if (ZeroLine == null) ZeroLine = 0;
if (SmthLen == null) SmthLen = 3;
var Price = getValue(sPrice, 0, -2);
var vPrice = Price[0] - Price[1];
var FactorR = 2 / (r + 1);
var FactorS = 2 / (s + 1);
var FactorU = 2 / (u + 1);
var XA1 = FactorR * vPrice + (1 - FactorR) * XA1_1;
var XA2 = FactorS * XA1 + (1 - FactorS) * XA2_1;
var XA3 = FactorU * XA2 + (1 - FactorU) * XA3_1;
vPrice = Math.abs(Price[0] - Price[1]);
var aXA1 = FactorR * vPrice + (1 - FactorR) * aXA1_1;
var aXA2 = FactorS * aXA1 + (1 - FactorS) * aXA2_1;
var aXA3 = FactorU * aXA2 + (1 - FactorU) * aXA3_1;
var Val1 = 100 * XA3;
var Val2 = aXA3;
var TSI = 0.0;
if (Val2 != 0) TSI = Val1 / Val2;
else TSI = 0.0;
var Factor = 2 / (SmthLen + 1);
var XA = Factor * TSI + (1 - Factor) * XA_1;
if (getBarState() == BARSTATE_NEWBAR)
{
XA1_1 = XA1;
XA2_1 = XA2;
XA3_1 = XA3;
aXA1_1 = aXA1;
aXA2_1 = aXA2;
aXA3_1 = aXA3;
XA_1 = XA;
}
return new Array(TSI, XA, ZeroLine);
}
Some of the code in this I just cross off to computation, and I am not going into extreme depth on it, but the essentials for price in terms of high, low, open and close are computed on the full bar once it is formed. Meaning, that on the last possible tick of a bar. In this manner, the EFS has all the data to compute a return value for that bar based on all possible data points that made that bar.
When I write an EFS, I can only react to that signal, on the very first tick of the NEXT bar, so I coded my EFS to reflect this, and only process signals on the next bar, and as an error, I was calling the value from my TSS EFS on the very FIRST tick of the NEW bar. The first tick of the new bar has identical values for open, close, high and low. It is no wonder why my values were so off compared to backtesting and real-time results.
Am I correct in this assumption?
I have since corrected my EFS and will be able to fully test on Monday's market. I will post my findings then.
Regards,
Thomas.
Comment