Nothing happens when it comes up to handle a file, MQL4
Nothing happens when it comes up to handle a file, MQL4
Loading saved threads...
StickFix · External communityPost link
External question — Stack Overflow Stack Exchange
Author: StickFix
Original post: https://stackoverflow.com/questions/77277399
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I'm a little perplexed by what I see happening, or rather, by what I DON'T see happening.
In the code I'm showing you next, the code begins to work from the if(OrdersTotal()>0) on, but all what is before simply doesn't give any life sign. No errors, nothing. Not even the Print works. But as I said, after that "Print("Wtf is happening here?" all begins to work. Any ideas why?
The same happens when I try to write something into the same file, using the same code, in the OnTick() function.
What I already did:
I looked into another similar topic here in StackOverflow and checked the answers without success.
I also asked ChatGPT in several attempts and checked all the answers and tips it gave to me.
I took this code and copied it into a script and it works perfectly.
Since I wrote that code again to open the file, I copied a code I did in the past to do the same, but in this past EA it works and in the present EA it doesn't work.
I filled this part of the code with GetLastError() but it never apeared any error.
Thank you very much in advance!
bool Flag,FlagBuy,FlagSell;
int Error;
int TicketLTL_A_S,TicketLTL_B_S,TicketLTL_C_S,TicketLBL_A_S,TicketLBL_B_S,TicketLBL_C_S;
int TicketLTL_A_B,TicketLTL_B_B,TicketLTL_C_B,TicketLBL_A_B,TicketLBL_B_B,TicketLBL_C_B;
int TakeProfit,StopLoss; // Has to be integer, not bool.
int filehandle;
double Spread,FirstRefPrice,Interval,Lots;
double LadderStepTop_LevelC,LadderStepTop_LevelB,StepUpPrice,LadderStepTop_LevelA,LadderStepBottom_LevelA,StepDownPrice,LadderStepBottom_LevelB,LadderStepBottom_LevelC;
int fileHandle;
string fileName="AccountStatus.csv";
string dataRow;
int OnInit() {
// Please adjust the following parameters:
Spread=Ask-Bid;
Interval=0.002;
Lots=0.01;
TakeProfit=1; // 1=activate, 0=deactivate
StopLoss=0; // 1=activate, 0=deactivate
//File for statistics. It simply doesn't work, without any error.
fileHandle = FileOpen(fileName, FILE_WRITE|FILE_CSV); //Open the file for writing (create it if it doesn't exist)
if (fileHandle != INVALID_HANDLE) { // Check if the file was opened successfully
Print("File opened/created successfully.");
// Write data to the file
dataRow = "Init Date;Time"; // Replace with your data headers
FileWrite(fileHandle, dataRow); // Write the header row
dataRow = TimeToString(TimeCurrent(), TIME_DATE | TIME_MINUTES);
FileWrite(fileHandle, dataRow);
dataRow = "DateTime;Balance;Equity;Margin";
FileWrite(fileHandle, dataRow);
FileClose(fileHandle);
}
else {
Print("Error opening the file: ", GetLastError());
}
Print("Wtf is happening here? This print looks to be inhibited. ",GetLastError()); // Up to this, nothing happens at all.
// It begins to work from here on.
if(OrdersTotal()>0) { // If there are any order placed, opened or pending, then
if(OrderSelect(0, SELECT_BY_POS)) { // Select any order from the pool, like the first=0
Quote
Report
StickFix · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: StickFix
Original post: https://stackoverflow.com/a/77280545
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Solution:
After seeing that other strange things happened like that nothing happens when I compile the EA again when it should restart the EA on the chart, I thought about reinstalling the MT4 platform. But wait: let's test less aggressive methods first, since other EAs were working well.
I simply "Saved as..." the EA under a different name, compiled it, attached it to the chart and wow! Everything is working now.
What I think may have happened, is that after compiling the same EA numerous times, something must have broken within the MT4 platform regarding this particular EA. Restarting that process or putting it on another rail was the solution.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: StickFix Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/77277399 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I'm a little perplexed by what I see happening, or rather, by what I DON'T see happening. In the code I'm showing you next, the code begins to work from the if(OrdersTotal()>0) on, but all what is before simply doesn't give any life sign. No errors, nothing. Not even the Print works. But as I said, after that "Print("Wtf is happening here?" all begins to work. Any ideas why? The same happens when I try to write something into the same file, using the same code, in the OnTick() function. What I already did: I looked into another similar topic here in StackOverflow and checked the answers without success. I also asked ChatGPT in several attempts and checked all the answers and tips it gave to me. I took this code and copied it into a script and it works perfectly. Since I wrote that code again to open the file, I copied a code I did in the past to do the same, but in this past EA it works and in the present EA it doesn't work. I filled this part of the code with GetLastError() but it never apeared any error. Thank you very much in advance! bool Flag,FlagBuy,FlagSell; int Error; int TicketLTL_A_S,TicketLTL_B_S,TicketLTL_C_S,TicketLBL_A_S,TicketLBL_B_S,TicketLBL_C_S; int TicketLTL_A_B,TicketLTL_B_B,TicketLTL_C_B,TicketLBL_A_B,TicketLBL_B_B,TicketLBL_C_B; int TakeProfit,StopLoss; // Has to be integer, not bool. int filehandle; double Spread,FirstRefPrice,Interval,Lots; double LadderStepTop_LevelC,LadderStepTop_LevelB,StepUpPrice,LadderStepTop_LevelA,LadderStepBottom_LevelA,StepDownPrice,LadderStepBottom_LevelB,LadderStepBottom_LevelC; int fileHandle; string fileName="AccountStatus.csv"; string dataRow; int OnInit() { // Please adjust the following parameters: Spread=Ask-Bid; Interval=0.002; Lots=0.01; TakeProfit=1; // 1=activate, 0=deactivate StopLoss=0; // 1=activate, 0=deactivate //File for statistics. It simply doesn't work, without any error. fileHandle = FileOpen(fileName, FILE_WRITE|FILE_CSV); //Open the file for writing (create it if it doesn't exist) if (fileHandle != INVALID_HANDLE) { // Check if the file was opened successfully Print("File opened/created successfully."); // Write data to the file dataRow = "Init Date;Time"; // Replace with your data headers FileWrite(fileHandle, dataRow); // Write the header row dataRow = TimeToString(TimeCurrent(), TIME_DATE | TIME_MINUTES); FileWrite(fileHandle, dataRow); dataRow = "DateTime;Balance;Equity;Margin"; FileWrite(fileHandle, dataRow); FileClose(fileHandle); } else { Print("Error opening the file: ", GetLastError()); } Print("Wtf is happening here? This print looks to be inhibited. ",GetLastError()); // Up to this, nothing happens at all. // It begins to work from here on. if(OrdersTotal()>0) { // If there are any order placed, opened or pending, then if(OrderSelect(0, SELECT_BY_POS)) { // Select any order from the pool, like the first=0
Checking account access…