Announcement

Collapse
No announcement yet.

Global Variables vs. File objects

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

  • Global Variables vs. File objects

    I am trying to create a way to count the number of symbols in a Watchlist, and save that number somewhere where a different EFS can access it. I decide to use a file object that adds an element for every symbol in the Watchlist and then reads the length of that file to determine the number of elements counted. Later I will try and acces that number from a charting study. I don't know if this is the best approach, but I have not figured out how to have one study create/manipulate variables that a separate EFS can read. (I originally thought QLink may offer a solution, but importing calculations from an Excel doesn't seem to be possible either). I created the following code to count the number of symbols in a Watchlist but it doesn't seem to work. Any ideas or help appreciated.



    PHP Code:
    function preMain()
    {
        
    setCursorLabelName("Text",0);
        
    setDefaultBarFgColor(Color.white0); 
            
        
    setCursorLabelName("Length ",1);
        
    setDefaultBarFgColor(Color.white1); 


    }

    var 
    Tot = new File"Total/test.txt" ); 
    Tot.mkDir(); 

    var 
    line="ini";
    var 
    Lngth=-11;
    var 
    rArray = new Array();

    function 
    Main()
    {
        if (
    getBarState==BARSTATE_ALLBARS)
        {
            if( 
    Tot.exists() ) { 
                                                 
                
    Tot.open"at+" );
                
    Tot.write("x");
                
    line=Tot.readln();
                
    Tot.close();  
                
    Lngth=Tot.getLength();                       
            } 
            else {
                
    Lngth=-9;
                
    line="! Exist";  
            }     
        }
        
        
    rArray[0]=line;
        
    rArray[1]=Lngth;
         
        
        return 
    rArray;


  • #2
    HawkArps
    Main() should be main()
    Alex


    Originally posted by HawkArps View Post
    I am trying to create a way to count the number of symbols in a Watchlist, and save that number somewhere where a different EFS can access it. I decide to use a file object that adds an element for every symbol in the Watchlist and then reads the length of that file to determine the number of elements counted. Later I will try and acces that number from a charting study. I don't know if this is the best approach, but I have not figured out how to have one study create/manipulate variables that a separate EFS can read. (I originally thought QLink may offer a solution, but importing calculations from an Excel doesn't seem to be possible either). I created the following code to count the number of symbols in a Watchlist but it doesn't seem to work. Any ideas or help appreciated.



    PHP Code:
    function preMain()
    {
        
    setCursorLabelName("Text",0);
        
    setDefaultBarFgColor(Color.white0); 
            
        
    setCursorLabelName("Length ",1);
        
    setDefaultBarFgColor(Color.white1); 


    }

    var 
    Tot = new File"Total/test.txt" ); 
    Tot.mkDir(); 

    var 
    line="ini";
    var 
    Lngth=-11;
    var 
    rArray = new Array();

    function 
    Main()
    {
        if (
    getBarState==BARSTATE_ALLBARS)
        {
            if( 
    Tot.exists() ) { 
                                                 
                
    Tot.open"at+" );
                
    Tot.write("x");
                
    line=Tot.readln();
                
    Tot.close();  
                
    Lngth=Tot.getLength();                       
            } 
            else {
                
    Lngth=-9;
                
    line="! Exist";  
            }     
        }
        
        
    rArray[0]=line;
        
    rArray[1]=Lngth;
         
        
        return 
    rArray;

    Comment

    Working...
    X