Announcement

Collapse
No announcement yet.

multiple ticker symbols in one indicator panel

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

  • multiple ticker symbols in one indicator panel

    The following efs code works fine, I am mainly concerned about efficiency. This indicator panel plots four different tickers and it does not use any compute_on_close command. This panel is used under a 3-minute bar chart of an emini (AB or ES).

    Will this efs get executed every time any one of the tickers changes value or when Price changes in the main panel or is one of them the 'master'?

    Should I remove statements like:
    if (vQT == null) return;

    A third question: is the *1 on a statement like
    var vT = close(0, 1, "$TRIN")*1;
    necessary? I do it because it was done in the library example.

    PHP Code:
    /* 
         Larry's breadth panel
         four indicators: 
           NY Tick       blue bars
           Nasdaq Tick   green line
           $ADD          blue line
           NY TRIN       purple line (inverted)
         some of this code borrowed from TickExtremes.efs in eSignal library
    */

    function preMain() {
        
    setPriceStudy(false);
        
    setStudyTitle("BRED4");
      
    //  deleted some code here for brevity
      //     just sets colors,plottype...  
        
    setStudyMax(1500);
        
    setStudyMin(-1500);
    }

    var 
    vColor Color.RGB(101,150,220);
    var 
    vLoaded false;
    var 
    barH null;
    var 
    barL null;
    var 
    vNum 150;         // limits how many bars can be drawn
    var BarCntr 0;
    var 
    vSum 0;
     
    function 
    main() {   

        if (
    vLoaded == false) {
            
    addBand1000PS_SOLID1Color.grey"top");
            
    addBand(    0PS_SOLID1Color.black"zero");
            
    addBand(-1000PS_SOLID1Color.grey"bottom");
            
    vLoaded true;
        }
        
        var 
    vNT close(01"$TICK")*1;
        if (
    vNT == null) return;


        if (
    getBarState() == BARSTATE_NEWBAR) {
            if (
    BarCntr vNum) {
                
    BarCntr += 1;
            } else {
                
    BarCntr 0;
            }
            
    barH vNT;
            
    barL vNT;
        }
        
    // NY tick is drawn as bars 
    // the vNT value returned below is for esignal to draw the horizontal tick marks    

        
    if (isTick() == true || isRawTick() == true) {
            
    barH Math.max(barHvNT);
            
    barL Math.min(barLvNT);
        } else {
            var 
    high(01"$tick")*1;
            if (
    == null) return;
            var 
    low(01"$tick")*1;
            if (
    == null) return;
            
    barH Math.max(barHhvNT);
            
    barL Math.min(barLlvNT);
        }    
        
    drawLineRelative(0barL0barHPS_SOLID2vColor"bar" BarCntr);

        var 
    vQT close(01"$TICKQ")*1;
        if (
    vQT == null) return;

        var 
    vA close(01"$ADD")*1;
        if (
    vA == null) return;

        var 
    vT close(01"$TRIN")*1;
        if (
    vT == null) return;
        
    // invert trin so it sorta fits the same scale
        
    var vR =  (1.0 vT) * 1667;

        return new Array(
            
    vNT,
            
    vQT,
            
    vA,
            
    vR
        
    );

    }
    //    END     // 

  • #2
    domecat
    In terms of efficiency it should be fine. However to retrieve the values of the other symbols you are using EFS1 functions [for example close(0,1,"$TICK")] which do not maintain syncronization between the symbols. So if any of the other symbols have a zero volume bar or are not trading at that time (this will happen for example if you are using a Time Template set to ES or AB trading hours) you will get incorrect results. If you run a search in this Bulletin Board on this subject you will find several explanations and examples as to why this happens.
    This is where EFS2 comes into play as it now allows you to maintain all the symbols used in an efs correctly syncronized to each other.
    Here is your same code written using EFS2 functions to retrieve the values of the other symbols. Notice that I create the series for those symbols only once inside the vLoaded statement and that I use the sym() function to call the price series for the external symbols. Then I retrieve the values I need with the getValue() method.
    As an aside the enclosed formula should be more efficient than the one you posted even if it actually performs much more advanced functions.
    For more information and examples on the sym() function see the EFS2 Function Reference in the EFS KnowledgeBase.
    Alex

    PHP Code:
    /* 
         Larry's breadth panel
         four indicators: 
           NY Tick       blue bars
           Nasdaq Tick   green line
           $ADD          blue line
           NY TRIN       purple line (inverted)
         some of this code borrowed from TickExtremes.efs in eSignal library
    */
     
    function preMain() {
        
    setPriceStudy(false);
        
    setStudyTitle("BRED4");
      
    //  deleted some code here for brevity
      //     just sets colors,plottype...  
        
    setStudyMax(1500);
        
    setStudyMin(-1500);
    }
     
    var 
    vColor Color.RGB(101,150,220);
    var 
    vLoaded false;
    var 
    barH null;
    var 
    barL null;
    var 
    vNum 150;         // limits how many bars can be drawn
    var BarCntr 0;
    var 
    vSum 0;
    //ACM added following global variables
    var vCloseTICK null;
    var 
    vHighTICK null;
    var 
    vLowTICK null;
    var 
    vCloseTICKQ null;
    var 
    vCloseADD null;
    var 
    vCloseTRIN null;
    //end section added by ACM
     
    function main() {   
     
        if (
    vLoaded == false) {
            
    addBand1000PS_SOLID1Color.grey"top");
            
    addBand(    0PS_SOLID1Color.black"zero");
            
    addBand(-1000PS_SOLID1Color.grey"bottom");
            
    //ACM added the following section
            
    vCloseTICK close(sym("$tick"));
            
    vHighTICK high(sym("$tick"));
            
    vLowTICK low(sym("$tick"));
            
    vCloseTICKQ close(sym("$tickq"));
            
    vCloseADD close(sym("$add"));
            
    vCloseTRIN close(sym("$trin"));
            
    //end section added by ACM   
            
    vLoaded true;
        }
     
        var 
    vNT vCloseTICK.getValue(0);//ACM modified
        
    if (vNT == null) return;
     

        if (
    getBarState() == BARSTATE_NEWBAR) {
            if (
    BarCntr vNum) {
                
    BarCntr += 1;
            } else {
                
    BarCntr 0;
            }
            
    barH vNT;
            
    barL vNT;
        }
        
    // NY tick is drawn as bars 
    // the vNT value returned below is for esignal to draw the horizontal tick marks    
     
        
    if (isTick() == true || isRawTick() == true) {
            
    barH Math.max(barHvNT);
            
    barL Math.min(barLvNT);
        } else {
            var 
    vHighTICK.getValue(0);//ACM modified
            
    if (== null) return;
            var 
    vLowTICK.getValue(0);//ACM modified
            
    if (== null) return;
            
    barH Math.max(barHhvNT);
            
    barL Math.min(barLlvNT);
        }    
        
    drawLineRelative(0barL0barHPS_SOLID2vColor"bar" BarCntr);
     
        var 
    vQT vCloseTICKQ.getValue(0);//ACM modified
        
    if (vQT == null) return;
     
        var 
    vA vCloseADD.getValue(0);//ACM modified
        
    if (vA == null) return;
     
        var 
    vT vCloseTRIN.getValue(0);//ACM modified
        
    if (vT == null) return;
        
    // invert trin so it sorta fits the same scale
        
    var vR =  (1.0 vT) * 1667;
     
        return new Array(
            
    vNT,
            
    vQT,
            
    vA,
            
    vR
        
    );
     
    }
    //    END     // 

    Comment


    • #3
      domecat

      Should I remove statements like:
      if (vQT == null) return;


      I don't believe you should. Null checks ensure that you are using valid data in your calculations

      A third question: is the *1 on a statement like
      var vT = close(0, 1, "$TRIN")*1;
      necessary? I do it because it was done in the library example.


      You would multiply by 1 if you were converting a string to a value. In this case close(0, 1, "$TRIN") is not a string so multiplying by 1 is not necessary.
      Alex

      Comment


      • #4
        Alexis thanks for the fixes you suggested. Here is the
        new full version if anyone is interested. Incidentally this
        version makes a more accurate bar chart of $TICK than
        before.

        PHP Code:
        /* 
             Larry's breadth panel
             four indicators: 
               NY Tick       blue bars
               Nasdaq Tick   green line
               $ADD          blue line
               NY TRIN       purple line (inverted)
             some of this code borrowed from TickExtremes.efs in eSignal library
        */
         
        function preMain() {
            
        setPriceStudy(false);
            
        setStudyTitle("BRED4");

            
        setCursorLabelName("TickNY"0);
            
        setPlotType(PLOTTYPE_FLATLINES0); 
            
        setDefaultBarStyle(PS_SOLID0);
            
        setDefaultBarThickness(20);
            
        setDefaultBarFgColor(Color.blue0);   

            
        setCursorLabelName("TickQ"1);
            
        setPlotType(PLOTTYPE_LINE1);
            
        setDefaultBarStyle(PS_SOLID1);
            
        setDefaultBarThickness(21);
            
        setDefaultBarFgColor(Color.green1);

            
        setCursorLabelName("$ADD"2);
            
        setDefaultBarStyle(PS_SOLID2);
            
        setDefaultBarFgColor(Color.blue2);
            
        setDefaultBarThickness(22);
            
        setPlotType(PLOTTYPE_LINE2);

            
        setCursorLabelName("RTrin"3);
            
        setDefaultBarStyle(PS_SOLID3);
            
        setDefaultBarFgColor(Color.magenta3);
            
        setDefaultBarThickness(23);
            
        setPlotType(PLOTTYPE_LINE3);
            
            
        setStudyMax(1500);
            
        setStudyMin(-1500);
        }
         
        var 
        vColor Color.RGB(101,150,220);
        var 
        vLoaded false;
        var 
        barH null;
        var 
        barL null;
        var 
        vNum 150;         // limits how many bars can be drawn
        var BarCntr 0;
        var 
        vSum 0;
        //ACM added following global variables
        var vCloseTICK null;
        var 
        vHighTICK null;
        var 
        vLowTICK null;
        var 
        vCloseTICKQ null;
        var 
        vCloseADD null;
        var 
        vCloseTRIN null;
        //end section added by ACM
         
        function main() {   
         
            if (
        vLoaded == false) {
                
        addBand1000PS_SOLID1Color.grey"top");
                
        addBand(    0PS_SOLID1Color.black"zero");
                
        addBand(-1000PS_SOLID1Color.grey"bottom");
                    
        //ACM added the following section
                
        vCloseTICK  close(sym("$tick"));
                
        vHighTICK   high(sym("$tick"));
                
        vLowTICK    low(sym("$tick"));
                
        vCloseTICKQ close(sym("$tickq"));
                
        vCloseADD   close(sym("$add"));
                
        vCloseTRIN  close(sym("$trin"));
                    
        //end section added by ACM   
                
        vLoaded true;
            }
         
            var 
        vNT vCloseTICK.getValue(0);        //ACM modified
            
        if (vNT == null) return;
         

            if (
        getBarState() == BARSTATE_NEWBAR) {
                if (
        BarCntr vNum) {
                    
        BarCntr += 1;
                } else {
                    
        BarCntr 0;
                }
                
        barH vNT;
                
        barL vNT;
            }
            
        // NY tick is drawn as bars 
        // the vNT value returned below is for esignal to draw the horizontal tick marks    
         
            
        if (isTick() == true || isRawTick() == true) {
                
        barH Math.max(barHvNT);
                
        barL Math.min(barLvNT);
            } else {
                var 
        vHighTICK.getValue(0);          //ACM modified
                
        if (== null) return;
                var 
        vLowTICK.getValue(0);           //ACM modified
                
        if (== null) return;
                
        barH Math.max(barHhvNT);
                
        barL Math.min(barLlvNT);
            }    
            
        drawLineRelative(0barL0barHPS_SOLID2vColor"bar" BarCntr);
         
            var 
        vQT vCloseTICKQ.getValue(0);        //ACM modified
            
        if (vQT == null) return;
         
            var 
        vA vCloseADD.getValue(0);           //ACM modified
            
        if (vA == null) return;
         
            var 
        vT vCloseTRIN.getValue(0);          //ACM modified
            
        if (vT == null) return;
            
        // invert trin so it sorta fits the same scale
            
        var vR =  (1.0 vT) * 1667;
         
            return new Array(
                
        vNT,
                
        vQT,
                
        vA,
                
        vR
            
        );
         

        Comment

        Working...
        X