esignal easy formula help please

ok, i'm not much of a programmer. i understand some basics, but that's about it.

i made a formula for esignal that works, but it is plotting it in the wrong place. i made a simple formula to explain my problem:

function preMain()
{
setPriceStudy(true);
setCursorLabelName("5sma");
}
function main(Price, Periods)
{
var close = getValue("Close",0);
var close1 = getValue("Close",1);
var close2 = getValue("Close",2);
var close3 = getValue("Close",3);
var close4 = getValue("Close",4);

var ma = ((close+close1+close2+close3+close4) / 5);

return ma;
}

the above formula calculates a simple 5 period moving average. however, when i have esignal do a 5sma on its own and i run my formula, my values are the same, but my 5sma gets plotted 5 days ago. lol all i want is to get the above formula to line up exactly like a 5sma done by esignal.

once i see what my problem is, i will go back and fix my original idea.

thanks
 
here's a chart that shows my problem..

the black line is a 5sma done automatically by esignal.

the blue line is a 5sma done by the formula i made.

i just want them to match up, but for some reason my formula is lagging.
 

Attachments

Quote from Runningbear:

I like your blue one better, it appears to predict the future:D :D
hehe that's because my blue line is based on recent bars, but then it is getting shifted to the left by accident. :mad: :confused:
 
the getValue() function's 2nd parameter should be negative if you want 'bars ago'. It's positive if you want 'bars in the future', which is why your SMA is charted 5 bars behind the current price (since eSignal cannot see the future just yet, that's coming in version 8.0 ;) ).

try:

PHP:
getValue("close", 0)
getValue("close", -1)
getValue("close", -2)
etc ....
 
Quote from Dion Loy:

the getValue() function's 2nd parameter should be negative if you want 'bars ago'. It's positive if you want 'bars in the future', which is why your SMA is charted 5 bars behind the current price (since eSignal cannot see the future just yet, that's coming in version 8.0 ;) ).

try:

PHP:
getValue("close", 0)
getValue("close", -1)
getValue("close", -2)
etc ....
dude! thank you so much! that's all i needed! all i had to do was change those positive numbers to negative........this is great.

THANKS! :D :cool:
 
GG

Esignal will help you write anything you want. I requested some custom Keltner channels and they sent me the formula a few days later. Inserted it in my formulas library and bingo.
 
Quote from easyrider:

GG

Esignal will help you write anything you want. I requested some custom Keltner channels and they sent me the formula a few days later. Inserted it in my formulas library and bingo.
how do you request them?
 
Back
Top