fxDreema

    • Register
    • Login
    • Search
    • Back to the main page
    • Categories
    • Recent
    • Tags
    • Popular
    • Search

    Read file data

    Questions & Answers
    4
    20
    5017
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      ekifox last edited by

      Hello,
      I would like to automate my daily strategy.

      Every day a .csv file is made by an external program, and I would like to make a ea able to read it and react depending on the information inside the file.
      More precisely, the file contains a price, and the ea should read it and buy or sell depending on the number found.

      Is it possible?
      Can you please help me?
      Thanks a lot!

      1 Reply Last reply Reply Quote 0
      • l'andorrà
        l'andorrà last edited by

        I guess that must need some custom code. AFAIK it is not possible with the existing blocks right now, but I may be wrong. Any hint, miro or roar?

        (English) I will try to help everyone in these fxDreema forums. But if you want to learn how to use the platform in depth or more quickly, I can help you with my introductory fxDreema course in English at https://www.theandorraninvestor.eu.

        (Català) Miraré d’ajudar tothom en aquests fòrums d’fxDreema. Tanmateix, si vols aprendre a fer servir la plataforma amb més profunditat o més de pressa, t’hi puc ajudar amb el meu curs d’introducció a fxDeema en català a https://www.theandorraninvestor.eu/ca.

        (Español) Intentaré ayudar a todo el mundo en estos foros de fxDreema. Sin embargo, si quieres aprender a usar la plataforma en profundidad o más deprisa, te puedo ayudar con mi curso de introducción a fxDreema en español en https://www.theandorraninvestor.eu/es.

        1 Reply Last reply Reply Quote 0
        • T
          trader.philipps last edited by

          @ekifox You may achieve this by cusomt MQL code. Here is the API documentation. How many values are in you CSV file?
          Another thing you might keep in mind is how to get to know that the file was updated.

          I like to share my knowledge, but expect the others to contribute as well.

          1 Reply Last reply Reply Quote 0
          • E
            ekifox last edited by

            Thanks for the reply!
            I forgot to say that it's for mt5, not mt4.

            I'm trying to store in the EA only one numeric variable. The file is updated based on a timing schedule:
            5min after the previous candle is closed: EA(1) saves chart info on some files.
            10min after the previous candle is closed: Custom script checks date/hour of files created. Custom R script elaborate these files and generates a single csv file with the TP.
            15min after the previous candle is closed: EA(2) reads the file with TP and reacts accordingly.

            I'm blocked in the last point 😞

            T 1 Reply Last reply Reply Quote 0
            • T
              trader.philipps @ekifox last edited by

              @ekifox looks like it's pretty much the similar in mql5. Have a look here

              I like to share my knowledge, but expect the others to contribute as well.

              1 Reply Last reply Reply Quote 0
              • E
                ekifox last edited by

                Thanks for the suggestions!
                I am able to import from the file the number I want, but only as a string so unuseful if fxdreema can't elaborate it. Can someone help me with the code please?

                int handle = FileOpen(tempFileName,FILE_READ|FILE_CSV,0,CP_UTF8);
                FileSeek(handle,0,SEEK_SET);
                while(!FileIsEnding(handle))
                {
                letto = FileReadString(handle,0); //<--this works
                lettod = FileReadNumber(handle); //<-- this does not work and gives back value 0.0
                }

                FileClose(handle);

                Print(letto);
                Print(lettod);

                1 Reply Last reply Reply Quote 0
                • T
                  trader.philipps last edited by

                  @ekifox Use StringToDouble method to convert the string to double.

                  I like to share my knowledge, but expect the others to contribute as well.

                  1 Reply Last reply Reply Quote 0
                  • E
                    ekifox last edited by

                    lettod is set on variables as double.

                    lettod = StringToDouble(letto);

                    but it keeps giving back 0.0

                    T 1 Reply Last reply Reply Quote 0
                    • T
                      trader.philipps @ekifox last edited by

                      @ekifox if you print the string, what format does it has? Can you just print it to terminal lo with the Print() function?

                      I like to share my knowledge, but expect the others to contribute as well.

                      1 Reply Last reply Reply Quote 0
                      • E
                        ekifox last edited by

                        For the string variable: Print(letto) It gives the correct content (as string).
                        For the double variable: Print(lettod) it gives 0.0 all the time.
                        Thanks for the support!

                        T 1 Reply Last reply Reply Quote 0
                        • T
                          trader.philipps @ekifox last edited by

                          @ekifox that's strange! Would you mind to share your project and the text file?

                          I like to share my knowledge, but expect the others to contribute as well.

                          1 Reply Last reply Reply Quote 0
                          • E
                            ekifox last edited by ekifox

                            https://fxdreema.com/shared/Q2w2FX5Lc

                            0_1569391111904_reader.mq5

                            can't upload the .csv file, but it's just prova.csv file containing one line of 1.23456

                            THANKS FOR THE HELP!


                            Great, now it started speaking mandarin 😕
                            0_1569391447434_Cattura.JPG

                            T 1 Reply Last reply Reply Quote 0
                            • T
                              trader.philipps @ekifox last edited by

                              @ekifox yepp, my result looks similar. It doesn't get the string but a byte it looks like.
                              No clue at the moment.

                              I like to share my knowledge, but expect the others to contribute as well.

                              1 Reply Last reply Reply Quote 1
                              • E
                                ekifox last edited by

                                Thanks anyway! Hope to find a solution

                                T 1 Reply Last reply Reply Quote 0
                                • T
                                  trader.philipps @ekifox last edited by

                                  @ekifox Finally by try and error :))

                                  Use this for handle:

                                  //
                                  int handle = FileOpen(tempFileName,FILE_READ|FILE_CSV|FILE_ANSI);
                                  //

                                  Don't ask me why it has to be FILE_ANSI as I saved my file with UTF-8 encoding explicitly.
                                  However, the result looks like this..

                                  0_1569458105983_7d7dc2bf-ee91-45bf-8fff-7ec6f78b45ef-image.png

                                  I like to share my knowledge, but expect the others to contribute as well.

                                  E 1 Reply Last reply Reply Quote 3
                                  • E
                                    ekifox @trader.philipps last edited by

                                    OMG it works!!!
                                    for the unfortunate posterity who will find themselves in the same problem in the future, this is the code:

                                    ResetLastError();
                                    int handle = FileOpen(tempFileName,FILE_READ|FILE_CSV|FILE_ANSI);
                                    if(handle!=INVALID_HANDLE)
                                    {
                                    while(!FileIsEnding(handle))
                                    {
                                    letto = FileReadString(handle,0);
                                    //lettod = FileReadDouble(handle);
                                    lettod=StringToDouble(letto);
                                    Print("---> string :",letto);
                                    Print("---> double :",lettod);
                                    }
                                    }
                                    else
                                    {
                                    Print("File not opened. Error : ", GetLastError());
                                    }
                                    FileClose(handle);

                                    You have to set as constant string tempFileName --> the file name with extension
                                    letto --> as string variable
                                    lettod --> as double string variable

                                    @trader-philipps YOU ARE THE MAN! How can I repay you???

                                    T 1 Reply Last reply Reply Quote 1
                                    • T
                                      trader.philipps @ekifox last edited by

                                      @ekifox Just keep sharing your interesting projects! That will pay enough for all of us.

                                      I like to share my knowledge, but expect the others to contribute as well.

                                      E Zackry 2 Replies Last reply Reply Quote 0
                                      • E
                                        ekifox @trader.philipps last edited by

                                        I aim to make a multivariable statistical model with R. To do this we need variables and a targhet. The targhet is close price of a symbol of bar 1. the variables are as many information as possbile of bar 2 (bar datas, indicators values etc, not only from targhet symbol).

                                        How to collect targhet and variables:
                                        I made this to extract as many information as possible from the market.
                                        0_1569663033618_autoextract2.mq5
                                        Variable legend:

                                        • bars: "from" how many bars in the past it will start collecting data.
                                        • bar_a: "to" how many bars in the past it will stop collecting data.
                                        • market: list of symbols to extract data
                                        • live: if = 0 it will extract data from "bars" to "bar_a". if != 0 it will extract only the single bar you set as live value. (this was made for backtesting).

                                        Example:
                                        We want to extract AUDUSD, USDJPY, GBPUSD as variables. we target close price bar of EURUSD. We want to collect data from 3000 1h bars in the past to 10 1h bar in the past.
                                        Since we target EURUSD 1h time frame, we load the ea in the 1h EURUSD chart. Variables are set like this:

                                        • bars: 3000
                                        • bar_a: 10
                                        • market: AUDUSD, USDJPY, GBPUSD
                                        • live: 0

                                        press ok, and let the ea do its job. When the job is done you will find in /Files folder 4 files:

                                        • AUDUSD.csv <-- data from 1h time frame extracted from this symbol (1 bar before targhet bar)
                                        • USDJPY.csv <-- data from 1h time frame extracted from this symbol (1 bar before targhet bar)
                                        • GBPUSD.csv <-- data from 1h time frame extracted from this symbol (1 bar before targhet bar)
                                        • targhet.csv <-- close price of EURUSD (1 bar after AUDUSD, USDJPY, GBPUSD)

                                        What kind of information are collected for variables (not target)?
                                        check block n.8. You can customize it, but Candle ID needs to stay as bvar variable and tempo needs to stay as it is to have a better organization in R database.

                                        How to change targhet?
                                        to change the target symbol just load it in the desired symbol. to change the target information check block n. 24 and change aim. Candle ID needs to stay as bvar variable. tempo needs to stay as it is. Do not put more variables than aim and tempo, unless you know what you are doing.

                                        How to extract all this data from only one bar?
                                        you want to extract all the infos above from bar 5? just set variable live = 5. only the raw of bar 5 will be collected. This is made for backtesting, in fact no target.csv will be produced.

                                        Now that we have our data, we can create an R database merging all csv extracted from this ea. We can train a machine learning model from this data, or use glm models, caret, or whatever model you would like to use. At the moment of writing, i'm studying xgbTree with caret (please refere to this page: Predictive modeling and machine learning in R with the caret package). next study model will be glm.

                                        Once the model is done and we are happy with it, we can make prediction (wrong or right) about the target, save them in a csv file, and thanks to @trader-philipps we are able to make a ea that can read the prediction from the csv file and react to them.

                                        tl;dr
                                        We train a statistical model to be able to predict bar 1 price, given information from the previous bar (bar 2). once the model is trained, we give bar 0 information to the model to predict the next bar price (bar -1).

                                        T 1 Reply Last reply Reply Quote 2
                                        • T
                                          trader.philipps @ekifox last edited by trader.philipps

                                          @ekifox Wow! Scientific work ahead! Please keep updating us!

                                          I like to share my knowledge, but expect the others to contribute as well.

                                          1 Reply Last reply Reply Quote 0
                                          • Zackry
                                            Zackry @trader.philipps last edited by

                                            @trader-philipps hi , got somewhat similar situation ,the only difference is i have 4 columns so can you perhaps share how the custom mql code block knows which column to read?

                                            1 Reply Last reply Reply Quote 0
                                            • 1 / 1
                                            • First post
                                              Last post

                                            Online Users

                                            T
                                            B
                                            A
                                            P

                                            12
                                            Online

                                            146.7k
                                            Users

                                            22.4k
                                            Topics

                                            122.6k
                                            Posts

                                            Powered by NodeBB Forums | Contributors