esignal easy formula help please

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

  1. 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. 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.
     
  3. I like your blue one better, it appears to predict the future:D :D
     
  4. 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:
     
  5. Miki

    Miki

    Accidental Holy Grail – I like that.
    :p
     
  6. Dion Loy

    Dion Loy eSignal

    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. 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:
     
  8. 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. how do you request them?
     
  10. wild

    wild