ET News & Sponsor Info
General Topics
Markets
Technical Topics
Brokerage Firms
Company Specific
Tools of the Trade
Trading for a Living
Community Lounge
Site Support

# esignal easy formula help please

Discussion in 'Trading Software' started by Gordon Gekko, Nov 26, 2002.

1. ### Gordon Gekko

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

2. ### Gordon Gekko

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.

File size:
5.2 KB
Views:
84
3. ### Runningbear

I like your blue one better, it appears to predict the future

4. ### Gordon Gekko

hehe that's because my blue line is based on recent bars, but then it is getting shifted to the left by accident.

5. ### Miki

Accidental Holy Grail â I like that.

6. ### Dion LoyeSignal

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 .... ```

7. ### Gordon Gekko

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!

8. ### 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.

9. ### Gordon Gekko

how do you request them?

10. ### wild

ET IS FREE FOR TRADERS BECAUSE OF THE FINANCIAL SUPPORT FROM THESE SPONSORS: