Announcement

Collapse
No announcement yet.

Remove Drawn Line

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

  • Remove Drawn Line

    i'm trying to delete a line i draw but canot seem to do it.
    Basically the code allows the user to double left click on a point and it will draw a horizontal line there, while exporting some information to a text file. then i am trying to double right click to delete the line....this is the part that i cannot seem to get to work.
    is there some thing obvious i am missing in the updateRDblClickInfo(barIndex, yValue) function.
    thanks.
    the code is below
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;
    PHP Code:
    function preMain() { 

       
    setPriceStudy(true); 
       
    setStudyTitle("DbleClk draw line"); 
       
    setShowCursorLabel(false); 

    var 
    linename="buyline" //give the line a name
    function main() { 


    function 
    onLButtonDblClkbarIndexyValue) { 

       
    debugPrintln("LeftDblClk: " barIndex ", " yValue); 
       
    updateLDblClickInfo(barIndexyValue); 

    function 
    onRButtonDblClkbarIndexyValue) { 

       
    updateRDblClickInfo(barIndexyValue); 

    function 
    updateLDblClickInfo(barIndexyValue) { 

       
    drawTextAbsolute(535"Double Clicked bar " barIndex " at " yValue.toFixed(2),  
       
    Color.whiteColor.navyText.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.BOLDnull14"DblClickInfo"); 
       
        
    addLineToolLineTool.HORZyValue2Color.bluelinename ); 
        
    writetoFile(yValue);
    }
    function 
    updateRDblClickInfo(barIndexyValue) { 

       
    drawTextAbsolute(535"Double Clicked bar " barIndex " at " yValue.toFixed(2),  
       
    Color.whiteColor.navyText.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.BOLDnull14"DblClickInfo"); 
       
    removeline(linename);
    }
    function 
    writetoFile(yValue){
    var 
    = new File("myfileii.txt");  //the file will be created in:  eSignal/FormulaOutput/
    sSymbol getSymbol(); 

     
    a.open("at+");   // Opens and appends the file
        //a.open("wt+"); // Opens and overwrites the file
        
    if(!a.isOpen()) {
            
    debugPrintln("Could not open file!");
        } else {
            
    a.writeln(sSymbol +","yValue.toFixed(2)+linename );
        }
        
    a.close();




  • #2
    Hello Dug,

    Unfortunately, the right button click functions are superseded by the right click menu. What you could do is use the double left click for both drawing and removing the line. To do this you'll need to add a button to the chart that toggles a Boolean flag. When the flag is true the double click action will remove the line. When it's false the action will draw the line. Also, you need to use removeLineTool() instead of removeLine() when using addLineTool() to create the line. Try the following.

    PHP Code:
    function preMain() { 

       
    setPriceStudy(true); 
       
    setStudyTitle("DbleClk draw line"); 
       
    setShowCursorLabel(false); 
    }
     
    var 
    linename="buyline" //give the line a name
    var bRemove false;
    var 
    sText "Draw Line";

    function 
    main() { 
        if (
    getBarState() == BARSTATE_NEWBAR) {
            
    drawButton(sText);
        }
    }


    function 
    removal() {
        if (
    bRemove == false) {
            
    bRemove true;
            
    sText "Remove Line"
            
    drawButton(sText);
        } else {
            
    bRemove false;
            
    sText "Draw Line"
            
    drawButton(sText);
        }
        return;
    }


    function 
    drawButton(t) {
        
    drawTextRelative(315sText+"@URL=EFS:removal"nullnull
            
    Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.BUTTONnull12"switch");
        return;
    }
     
     
    function 
    onLButtonDblClkbarIndexyValue) { 
       
    debugPrintln("LeftDblClk: " barIndex ", " yValue); 
       
    updateLDblClickInfo(barIndexyValue); 



    //function onRButtonDblClk( barIndex, yValue) { 
    //   updateRDblClickInfo(barIndex, yValue); 
    //} 


    function updateLDblClickInfo(barIndexyValue) { 
        
    drawTextAbsolute(535"Double Clicked bar " barIndex " at " yValue.toFixed(2),  
            
    Color.whiteColor.navyText.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.BOLDnull14"DblClickInfo");        
        if (
    bRemove == false) {
            
    addLineToolLineTool.HORZyValue2Color.bluelinename ); 
            
    writetoFile(yValue);
        } else {
            
    //removeline(linename);
            
    removeLineTool(LineTool.HORZlinename);
        }
    }


    //function updateRDblClickInfo(barIndex, yValue) { 
    //   drawTextAbsolute(5, 35, "Double Clicked bar " + barIndex + " at " + yValue.toFixed(2),  
    //   Color.white, Color.navy, Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.BOLD, null, 14, "DblClickInfo"); 
    //   //removeline(linename);
    //   debugPrintln("hello");
    //   removeLineTool(LineTool.HORZ, linename);
    //}

    function writetoFile(yValue){
        var 
    = new File("myfileii.txt");  //the file will be created in:  eSignal/FormulaOutput/
        
    sSymbol getSymbol(); 

        
    a.open("at+");   // Opens and appends the file
        //a.open("wt+"); // Opens and overwrites the file
        
    if(!a.isOpen()) {
            
    debugPrintln("Could not open file!");
        } else {
            
    a.writeln(sSymbol +","yValue.toFixed(2)+linename );
        }
        
    a.close();

    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
      thanks very much...for the fast response and the quick fix.
      being new to EFS programming, can i assume that if i want to have more than one line on the chart, and that i may not necessarily want to remove all the lines at once would it be easiest and best to apply a button for each line i apply to the chart?
      Calling each one a different name eg; buy line, sell line, stop line. that way i could turn each on or off, depending on which line i wished to draw or delete at the time. and giving each a different colour to show which line is which.

      Comment


      • #4
        Hi Dug,

        You can handle this several ways, but I would second the button change that Jason recommends, then when you are in that mode, highlight by re-coloring or re-sizing the lines, cycling through them with the left click. When the one you want to delete is highlighted, you can click the delete button. You would do that by maintaining an array of names associated with the lines respective labels and cycling through that.

        Here is an efs (the Trend Line Alerts) that performs some of this manipulation in this thread.

        FWIW, you can use the right mouse button if you are clicking a button, and then differentiate that event within your efs if you choose. Take a look at some of the button efs's in my fileshare for info on this. Similarly, take a look at the help file efs that Chris Kryza wrote for additional info. http://share.esignal.com/groupconten...r=&groupid=114

        Comment


        • #5
          Dug
          Adding to Jason's and Steve's replies. Consider also that lines drawn with the addLineTool() command can be deleted directly by right clicking on them and selecting Remove. You can also change their properties (color, thickness, type) using the same method.
          Alex

          Comment


          • #6
            brilliant, fantastic. thanks everyone.
            i did not realise that you could right click on the line. the simple things always work the best!
            i will endeavour to work on this some more, and try and stump myself again.

            Comment

            Working...
            X