Announcement

Collapse
No announcement yet.

Series output or use of getSeries()

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

  • Series output or use of getSeries()

    Hi,

    How to get output as series object. whenever i use getSeries it doesn't output anything neither any error.? Please help me out in getting series output. efs code is as below.


    Regards
    Lucky

    PHP Code:
    var fpArray = new Array;

    function 
    preMain() {
    setPriceStudy(false);
    setStudyTitle("CCI EDIT");
    setCursorLabelName("CCI"0);
    setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(1,0);
    addBand(100PS_DASH1Color.grey,"Upper");
    addBand(-100PS_DASH1Color.grey,"Lower");

    var 
    x=0;

    fpArray[x] = new FunctionParameter("Length"FunctionParameter.NUMBER);
    with(fpArray[x++])
    {
    setName("CCI Period 1");
    setLowerLimit(1);
    setDefault(50);
    }
    fpArray[x] = new FunctionParameter("CCI1Source"FunctionParameter.STRING);
    with(fpArray[x++]){
    setName ("CCI 1 Source");
    addOption("open");
    addOption("high");
    addOption("low");
    addOption("close");
    addOption("hl2");
    addOption("oc2");
    addOption("hlc3");
    addOption("ohlc4");
    addOption("hlcc4");
    setDefault("close");
    }

    //End preMain()

    var xPrice null;
    var 
    xAvgPrice null;
    var 
    xCCI null;

    function 
    main(LengthCCI1Source){

    if(
    Length==nullLength 50;

    if(
    xPrice==nullxPrice = eval(CCI1Source)();
    if(
    xAvgPrice==nullxAvgPrice sma(Length,xPrice);

    if(
    xPrice.getValue(-Length)==null||xAvgPrice.getValue(-Length)==null) return;

    var 
    Sum 0;

    for (
    i=0i<Length-1i++){
    Sum += Math.abs(xPrice.getValue(-i)-xAvgPrice.getValue(0));
    }
    //if(Length != 0){
    var MeanDevPrice Sum/Length;
    var 
    CCI = (xPrice.getValue(0)-xAvgPrice.getValue(0))/(MeanDevPrice*0.015);
    //xCCI = getSeries(CCI);
    //var CCI = getSeries((xPrice.getValue(0)-xAvgPrice.getValue(0))/(MeanDevPrice*0.015));
    // } else CCI =0 ;
    return CCI;
    //return getValue.CCI(-2);
    }

  • #2
    Hello laxmicc,
    getSeries() does not create a series object, it can only be used to ensure that a series is returned when main()'s return is a series object, or if there are multiple returns it lets you pick which series that you want. I created a series object from your code for you and included notes about things that weren't right. See: getSeries() – EFS (esignal.com)? (https://efs.kb.esignal.com/hc/en-us/...947-getSeries-)

    Happy Trading,
    LetUsLearn

    PHP Code:
    // "use strict"; // I normally include this to make sure all vars are declared, but I can't with your fpArray "with" statements.
    var fpArray = []; // You had = new Array; it should be = new Array(); or like I always do: [];
    var xPrice null;
    var 
    xAvgPrice null;
    var 
    xCCI null;
    var 
    nLength null // You can't pass your main parameter "Length" to a function so you assign it to a global var.

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("CCI EDIT");
    setCursorLabelName("CCI"0);
    setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(1,0);
    addBand(100PS_DASH1Color.grey,"Upper");
    addBand(-100PS_DASH1Color.grey,"Lower");

    var 
    x=0;

    fpArray[x] = new FunctionParameter("Length"FunctionParameter.INTEGER); // You had NUMBER which could be 9.783
    with(fpArray[x++])
    {
    setName("CCI Period 1");
    setLowerLimit(1);
    setDefault(50);
    }
    fpArray[x] = new FunctionParameter("CCI1Source"FunctionParameter.STRING);
    with(fpArray[x++]){
    setName ("CCI 1 Source");
    addOption("open");
    addOption("high");
    addOption("low");
    addOption("close");
    addOption("hl2");
    addOption("oc2");
    addOption("hlc3");
    addOption("ohlc4");
    addOption("hlcc4");
    setDefault("close");
    }

    //End preMain()

    /*var xPrice = null; There's nothing wrong with this, but I prefer all global vars to be together at the top of the program.
    var xAvgPrice = null;
    var xCCI = null; */

    function main(LengthCCI1Source){
    if(
    getBarState() == BARSTATE_ALLBARS){ // The first 4 lines commented out below should be in an ALLBARS statement
    nLength Length// so that they are evaluated only once instead of on EVERY tick !!
    xPrice = eval(CCI1Source)(); // The ALLBARS statement is evaluated just once when the program first loads.
    xAvgPrice sma(LengthxPrice);
    xCCI efsInternal("GetCCI"xPricexAvgPricenLength);

    //if(Length==null) Length = 50; // This is being unnecessarily evaluated on every tick !

    //if(xPrice==null) xPrice = eval(CCI1Source)(); // This is being unnecessarily evaluated on every tick !
    //if(xAvgPrice==null) xAvgPrice = sma(Length,xPrice); // This is being unnecessarily evaluated on every tick !
    // The line below is being unnecessarily evaluated on every tick !
    //if(xPrice.getValue(-Length)==null||xAvgPrice.getValue(-Length)==null) return; // if(getCurrentBarCount < Length) return;
    }
    /* CCI is an EFS Keyword for a Commodity Channel Index, so you can't use it, use nCCI instead !!
    var Sum = 0;

    for (i=0; i<Length-1; i++){
    Sum += Math.abs(xPrice.getValue(-i)-xAvgPrice.getValue(0));
    }
    //if(Length != 0){
    var MeanDevPrice = Sum/Length;
    var CCI = (xPrice.getValue(0)-xAvgPrice.getValue(0))/(MeanDevPrice*0.015);
    //xCCI = getSeries(CCI);
    //var CCI = getSeries((xPrice.getValue(0)-xAvgPrice.getValue(0))/(MeanDevPrice*0.015));
    // } else CCI =0 ;
    return CCI;
    //return getValue.CCI(-2);

    */
    return xCCI.getValue(0);
    }

    function 
    GetCCI(xPricexAvgPricenLength){ // Code a function and have efsInternal create a series object from it.
    if(getCurrentBarCount nLength) return;
    var 
    MeanDevPrice null;
    var 
    nCCI null;
    var 
    Sum 0;
    for (var 
    0nLength 1i++){
    Sum += Math.abs(xPrice.getValue(-i) - xAvgPrice.getValue(0)); // There's nothing wrong with your spacing above,
    // I just prefer the extra spacing for clarity.
    MeanDevPrice Sum nLength;
    nCCI = (xPrice.getValue(0) - xAvgPrice.getValue(0)) / (MeanDevPrice 0.015);
    return 
    nCCI;
    }

    Comment


    • #3
      Oops,

      After I sent the above message, I decided to look at the chart full screen and seen that xCCI was calculating from the very first bar and yielding some useless numbers...very strange! When I looked at my function, I seen that getCurrentBarCount was lacking its function operator () in BOTH the function and the comment that I did above that. So, in the function add () to getCurrentBarCount so that you have getCurrentBarCount() and it will wait for the 50th bar before it begins to calculate xCCI.

      Comment

      Working...
      X