Announcement

Collapse
No announcement yet.

DrawLineRelative not sticking to the chart

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

  • DrawLineRelative not sticking to the chart

    Hi, I figure I am missing something simple here.
    I have an EFS that when I double click on a particular price point on a chart, the price and bars are recorded. Then when I hit a button that is on the chart it writes these price levels to a text file. At the same time, the EFS removes and then draws a unique line at that price level. This all works perfectly......see part of the EFS below.

    function BuyOn(){

    Action="Buys";
    linename="buyline";
    removeLine(120)
    drawLineRelative( -30, yy, -1, yy, PS_SOLID, 2, Color.blue, 120 );

    writetoFile(yy);

    }

    However, if I load up another chart, and then go back to this first chart, the lines that were drawn no longer show.
    When I manually draw a line it stays with the chart, but any lines using using drawlinerelative do not.
    How do I get them to hold? Is this possible?
    (or do I need to re-read from the text file each time the particular stock is loaded and redraw a line?)
    thanks.
    Last edited by Adina; 11-25-2010, 07:49 PM.

  • #2
    DrawLineRelative not sticking to chart

    It's been a while since i was coding so this is a stab in semi darkness...
    As you hard code the 'handle' to your line at 120, i wonder whether it gets messed up by switching charts (if the handle is a 'per-chart' handle).

    Bey

    Comment


    • #3
      thanks BeyMelamed, I tried mucking around with the tags etc;
      I would have thought that once the line was drawn on a chart it stayed until it was deleted by the user, or via an EFS. But maybe not. This seems to be more the problem, that a line drawn by an EFS disappears, if the chart changes.
      I hope someone else might be able to clarify this.

      Comment


      • #4
        I'm not sure this will help but do a search for:

        getInvokerID()

        It returns a unique chart ID number based on the order in which the charts were initialized during start up.

        By adding this to the *.Txt file name in both the write & read, it may help by preventing another chart with the same efs to overwrite the text file.

        You could also create a unique global variable that includes the getInvokerID() in the name as the line tag which won't be deleted unless so coded.

        Wayne
        Last edited by waynecd; 11-29-2010, 12:20 AM.

        Comment


        • #5
          thanks Waynecd,
          it seems that a line written by an EFS does not hold, and that it will need to be reloaded somehow.
          Either by checking out this getInvokerID(), and or by reloading the line data from the text files.


          More work to do.

          Comment


          • #6
            Assuming that the "yy" values used to draw the line are obtained from the text file, one troubleshooting test I might run is:

            1- Have the line drawn on a chart, say chart x. Then I would open the text file in Notepad or something to see what it has and close it again.

            2- Next I would recreate the conditions where the line disappears (open a new chart). Followed by checking the contents of the text file to see how this action affected the text file contents.

            3- If loading the new chart changes the values then, in chart x, save the text file values to a global variable and adjust the conditional controling when the text file is read as necessary.

            This is just one possible test. From my experience a drawn line remains drawn unless the same tag is reused, code erases the line, or the x & y values change or are removed.

            Somehow I think that an efs in the newly loaded chart has access to the text file and overwrites it.

            Wayne
            Last edited by waynecd; 11-29-2010, 10:27 PM.

            Comment


            • #7
              Thanks for feedback Waynecd, however, my explanation has not conveyed the situation.
              Lets say I have a chart ABC company The EFS I have written picks up when I dbleclk on the chart. Then I hit a button (also drawn on the chart by the same EFS). This draws a line where I dbl click on a chart (at the "yy" point (or a price level)), and writes this price level to a text file.
              This all works fine.
              the issue comes when I load a new stock into the same chart window, and THEN GO BACK and reload to the original ABC company in that chart window. The line has dissappeared.
              the point being the EFS does not automatically draw the line. It draws only when I manually choose the price level.
              So either I am missing something fundamental or simple, OR a line drawn using an EFS in the manner I have done does not hold on the chart, and the only real solution is to read a text file everytime I load a chart.
              (dont know if this makes a difference to the thread)
              thanks.

              Comment


              • #8
                I agree. Writing the value to and reading it from a file with the chart symbol as part of the file name (so that the line is only drawn for that symbol) will redraw the line once the value is read from the file. Alternately you could use "setGlobalValue()", "getGlobalValue()", and "removeGlobalValue()" with a symbol identifier for the variable name to achieve the same results.
                drawn using an EFS in the manner I have done does not hold on the chart, and the only real solution is to read a text file everytime I load a chart.
                An efs that has a straight code like:
                drawLineRelative(0, 1135,...)
                will always draw the line at 1135. However, the variable that stores the value to be used to draw the line in your script does not survive reloading. It is reset to it's default value or null. Say, it is a global variable outside of main:
                PHP Code:
                var nNumVal null;
                function 
                main(){...} 
                or a local varible inside of main
                PHP Code:
                function main(){
                var 
                nNumVal null;
                ...} 
                or even by the button code itself.

                This test script might help, load it on a chart then change the symbol, interval, etc:
                Both "x" & "y" will be null upon reloading the chart with a new symbol, changing the interval, etc.


                PHP Code:
                debugClear();
                function 
                preMain(){
                    
                setPriceStudy(true);
                }
                var 
                null;
                var 
                bInit false;
                var 
                bInit1 false;
                function 
                main(){
                    var 
                null;
                    if(!
                bInit){
                        
                debugPrintln("10: x: ," " , y: ," y);
                        
                bInit true;
                    }
                    
                7;
                    
                9;
                    if(!
                bInit1){
                        
                debugPrintln("17: x: ," " , y: ," y);
                        
                bInit1 true;
                    }
                    return;

                Wayne
                Last edited by waynecd; 12-01-2010, 12:47 AM.

                Comment


                • #9
                  thanks Waynecd.
                  I will try and muck around with the global variable and the read write from a text file. Both ideas are always handy to know.

                  Comment


                  • #10
                    Hi, in trying to read from the text files - I have hit a snag.
                    Basically the code I use is designed to read a number representing a price level from a text file, and then draw a horizontal line at that price level. This should occur everytime the chart is opened. 9so different stocks will have different lines drawn for them)
                    the code I am using is

                    function ReadTextFiles(){
                    //read a file
                    sSymbol = getSymbol(); //the symbol for the chart that is loaded
                    Action="BuyBrk"; //the distinguishing action for the line
                    var f = new File( "/"+"price_alerts"+"/"+sSymbol+Action+"PricesFile.txt" );

                    if( f.exists() ) {
                    f.open( "rt" );
                    var line;
                    while( !f.eof() ) { //while its not the end of the file
                    line = f.readln();
                    if(line==null) return;//this is the null check
                    var n = parseFloat( line ); //convert text to price value
                    debugPrintln( "Line: [" + line + "]" );
                    //plot line to chart
                    //removeLine(120)
                    drawLineRelative( -30, n, -1, n, PS_SOLID, 2, Color.blue,120);
                    }
                    f.close();
                    }
                    }

                    The problem seems to be that while it gets the value from text file no problems and it shows this in the debugprintln function.
                    I cannot get the line to actually be drawn, so I wonder if its to do with something simple. thanks.

                    Comment


                    • #11
                      It turned out I had some issues with the
                      if(line==null) return;//this is the null check

                      As when reading from the text files, the last line is always going to be null or blank.

                      I have mucked around, replaced a few things and seemingly got it all working. I am sure its clunky and could be cleaner and hence faster but it works.

                      Basically it allows the user to double click on the chart in four different places and then records these price levels as a text file. EFs is attached.
                      Attached Files

                      Comment

                      Working...
                      X