Java formula Esignal

chump

Senior member
2,212 274
All I know about programming is what I can see on the remote control for the TV so I am looking for some help.

Basically I want to adapt the ema formulas in esignal to create the ability to period shift emas (offset emas). Esignal use java and I assume this is not coffee they are talking about.

If anyone is will ing to help I can do a cut and paste of the ema formula in esignal for you to adapt.

Not being lazy, just each to there own and I would have to start learning this stuff from scratch which is a bit tedious given my needs.

Cheers
 

FTSE Beater

Experienced member
1,518 5
Hi Chump

It shouldn't be too difficult. If you would be kind enough to post up the formula, I'll have a look at it for you.
Are you trying to display the lines or use the values in some kind of formula :confused:
 

chump

Senior member
2,212 274
FT,
Thanks for your offer of help.Much appreciated.This is the formula for a 15ema in esignal. I am trying to find out how to adapt this so that I can move/offset the ema either backwards or forwards say x periods where x can be 3 or any number for that matter.


function preMain() {
setPriceStudy(true);
}

var dLastMA = 0.0;
var dThisMA = 0.0;
var dPercent = 0.0;
var dCount = 0;
var bPrimed = false;


function main(nInputLength) {
if(nInputLength == null)
nInputLength = 15;

var nBarState = getBarState();
var i;
var dValue;
var dSum = 0.0;

if(nBarState == BARSTATE_ALLBARS) {
// reset!
dPercent = (2.0 / (nInputLength + 1.0));
dLastMA = 0.0;
dThisMA = 0.0;
dCount = 0;
}

if(nBarState == BARSTATE_NEWBAR) {
dLastMA = dThisMA;
}
dThisMA = dLastMA;

if(bPrimed == false) {
dValue = getValue("Close", 0, -nInputLength);
if(dValue == null)
return;

for(i = 0; i < nInputLength; i++) {
dSum += dValue;
}

dLastMA = dSum / nInputLength;
dThisMA = dLastMA;

bPrimed = true;
} else {
dValue = getValue("Close");
if(dValue == null)
return;

dThisMA = (dValue - dLastMA) * dPercent + dLastMA;
}


return dThisMA;

}


Cheers
 

FTSE Beater

Experienced member
1,518 5
Hi Chump

I've had a look at it, and this is what I've come up with

function preMain() {
setPriceStudy(true);
}

var dLastMA = 0.0;
var dThisMA = 0.0;
var dPercent = 0.0;
var dCount = 0;
var bPrimed = false;


function main(nInputLength) {
if(nInputLength == null)
nInputLength = 15;

var nBarState = getBarState();
var i;
var dValue;
var dSum = 0.0;

if(nBarState == BARSTATE_ALLBARS) {
// reset!
dPercent = (2.0 / (nInputLength + 1.0));
dLastMA = 0.0;
dThisMA = 0.0;
dCount = 0;
}

if(nBarState == BARSTATE_NEWBAR) {
dLastMA = dThisMA;
}
dThisMA = dLastMA;

if(bPrimed == false) {
dValue = getValue("Close", 0, -nInputLength);
if(dValue == null)
return;

for(i = 0; i < nInputLength; i++) {
dSum += dValue;
}

dLastMA = dSum / nInputLength;
dThisMA = dLastMA;

bPrimed = true;
} else {
dValue = getValue("Close",10);
if(dValue == null)
return;

dThisMA = (dValue - dLastMA) * dPercent + dLastMA;
}


return dThisMA;

}

The only bit I added was the bit in red above. You'll have to turn that into a variable, which I can't remember how to do :eek:

HTH :)
 

chump

Senior member
2,212 274
Ft,
Thanks for the help. I will give it a try and see what it looks like.

Cheers
 
 
AdBlock Detected

We get it, advertisements are annoying!

But it's thanks to our sponsors that access to Trade2Win remains free for all. By viewing our ads you help us pay our bills, so please support the site and disable your AdBlocker.

I've Disabled AdBlock