How to modify this to read a parameter from a txt

 

Hi,

How can I modify this, to make it read a value from a txt? (and how should the txt be written?)

I've tried with this ... but I think I'm very far away

Please help, now money for freelance.

//+------------------------------------------------------------------+
//|                                                        Timer.mq5 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2021, Vladimir Karputov"
#property link      "https://www.mql5.com/ru/market/product/43516"
#property version   "1.000"
//---
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
//---
CPositionInfo  m_position;                   // object of CPositionInfo class
CTrade         m_trade;                      // object of CTrade class
//--- input parameters
input uchar    InpAfterHour   = 0; // After: Hour ... (max 255)
//input uchar    InpAfterMinutes= 42; // After: Minutes ... (max 255)
input uchar    InpAfterSeconds= 59; // After: Seconds ... (max 255)
//---
long     m_after  = 0;

string ip = "127.0.0.1";
int puerto = 8888;
uchar InpAfterMinutes=MiParametro;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnStart() {
    double MiParametro;

    if (ServerEstaCorriendo()) {
        // Leer el valor de Python
        MiParametro = ReadFromPython();

        // Resto del código del EA
        Print("Valor de MiParametro desde Python: ", MiParametro);
    } else {
        Print("El servidor de Python no está en ejecución.");
    }

    return(INIT_SUCCEEDED);
}

bool ServerEstaCorriendo() {
    // Implementa tu lógica para verificar si el servidor de Python está en ejecución
    // Por ejemplo, puedes intentar conectarte a través de sockets o verificar un archivo de bloqueo
    // Devuelve true si el servidor está en ejecución, de lo contrario, false.

    // Ejemplo ficticio:
    int socket = SocketCreate();
    if (socket != INVALID_HANDLE) {
        SocketClose(socket);
        return true;
    } else {
        return false;
    }
}

double ReadFromPython() {
    // Implementa tu lógica para leer el valor desde Python
    // Puedes utilizar sockets, archivos compartidos, etc.

    // Ejemplo ficticio:
    double valor;
    FileReadArray("C:/Users/jsgas/OneDrive/Trading/Deep Learning/DLF con telegram/archivo_python.txt", valor);
    return valor;
}


//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   //--- Print "Hello, World!" to the log
   Print("Hello, World!");
  }
//+------------------------------------------------------------------+

// 
// This script, when run, will execute the `OnStart` function and print "Hello, World!" to the log of the MetaTrader 5 terminal.
// 


int OnInit()
  {
//--- forced initialization of variables
   m_after  = 0;
   m_after=InpAfterHour*60*60+InpAfterMinutes*60+InpAfterSeconds;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   for(int i=PositionsTotal()-1; i>=0; i--) // returns the number of current positions
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
        {
         if(TimeCurrent()-m_position.Time()>=m_after)
            m_trade.PositionClose(m_position.Ticket()); // close a position
        }
  }
//+------------------------------------------------------------------+
 

edited: this one works!


//+------------------------------------------------------------------+
//|                                                        Timer.mq5 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2021, Vladimir Karputov"
#property link      "https://www.mql5.com/ru/market/product/43516"
#property version   "1.000"

//--- display the window of input parameters when launching the script
#property script_show_inputs

//--- parameters for data reading
input string InpFileName="archivo_python.txt"; // file name
input string InpDirectoryName="Files"; // directory name
//---
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>

//---
CPositionInfo  m_position;                   // object of CPositionInfo class
CTrade         m_trade;                      // object of CTrade class
//--- input parameters
input uchar    InpAfterHour   = 0; // After: Hour ... (max 255)
input uchar    InpAfterMinutes= 42; // After: Minutes ... (max 255)
input uchar    InpAfterSeconds= 59; // After: Seconds ... (max 255)
//---
int file_handles;
uchar valor_uchar;
long     m_after  = 0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

int OnInit()
  {

   // Abrir el archivo para lectura
   string file_path = "C:/Users/jsgas/AppData/Roaming/MetaQuotes/Terminal/D0E8209F77C8CF37AD8BF550E51FF075/MQL5/Files/archivo_python.txt";
   file_handles = FileOpen(file_path, FILE_READ|FILE_TXT);
   
   if(file_handles != INVALID_HANDLE)
     {
      PrintFormat("Archivo %s abierto correctamente", file_path);
      
      // Leer el valor uchar desde el archivo
      if (FileReadInteger(file_handles, INT_VALUE))
        {
         PrintFormat("Valor uchar leído desde el archivo: %u", valor_uchar);
         m_after  = 0;
         m_after=valor_uchar;
        }
      else
        {
         Print("Error al leer el valor uchar desde el archivo");
        }

      // Cerrar el archivo después de la lectura
      FileClose(file_handles);
     }
   else
     {
      m_after  = 0;
      m_after=InpAfterHour*60*60+InpAfterMinutes*60+InpAfterSeconds;
      PrintFormat("Error al abrir el archivo %s, Código de error = %d", file_path, GetLastError());
     }
     
     

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   for(int i=PositionsTotal()-1; i>=0; i--) // returns the number of current positions
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
        {
         if(TimeCurrent()-m_position.Time()>=m_after)
            m_trade.PositionClose(m_position.Ticket()); // close a position
        }
  }
//+------------------------------------------------------------------+


This works