Announcement

Collapse
No announcement yet.

Removing Selected Lines With Multiple Studies

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

  • Removing Selected Lines With Multiple Studies

    I have three studies plotting a line on the price chart. When a new bar comes in, each study does its calculations, and then plots a line extension from the old bar to the new bar. I do this using

    drawLineRelative(-j,aWghtPrice[j],-(j-1),aWghtPrice[j-1],PS_SOLID,2,Color.blue,gID());

    So, I end up with a bunch of different "lines." I come up with the tag identifier using

    function gID() {return grID++};

    Now I want to remove only the line from the second study and refresh it by redoing all the calculations and replotting. I could keep track of all the individual gID() numbers for this line and then removing the line with removeLine(...) inside some loop.

    But, isn't there an easier way to remove just this one line? The clearLines() statement would remove all the lines -- even those from the other two studies. Right?

  • #2
    Hello AssetHound,

    The first question that comes to mind is why are you using drawLineRelative() to plot each study? If you are calculating a value for each study that has a value for each bar it would be easier to plot the studies from the return statement rather that drawing a collection of line segments from bar to bar.

    At any rate, to simplify the process of removing one of the drawnLine studies I would recommend assigning a series of unique tag names for each of the three drawnLine studies. Concatenate to the gID() number a string that identifies each set. For example, try using something like "LineA_" + gID() for the tag name parameter. Use "LineB_" and "LineC_" for the other two sets. Then you can add a Boolean function parameter for each of the 3 drawLine studies to control the display of each. When one is set to false from Edit studies you can prevent that drawLine study from being drawn. This process does require you to run a loop and call removeLine() to remove each segment. Changing the function parameter forces a reload of the study which will see a false value for the parameter and not redraw that corresponding line. Here's the basic idea for one of the the lines.

    PHP Code:
    function preMain() {
        
    setStudyTitle("test");
        
    setPriceStudy(true);
        
        var 
    fp1 = new FunctionParameter("bLineA"FunctionParameter.BOOLEAN);
            
    fp1.setName("Display Line A");
            
    fp1.setDefault(true);
    }


    function 
    main(bLineA) {
        
        
    //  ... code logic for aWghtPrice array
        
        
    if (bLineA == true) {
            
    drawLineRelative(-j,aWghtPrice[j],-(j-1),aWghtPrice[j-1],PS_SOLID,2,Color.blue,"LineA_"+gID());
        }
        
        return;
    }

    function 
    gID() {return grID++}; 
    You wouldn't necessarily need to add the "LineA_" string to the tag name parameter in the above example. However, if you're using some other method to trigger the removal of the drawLine studies then you would need it so that a loop could be used that references the specific set of line segments corresponding to that tag name string and remove the desired set.

    PHP Code:
    for (var 0<= grIDi++) {
        
    removeLine("LineA_"+i);

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      That answered my question. I would need to use the loop and I'll look at the function parameter suggestion. Thanks.

      Regarding drawLineRelative, I have to load all the bars and then look back to do a variety of calculations. The results of these calculations are plotted against the price, including prior bars, for comparisons on support and resistance. I tried return, but it didn't work like I needed -- but, you reminded me to try a couple of other things also. I still think I'll end up "drawing." Thanks.
      -----------------------

      The first question that comes to mind is why are you using drawLineRelative() to plot each study? If you are calculating a value for each study that has a value for each bar it would be easier to plot the studies from the return statement rather that drawing a collection of line segments from bar to bar.

      Comment


      • #4
        You're most welcome. Thanks for the logic details, witch makes sense. I just wanted to make sure we weren't overlooking an easier solution.
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment

        Working...
        X