Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

First independent community of traders

First independent community of traders Logo First independent community of traders Logo

First independent community of traders Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • Buy Theme
  • Home
  • About Us
  • Blog
  • Contact Us
Home/ Questions/Q 4361
Next
In Process
hoz
hoz

hoz

  • 16 Questions
  • 22 Answers
  • 0 Best Answers
  • 32 Points
View Profile
  • 0
hoz
Asked: December 27, 20202020-12-27T05:10:17+00:00 2020-12-27T05:10:17+00:00In: Forex Expert Advisors

What’s wrong with FileReadDouble (FileWriteDouble)?

  • 0

There is a test script:

//+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//|                                                                                                                                                         writeSpicifiedType.mq5 |
//|                                                                                                                                                                            hoz |
//|                                                                                                                                                                                |
//+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
#property copyright "hoz"
#property link      ""
#property version   "1.00"

/*
double high = 0;
double profit = 0;
double low = 0;
*/

double high = 1.3154;
double profit = 50;
double low = 1.3140;

//+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//|                                                                                Script program start function                                                                   |
//+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void OnStart() {
//---
  Print("_high = ", DoubleToString(high));
  Print("_profit = ", profit);
  Print("_low = ", low);
  loadSettings();
  saveSettings();
  Print("high = ", high);
  Print("profit = ", profit);
  Print("low = ", low);
}

//+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//|                                                                                Expert Load setings function                                                                    |
//+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void loadSettings(void) {
  string fileName = _Symbol + ".dat";
  int fileHandle;
//---
  if (FileIsExist(fileName, 0)) {
    fileHandle = FileOpen(fileName, FILE_READ|FILE_BIN);
    
    if (fileHandle != INVALID_HANDLE) {
      high = FileReadDouble(fileHandle);
      Print(__FUNCTION__, " high = ", high);
      profit = FileReadDouble(fileHandle);
      Print(__FUNCTION__, " profit = ", profit);
      low = FileReadDouble(fileHandle);
      Print(__FUNCTION__, " low = ", low);
      FileClose(fileHandle);
    }
  }
}
//+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//|                                                                                Expert Save settings function                                                                   |
//+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void saveSettings(void) {
  string fileName = _Symbol + ".dat";
  int fileHandle;
  bool fileFound = true;
//---  
  if (FileIsExist(fileName, 0)) {
    if (FileDelete(fileName, 0))
      fileFound = false;
  } else {
    fileFound = false;
  }
//---
  if (!fileFound) {
    fileHandle = FileOpen(fileName, FILE_WRITE|FILE_BIN);
    if (fileHandle != INVALID_HANDLE) {
      FileWriteDouble(fileHandle, high);
      FileWriteDouble(fileHandle, profit);
      FileWriteDouble(fileHandle, low);
      FileClose(fileHandle);
    }
  }
}

