Announcement

Collapse
No announcement yet.

multiple symbol efs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • multiple symbol efs

    I'm trying to build a multi symbol efs.
    What it does is look at three symbols. For each symbol if the C>prev C then a value of "1" is assigned, if C<prev C a value of "-1", and if there is no change a value of "0" is assigned. Then I add up the values of the three symbols. Then a mov ave is taken of the indicator. This is repeated every bar.

    It is working, sort of. Once you load it, it plots fine going forward as new data comes in. The problem is that it won't load and plot any history prior to the time it is loaded.

    Could one of you efs wizards kindly provide some help in getting it to load and plot the same amount of data loaded in the chart?

    The efs is below:

    var vMAArray = new Array();

    function preMain() {
    setStudyTitle("SMH TICK");
    setCursorLabelName("MA of SMH TICK",0);
    setCursorLabelName("SMH TICK",1);

    // have to put in the lines

    var fp1 = new FunctionParameter("nMALength", FunctionParameter.NUMBER);
    fp1.setName("MA-Length"); //optional name to show in Edit Studies
    fp1.setLowerLimit(1);
    fp1.setDefault(5); //Edit this value to set a new default

    var fp2 = new FunctionParameter("sColor", FunctionParameter.COLOR); //for the symbol
    fp2.setName("Symbol-Color"); //optional name to show in Edit Studies
    fp2.setDefault(Color.blue); //default color in Edit Studies

    var fp3 = new FunctionParameter("maColor", FunctionParameter.COLOR); //for the Moving Average
    fp3.setName("MA-Color"); //optional name to show in Edit Studies
    fp3.setDefault(Color.red); //default color in Edit Studies

    var fp4 = new FunctionParameter("sWidth", FunctionParameter.NUMBER); //for Symbol width
    fp4.setName("Symbol-Width"); //name to show in Edit Studies
    fp4.setDefault(1); //default width in Edit Studies

    var fp5 = new FunctionParameter("maWidth", FunctionParameter.NUMBER);
    fp4.setName("MA-Width"); //optional name to show in Edit Studies
    fp5.setDefault(1); //default width

    }

    function main(vINTC,vAMAT,vTXN,nMALength,sColor,maColor,sWi dth,maWidth) {
    if(getCurrentBarIndex() != 0)
    return;

    // if current bar close > prev close then assign value of "1", if < prev close, then value -"-1", if same, value = "0"
    // do same for other signals
    if (close(0,"INTC") > close(-1, "INTC")) {
    vINTC = 1; }
    if (close(0,"INTC") < close(-1, "INTC")) {
    vINTC = -1; }
    if (close(0,"INTC") == close(-1, "INTC")) {
    vINTC = 0; }

    if (close(0,"AMAT") > close(-1, "AMAT")) {
    vAMAT = 1; }
    if (close(0,"AMAT") < close(-1, "AMAT")) {
    vAMAT = -1; }
    if (close(0,"AMAT") == close(-1, "AMAT")) {
    vAMAT = 0; }

    if (close(0,"TXN") > close(-1, "TXN")) {
    vTXN = 1; }
    if (close(0,"TXN") < close(-1, "TXN")) {
    vTXN = -1; }
    if (close(0,"TXN") == close(-1, "TXN")) {
    vTXN = 0; }


    vSMHtick = vINTC+vAMAT+vTXN; // sum up the three components


    // now apply a mov ave
    var nBarState = getBarState();

    if (nBarState == BARSTATE_NEWBAR) vMAArray.unshift(vSMHtick); //inserts array element to the front of the array

    vMAArray[0] = vSMHtick;

    if (vMAArray[nMALength-1] != null) {

    var vSum = 0;

    for (i=0; i <= nMALength-1; i++) {
    vSum += vMAArray[i];
    }

    var vMA = vSum / nMALength;

    }

    setBarFgColor(sColor, 0); //the number assigns the color to the first item in the return
    setBarFgColor(maColor, 1);
    setBarThickness(sWidth,0)
    setBarThickness(maWidth,1)


    return new Array (vMA,vSMHtick); // plot the indicator and the mov ave
    }

  • #2
    bigtee
    Delete the following lines at the beginning of main which are limiting the return to the current bar only
    if(getCurrentBarIndex() != 0)
    return;

    Alex

    Comment


    • #3
      Thank you Alex. It works great now. Most appreciated.

      bigtee

      Comment

      Working...
      X