Hi,
I'm using the following code but I'm getting different results everyday. The results are consistent within each day (even when I restart eSignal) but when I start eSignal at the start of a new day then the output data is completely different from that of the previous day.
My first thought was that this was due to the first day 'dropping out' of my time template so I have been adding one day to the length of the template each morning (so that the start date is always the same) and still get the same problem.
To make sure that the code is looking at the same data each time I have been noting down the start date and time, the first date and time that an output is returned and the value returned by that output. It is the value of this output which changes everyday even though (as far as I can see) it is taking it's data from identical inputs to the previous day.
I don't think it matters what product/symbol you look at for this to happen but I have been looking at AT 1!-DT (i.e. Dax).
Does anyone have any ideas why this is happening as I am at a complete loss? Many thanks in advance.
The code is as follows:
var fpArray = new Array();
var bInit = false;
var ECO = 0.0;
var ECOprev = 0.0;
function preMain() {
setStudyTitle("XYZ");
setCursorLabelName("XYZ", 0);
setDefaultBarFgColor(Color.red, 0);
addBand(0, PS_SOLID, 1, Color.cyan);
var x=0;
fpArray[x] = new FunctionParameter("r", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(300);
}
fpArray[x] = new FunctionParameter("s", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(150);
}
}
var xEMA = null;
var xvEMA = null;
var LongStop = null;
var ShortStop = null;
function main(r, s) {
var nState = getBarState();
if (nState == BARSTATE_ALLBARS) {
if (r == null) r = 300;
if (s == null) s = 150;
}
if ( bInit == false ) {
xEMA = ema(s, ema(r, efsInternal("CloseOpen")));
xvEMA = ema(s, ema(r, efsInternal("HighLow")));
bInit = true;
}
if (getCurrentBarCount() < Math.max(r,s)) return;
if(xvEMA.getValue(0) != 0) {
ECO = 100 * (xEMA.getValue(0) / xvEMA.getValue(0));
}
if(xvEMA.getValue(0) != 0) {
ECOprev = 100 * (xEMA.getValue(0) / xvEMA.getValue(0));
}
if(xvEMA.getValue(0) != 0)
return 100 * (xEMA.getValue(0) / xvEMA.getValue(0));
else
return;
}
function CloseOpen() {
var nRes = 0;
nRes = close(0) - open(0);
if (nRes == null) nRes = 1;
return nRes;
}
function HighLow() {
var nRes = 0;
nRes = high(0) - low(0);
if (nRes == null) nRes = 1;
return nRes;
}
I'm using the following code but I'm getting different results everyday. The results are consistent within each day (even when I restart eSignal) but when I start eSignal at the start of a new day then the output data is completely different from that of the previous day.
My first thought was that this was due to the first day 'dropping out' of my time template so I have been adding one day to the length of the template each morning (so that the start date is always the same) and still get the same problem.
To make sure that the code is looking at the same data each time I have been noting down the start date and time, the first date and time that an output is returned and the value returned by that output. It is the value of this output which changes everyday even though (as far as I can see) it is taking it's data from identical inputs to the previous day.
I don't think it matters what product/symbol you look at for this to happen but I have been looking at AT 1!-DT (i.e. Dax).
Does anyone have any ideas why this is happening as I am at a complete loss? Many thanks in advance.
The code is as follows:
var fpArray = new Array();
var bInit = false;
var ECO = 0.0;
var ECOprev = 0.0;
function preMain() {
setStudyTitle("XYZ");
setCursorLabelName("XYZ", 0);
setDefaultBarFgColor(Color.red, 0);
addBand(0, PS_SOLID, 1, Color.cyan);
var x=0;
fpArray[x] = new FunctionParameter("r", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(300);
}
fpArray[x] = new FunctionParameter("s", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(150);
}
}
var xEMA = null;
var xvEMA = null;
var LongStop = null;
var ShortStop = null;
function main(r, s) {
var nState = getBarState();
if (nState == BARSTATE_ALLBARS) {
if (r == null) r = 300;
if (s == null) s = 150;
}
if ( bInit == false ) {
xEMA = ema(s, ema(r, efsInternal("CloseOpen")));
xvEMA = ema(s, ema(r, efsInternal("HighLow")));
bInit = true;
}
if (getCurrentBarCount() < Math.max(r,s)) return;
if(xvEMA.getValue(0) != 0) {
ECO = 100 * (xEMA.getValue(0) / xvEMA.getValue(0));
}
if(xvEMA.getValue(0) != 0) {
ECOprev = 100 * (xEMA.getValue(0) / xvEMA.getValue(0));
}
if(xvEMA.getValue(0) != 0)
return 100 * (xEMA.getValue(0) / xvEMA.getValue(0));
else
return;
}
function CloseOpen() {
var nRes = 0;
nRes = close(0) - open(0);
if (nRes == null) nRes = 1;
return nRes;
}
function HighLow() {
var nRes = 0;
nRes = high(0) - low(0);
if (nRes == null) nRes = 1;
return nRes;
}