Can MetaTrader Read Txt Files using the include statement and import variables from the text file? - page 2

 

the opposite of "the god of programming" is

NOT "the devil of programming"

it is

"the god of NO-programming"

analysing a problem and find the solution is the core of programming. not writing some letters in a script.

if someone isnt able to solve the problems on its own, he is simply no programmer. such easy.

yes, my english sucks.

you should be glad, that i dont write in german :-))))))

 
I already know what the solution is....all that is needed is to implement it. So far, all I have been able to do is import strings using FileReadString. I can't import double values used for calculation. It is the last piece of a master puzzle...and YOU AREN'T HELPING...SO LEAVE
 

LOL

i have told you, that at least i had to know the structure of the file

and i dont write complete code for analysing it.

i havent said that i would possibly give you an advice to write your own code.but til now you havent posted the structure - so what ?

in a ascii-file each value is a string. an ascii-file is made of only strings...

read all as string and convert numbers with StringToDouble...

 

If you have a text file (.txt) created in notepad, and the only thing that is in the entire file is:


"Gold_Price = 1176.55"


How do I pull the "1176.55" out of the .txt file and into my EA to use in calculations? So far, the only way I have been able to do it is using FileReadString - which does me absolutely no good because I can't run calculations on String variables. I am not sure if I could use FileReadDouble or what to get just the "1176.55" into my EA.


Meikel, if you want to help me, then by all means. I don't need complete code! I only need one small iota...what file operator do I use to pull in variables from .txt files and what is the format for using it?! I would appreciate any help you can give. If you want to keep on with this run around, then please just leave.

 

string Line="Gold_Price = 1176.55";

string Result[];

in other languages this is very easy.

read one line of the file and use

StringExplode("=",Line,Result);

Result[0] will give "Gold Price "

Result[1] will give " 1176.55"

its late, i hope i have posted the correct function.... ( i always make a lot of bugs, thats the reason why i am good in debugging :-)))))


void StringExplode(string sDelimiter, string sExplode, string &sReturn[]){
   
   int ilBegin = -1,ilEnd = 0;
   int ilElement=0;
   while (ilEnd != -1){
      ilEnd = StringFind(sExplode, sDelimiter, ilBegin+1);
      ArrayResize(sReturn,ilElement+1);
      sReturn[ilElement] = "";     
      if (ilEnd == -1){
         if (ilBegin+1 != StringLen(sExplode)){
            sReturn[ilElement] = StringSubstr(sExplode, ilBegin+1, StringLen(sExplode));
         }
      } else { 
         if (ilBegin+1 != ilEnd){
            sReturn[ilElement] = StringSubstr(sExplode, ilBegin+1, ilEnd-ilBegin-1);
         }
      }      
      ilBegin = StringFind(sExplode, sDelimiter,ilEnd);  
      ilElement++;    
   }
}
 

yes, FileReadDouble is used for reading bin file not text file.

for text file, you should read string, and parse it to digits.

 
Calpurnia wrote >>

If you have a text file (.txt) created in notepad, and the only thing that is in the entire file is:

"Gold_Price = 1176.55"

How do I pull the "1176.55" out of the .txt file and into my EA to use in calculations? So far, the only way I have been able to do it is using FileReadString - which does me absolutely no good because I can't run calculations on String variables. I am not sure if I could use FileReadDouble or what to get just the "1176.55" into my EA.

Meikel, if you want to help me, then by all means. I don't need complete code! I only need one small iota...what file operator do I use to pull in variables from .txt files and what is the format for using it?! I would appreciate any help you can give. If you want to keep on with this run around, then please just leave.

Hi,

once i was doing like this, for me was working, maybe you need your own interpretation...

The file need to placed in your experts/files folder, the content in my file was f.e. VOLA=8.

Function was:

int ReadSignalsFromFile()
{
   int      handle;
   int      lines_read=0; 
   string   value;
   int      numColumns = 2;
   string p_name="";
   string p_value="";
   string FileName=Symbol()+Period()+".set";
   Print("Read EA Settings");
      
   handle=FileOpen(FileName,FILE_CSV|FILE_READ,'=');
   if(handle<0)
     {
      Print("Can not open " + FileName + " for reading => " + GetLastError());
      return(-1);
     }
    else
    {
      //Read File
      int column=0;
      int line=0;
      while(FileIsEnding(handle)==false)
        {
         value=FileReadString(handle);
         if(StringLen(value)<1) continue; // Skip empty lines
             p_name = value;             
             p_value = FileReadString(handle);
             if (p_name=="VOLA")  
             {VOLA=StrToInteger(p_value);
             Print("Vola:"+VOLA);}
             if (p_name=="CHECK_LEVEL")  
             {CHECK_LEVEL=StrToInteger(p_value);
             Print("CHECK_LEVEL:"+CHECK_LEVEL);}
             if (p_name=="Alpha") 
             { Alpha=StrToInteger(p_value);
             Print("Alpha:"+Alpha);}
             if (p_name=="Gamma") 
             { Gamma=StrToInteger(p_value);
             Print("Gamma:"+Gamma);}
             if (p_name=="TPFaktor")  
             {TPFaktor=StrToDouble(p_value);
             Print("TPFaktor:"+TPFaktor);}
             if (p_name=="RiskFaktor")  
             {RiskFaktor=StrToDouble(p_value);
             Print("RiskFaktor:"+RiskFaktor);}
             if (p_name=="LimitTPto") 
             { LimitTPto=StrToInteger(p_value);
             Print("LimitTPto:"+LimitTPto);}
             column = 0;
             line++;
             
          }
        }
  
   FileClose(handle); 
   //FileDelete(FileName); 
   return (0);
}

but how you can see i was looking for few parameters from my extern set-File.

Hope it helps for you, brgds

Reason: