Please Help - page 2

 
Thirteen:

  1. Yes, I would expect there would be a good possibility that the function would return false for trying to access the 2000th weekly bar. Assuming your broker trades all 52 weeks a year, 2000 divided by 52 is approximately 38.5 years. Does your broker even have weekly history data that goes back 38.5 years for the specified currency pair? There is a very good possibility that it doesn't, so the function returns false.
  2. Not necessarily . . . because some timeframes for a particular currency pair may have missing bars when no ticks were received during that time. If you want to use a synchronized time, then you probably should search for the bar with that time using iBarShift().
  3. Not sure what you mean.
  4. Of course, since the history data has already been downloaded into the Terminal's History Center!! What happens when the data hasn't been downloaded . . . how long will downloading that data take? It can take a several seconds for the data to be downloaded from your broker. Each call to MakeInfoString does not mean that the function will take 20 seconds to retrieve the data; rather, MakeInfoString is designed to take upto 20 seconds in 2 second intervals. If no 4066 error and data is returned from iTime() and the returned data is valid, the function returns immediately after building the return string without sleeping (and probably in less than a second). If the function doesn't need to sleep, it won't.
Also, why are you printing the 'line" variable when MakeInfoString() returns false?


Thanks for the information. I've replaced my MakeInfoString() with yours in my project.
 

As it happens. I need help with another function. I can't figure out why it doesn't always work. Please, could someone point out any errors or suggest how to rewrite.


The idea is to go the the end of the file, go up one line and read it.
//Returns the last line in a file. Exits with the pointer position at where it was.
string GetLastLine(int Handle){

        int initpos = FileTell(Handle);
        string Read = "";
        int ByteCount=3;  //  3 is for \r\n

        while( True){

                FileSeek(Handle,-1*ByteCount, SEEK_END);  //at first loop it is the last char in the last line
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                ///DEBUGGING
                int err = GetLastError();
                if( err != 0){
                        Print("GetLastLine(): Error ",err, " after FileSeek()-- " ,  ErrorDescription(err));
                        return("");
                }
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////                

                Read = FileReadString(Handle);
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                ///DEBUGGING
                err = GetLastError();
                if( err != 0){
                        Print("GetLastLine(): Error ",err, " after FileReadString() -- " ,  ErrorDescription(err));
                        return("");
                }
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////                


                if ( Read == "" ){  //we hit the "\r\n".

                        //roll back 
                        ByteCount--;      
                        FileSeek(Handle,-1*ByteCount, SEEK_END);  //at first loop it is the last char in the last line
                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                        ///DEBUGGING
                        err = GetLastError();
                        if( err != 0){
                                Print("GetLastLine(): Error ",err, " after FileSeek in if ( Read == \"\" )-- " ,  ErrorDescription(err));
                                return("");
                        }
                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////                


                        Read = FileReadString(Handle);
                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                        ///DEBUGGING
                        err = GetLastError();
                        if( err != 0){
                                Print("GetLastLine(): Error ",err, " after FileReadString() in if ( Read == \"\" ) -- " ,  ErrorDescription(err));
                                return("");
                        }
                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////                

                        FileSeek(Handle,initpos, SEEK_SET);     
                        return(StringTrimLeft(StringTrimRight(Read) ) );
                }       


                ByteCount++;
        }
}

I had a file that ended with:

20130908,00:00,33.3660,33.4280,32.4370,32.4470,34464

there wasn't a blank line at the end. Yet, my function said that the line is empty when I tested.

Reason: