Announcement

Collapse
No announcement yet.

SMA in excel efs problem help

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SMA in excel efs problem help

    hi im trying to get the moving average value in excel with this efs for a symbol ((ES U2)-($SPX)) that i am charting in esginal and am having problems getting it to work. this works for any normal symbol like say AAPL but not for ((ES M2)-($SPX))

    var ddeSMA10 = null;
    var vMA = new MAStudy(10, 0, "Close", MAStudy.SIMPLE);

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("DDE SMA10");
    setShowCursorLabel(false);
    }

    function main() {
    if (ddeSMA10 == null) {
    var sName = "SMA10" + getSymbol() + getInterval();
    sName = sName.replace("$", ""); // remove $ from string
    sName = sName.replace("#", ""); // remove # from string
    sName = sName.replace("-", "");
    sName = sName.replace("(", "");
    sName = sName.replace(")", "");
    sName = sName.replace(" ", "_") // replace space with underscore
    debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName);
    ddeSMA10 = new DDEOutput(sName);
    }

    var vSMA10 = vMA.getValue(MAStudy.MA);
    if (vSMA10 == null) return;

    ddeSMA10.set(vSMA10);

    return vSMA10;
    }

  • #2
    Re: SMA in excel efs problem help

    JasonR8
    JavaScript's replace() method only replaces the first occurrence of a defined string and not every occurrence. To replace every occurrence you must provide the replace() method a regular expression with a global modifier eg /mystring/g to replace all instances of mystring or /mystring/gi to replace all instances of mystring regardless of case. Note that you must escape special characters within your regular expression eg /\$/g
    Enclosed below is your script modified to force replacing each occurrence of the strings you defined
    Alex

    Code:
    var ddeSMA10 = null;
    var vMA = new MAStudy(10, 0, "Close", MAStudy.SIMPLE);
    
    function preMain() {
        setPriceStudy(true);
        setStudyTitle("DDE SMA10");
        setShowCursorLabel(false);
    }
    
    function main() {
        if (ddeSMA10 == null) {
            var sName = "SMA10" + getSymbol() + getInterval();
            sName = sName.replace(/\$/g, ""); // remove $ from string
            sName = sName.replace(/\#/g, ""); // remove # from string
            sName = sName.replace(/\-/g, "");
            sName = sName.replace(/\(/g, "");
            sName = sName.replace(/\)/g, "");
            sName = sName.replace(/\ /g, "_") // replace space with underscore
            debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName);
            ddeSMA10 = new DDEOutput(sName);
        }
    
        var vSMA10 = vMA.getValue(MAStudy.MA);
        if (vSMA10 == null) return;
    
        ddeSMA10.set(vSMA10);
    
        return vSMA10;
    }

    Originally posted by JasonR8
    hi im trying to get the moving average value in excel with this efs for a symbol ((ES U2)-($SPX)) that i am charting in esginal and am having problems getting it to work. this works for any normal symbol like say AAPL but not for ((ES M2)-($SPX))

    var ddeSMA10 = null;
    var vMA = new MAStudy(10, 0, "Close", MAStudy.SIMPLE);

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("DDE SMA10");
    setShowCursorLabel(false);
    }

    function main() {
    if (ddeSMA10 == null) {
    var sName = "SMA10" + getSymbol() + getInterval();
    sName = sName.replace("$", ""); // remove $ from string
    sName = sName.replace("#", ""); // remove # from string
    sName = sName.replace("-", "");
    sName = sName.replace("(", "");
    sName = sName.replace(")", "");
    sName = sName.replace(" ", "_") // replace space with underscore
    debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName);
    ddeSMA10 = new DDEOutput(sName);
    }

    var vSMA10 = vMA.getValue(MAStudy.MA);
    if (vSMA10 == null) return;

    ddeSMA10.set(vSMA10);

    return vSMA10;
    }

    Comment

    Working...
    X