Hi,
Need some help here to try and understand what is happening here.
While I have had reasonable success fixing realtime update problems with certain efs files, this one is giving me problems. I believe that it is the multiple getBarStates that is causing the problem. Can it be done?
Here is the code from TS support--
Thanks,
Alex
/************************************************** *****************
Provided By : TS Support, LLC for eSignal. (c) Copyright 2002
************************************************** ******************/
function preMain()
{
setStudyTitle("Demand Index");
setCursorLabelName("Demand Index", 0);
setDefaultBarFgColor(Color.blue, 0);
addBand(0, PS_SOLID, 1, Color.green);
}
vAvgTR = new Array();
var VolAvg_1 = 0;
var WghtClose_1 = 0;
var BuyPres_1 = 0;
var SellPres_1 = 0;
var WghtClose = 0;
var VolAvg = 0;
var BuyPres = 0;
var SellPres = 0;
function main(Length)
{
if(Length == null)
Length = 5;
var i;
var vSum = 0.0;
var hh2, ll2;
var WtCRatio = 1, VolRatio = 1, BuyP = 1, SellP = 1, Sign = 1, Constant = 1, BuyPres = 1, SellPres = 1, TempDI = 1, DMI = 1, WghtClose = 0, AvgTR = high() - low(), VolAvg = volume();
if(getCurrentBarIndex() - getOldestBarIndex() == 1)
{
for(i = -Length + 1; i >= 0; i++)
vSum += volume(i);
VolAvg = vSum / Length;
}
WghtClose = (high() + low() + 2 * close()) * .25;
if(high() > high(-1))
hh2 = high();
else
hh2 = high(-1);
if(low() < low(-1))
ll2 = low();
else
ll2 = low(-1);
if (getBarState() == BARSTATE_NEWBAR)
{
for(i = Length - 2; i >= 0; i--)
vAvgTR[i + 1] = vAvgTR[i]
vAvgTR[0] = hh2 - ll2;
}
vSum = 0;
for(i = 0; i < Length; i++)
vSum += vAvgTR[i]
AvgTR = vSum / Length;
VolAvg = ((VolAvg_1 * (Length - 1)) + volume()) / Length;
if(WghtClose != 0 && WghtClose_1 != 0 && AvgTR != 0 && VolAvg != 0)
{
WtCRatio = (WghtClose - WghtClose_1) / Math.min(WghtClose, WghtClose_1) ;
VolRatio = volume() / VolAvg;
Constant = ((WghtClose * 3) / AvgTR) * Math.abs(WtCRatio);
if(Constant > 88)
Constant = 88;
Constant = VolRatio / Math.exp(Constant);
if(WtCRatio > 0)
{
BuyP = VolRatio;
SellP = Constant;
}
else
{
BuyP = Constant;
SellP = VolRatio;
}
BuyPres = ((BuyPres_1 * (Length - 1)) + BuyP) / Length;
SellPres = ((SellPres_1 * (Length - 1)) + SellP) / Length;
TempDI = +1;
if(SellPres > BuyPres)
{
Sign = -1;
if(SellPres != 0)
TempDI = BuyPres / SellPres;
}
else
{
Sign = +1;
if(BuyPres != 0)
TempDI = SellPres / BuyPres;
}
TempDI = TempDI * Sign;
if(TempDI < 0)
DMI = -1 - TempDI;
else
DMI = +1 - TempDI;
}
if (getBarState() == BARSTATE_NEWBAR)
{
WghtClose_1 = WghtClose;
if(getCurrentBarIndex() - getOldestBarIndex() > 5){
BuyPres_1 = BuyPres;
SellPres_1 = SellPres;
}
VolAvg_1 = VolAvg;
}
return DMI;
}
Need some help here to try and understand what is happening here.
While I have had reasonable success fixing realtime update problems with certain efs files, this one is giving me problems. I believe that it is the multiple getBarStates that is causing the problem. Can it be done?
Here is the code from TS support--
Thanks,
Alex
/************************************************** *****************
Provided By : TS Support, LLC for eSignal. (c) Copyright 2002
************************************************** ******************/
function preMain()
{
setStudyTitle("Demand Index");
setCursorLabelName("Demand Index", 0);
setDefaultBarFgColor(Color.blue, 0);
addBand(0, PS_SOLID, 1, Color.green);
}
vAvgTR = new Array();
var VolAvg_1 = 0;
var WghtClose_1 = 0;
var BuyPres_1 = 0;
var SellPres_1 = 0;
var WghtClose = 0;
var VolAvg = 0;
var BuyPres = 0;
var SellPres = 0;
function main(Length)
{
if(Length == null)
Length = 5;
var i;
var vSum = 0.0;
var hh2, ll2;
var WtCRatio = 1, VolRatio = 1, BuyP = 1, SellP = 1, Sign = 1, Constant = 1, BuyPres = 1, SellPres = 1, TempDI = 1, DMI = 1, WghtClose = 0, AvgTR = high() - low(), VolAvg = volume();
if(getCurrentBarIndex() - getOldestBarIndex() == 1)
{
for(i = -Length + 1; i >= 0; i++)
vSum += volume(i);
VolAvg = vSum / Length;
}
WghtClose = (high() + low() + 2 * close()) * .25;
if(high() > high(-1))
hh2 = high();
else
hh2 = high(-1);
if(low() < low(-1))
ll2 = low();
else
ll2 = low(-1);
if (getBarState() == BARSTATE_NEWBAR)
{
for(i = Length - 2; i >= 0; i--)
vAvgTR[i + 1] = vAvgTR[i]
vAvgTR[0] = hh2 - ll2;
}
vSum = 0;
for(i = 0; i < Length; i++)
vSum += vAvgTR[i]
AvgTR = vSum / Length;
VolAvg = ((VolAvg_1 * (Length - 1)) + volume()) / Length;
if(WghtClose != 0 && WghtClose_1 != 0 && AvgTR != 0 && VolAvg != 0)
{
WtCRatio = (WghtClose - WghtClose_1) / Math.min(WghtClose, WghtClose_1) ;
VolRatio = volume() / VolAvg;
Constant = ((WghtClose * 3) / AvgTR) * Math.abs(WtCRatio);
if(Constant > 88)
Constant = 88;
Constant = VolRatio / Math.exp(Constant);
if(WtCRatio > 0)
{
BuyP = VolRatio;
SellP = Constant;
}
else
{
BuyP = Constant;
SellP = VolRatio;
}
BuyPres = ((BuyPres_1 * (Length - 1)) + BuyP) / Length;
SellPres = ((SellPres_1 * (Length - 1)) + SellP) / Length;
TempDI = +1;
if(SellPres > BuyPres)
{
Sign = -1;
if(SellPres != 0)
TempDI = BuyPres / SellPres;
}
else
{
Sign = +1;
if(BuyPres != 0)
TempDI = SellPres / BuyPres;
}
TempDI = TempDI * Sign;
if(TempDI < 0)
DMI = -1 - TempDI;
else
DMI = +1 - TempDI;
}
if (getBarState() == BARSTATE_NEWBAR)
{
WghtClose_1 = WghtClose;
if(getCurrentBarIndex() - getOldestBarIndex() > 5){
BuyPres_1 = BuyPres;
SellPres_1 = SellPres;
}
VolAvg_1 = VolAvg;
}
return DMI;
}
Comment