In OnStart (), I call loadSettings() and saveSettings () in turn, respectively, to read data and write data. Everything is elementary and simple. But for some reason, when reading, the data is not read. What is this supposed to mean?

  • 2 2 Answers
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    2 Answers

    • Voted
    • Oldest
    • Recent
    1. hoz

      hoz

      • 16 Questions
      • 22 Answers
      • 0 Best Answers
      • 32 Points
      View Profile
      hoz
      2020-12-27T05:10:26+00:00Added an answer on December 27, 2020 at 5:10 am

      XS. Overloaded the terminal and everything now works. Glyukanul apparently accidentally. The question is removed.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. barabashkakvn

      barabashkakvn

      • 7 Questions
      • 162 Answers
      • 0 Best Answers
      • 314 Points
      View Profile
      barabashkakvn
      2020-12-27T05:10:21+00:00Added an answer on December 27, 2020 at 5:10 am

      Like I wrote the most detailed example:

      //+------------------------------------------------------------------+
      //|                                           writeSpicifiedType.mq5 |
      //|                                                              hoz |
      //|                                                                  |
      //+------------------------------------------------------------------+
      #property copyright "hoz"
      #property link      ""
      #property version   "1.00"
      //---
      double high=-1.0;
      //+------------------------------------------------------------------+
      //| Script program start function                                    |
      //+------------------------------------------------------------------+
      void OnStart()
        {
      //---
         Print("");
         ReadSettings();
         Print("read high   = ",DoubleToString(high,5));
         high=rand()/32767.0+1.0;
         Print("rand high   = ",DoubleToString(high,5));
         WriteSettings();
        }
      //+------------------------------------------------------------------+
      //| Read setings function                                            |
      //+------------------------------------------------------------------+
      void ReadSettings(void)
        {
         Print(__FUNCTION__);
         string fileName=_Symbol+".dat";
         int fileHandle;
      //---
         if(FileIsExist(fileName,0))
           {
            Print("FileIsExist=true");
            fileHandle=FileOpen(fileName,FILE_READ|FILE_BIN);
            if(fileHandle!=INVALID_HANDLE)
              {
               Print("FileOpen=true");
               high=FileReadDouble(fileHandle);
               FileClose(fileHandle);
              }
            else
               Print("FileOpen=false");
           }
         else
            Print("FileIsExist=false");
        }
      //+------------------------------------------------------------------+
      //| Write settings function                                          |
      //+------------------------------------------------------------------+
      void WriteSettings(void)
        {
         Print(__FUNCTION__);
         string fileName=_Symbol+".dat";
         int fileHandle;
         bool fileFound=true;
      //---  
         if(FileIsExist(fileName,0))
           {
            Print("FileIsExist=true");
            if(FileDelete(fileName,0))
              {
               Print("FileDelete=true");
               fileFound=false;
              }
            else
               Print("FileDelete=false");
           }
         else
           {
            Print("FileIsExist=false");
            fileFound=false;
           }
      //---
         if(!fileFound)
           {
            Print("fileFound=false");
            fileHandle=FileOpen(fileName,FILE_WRITE|FILE_BIN);
            if(fileHandle!=INVALID_HANDLE)
              {
               Print("FileOpen=true");
               FileWriteDouble(fileHandle,high);
               FileClose(fileHandle);
              }
            else
               Print("FileOpen=false");
           }
         else
            Print("fileFound=true");
        }
      //+------------------------------------------------------------------+

      And the result (three runs, before the first run of the file is not yet)


      ReadSettings
      FileIsExist=false
      read high   = -1.00000
      rand high   = 1.92523
      WriteSettings
      FileIsExist=false
      fileFound=false
      FileOpen=true

      ReadSettings
      FileIsExist=true
      FileOpen=true
      read high   = 1.92523
      rand high   = 1.09458
      WriteSettings
      FileIsExist=true
      FileDelete=true
      fileFound=false
      FileOpen=true

      ReadSettings
      FileIsExist=true
      FileOpen=true
      read high   = 1.09458
      rand high   = 1.61129
      WriteSettings
      FileIsExist=true
      FileDelete=true
      fileFound=false
      FileOpen=true

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    Leave an answer

    Leave an answer
    Cancel reply

    Browse

    Sidebar

    Ask A Question

    Stats

    • Questions 504
    • Answers 2k
    • Posts 5
    • Comments 0
    • Best Answers 0
    • Users 681
    • Popular
    • Comments
    • Tags
    • forexcommunity

      Highlighting what’s important about questions & Answers on Discy Community!

      • 0 Comments
    • forexcommunity

      Introducing Keyboard Shortcuts, our first Labs feature

      • 0 Comments
    • forexcommunity

      Defining quality on Discy Engine — what a helpful answer ...

      • 0 Comments
    • forexcommunity

      Organizational and company accounts on Discy Engine the next step

      • 0 Comments
    • forexcommunity

      Hello world!

      • 0 Comments

    Related Questions

    • Brus Agell

      Правельный выбор

      • 0 Answers
    • pinupcasinoo

      Pin Up Casino

      • 0 Answers
    • c00l777

      During optimization, indicators that are not present in the robot ...

      • 2 Answers
    • c00l777

      During optimization, indicators that are not present in the robot ...

      • 0 Answers
    • c00l777

      Optimization results differ on different accounts

      • 3 Answers

    Users

    Leonardcig

    Leonardcig

    • 0 Questions
    • 0 Answers
    DennisByday

    DennisByday

    • 0 Questions
    • 0 Answers
    Haroldmeary

    Haroldmeary

    • 0 Questions
    • 0 Answers

    Footer

    First independent community of traders

    About

    An independent community of forex traders. This is where traders communicate. You can ask your questions and you will receive an answer to your question.
    • Terms of Use
    • Privacy Policy
    • Cookie Policy
    • Knowledge Base
    • Support

    © 2021 Forexcommunity.net. All Rights Reserved