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

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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.