mq4 read file and enter in trade

 

Hello!I have a text file with setups and .mq4 file that reads my file where are the trades and enter in them but it deosn't work.

I will be very happy if someone could help me!

#property copyright "Expert Advisor"
#property version   "1.00"
#property strict

input string FilePath = "trade_signals.txt";  // Calea către fișierul cu semnale
input double RiskAmount = 24.0;              // Risc maxim per trade (în $)

//+------------------------------------------------------------------+
//| Funcție de inițializare                                          |
//+------------------------------------------------------------------+
int OnInit() {
    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Funcție principală (executată la fiecare tick)                   |
//+------------------------------------------------------------------+
void OnTick() {
    ProcessTradeSignals();
    CheckForTP();
}

//+------------------------------------------------------------------+
//| Procesează semnalele din fișier                                  |
//+------------------------------------------------------------------+
void ProcessTradeSignals() {
    int handle = FileOpen(FilePath, FILE_READ|FILE_TXT);
    if(handle == INVALID_HANDLE) {
        Print("Eroare la deschiderea fișierului: ", GetLastError());
        return;
    }

    while(!FileIsEnding(handle)) {
        string line = FileReadString(handle);
        string parts[5];
        StringSplit(line, ',', parts);
        
        if(ArraySize(parts) != 5) continue;

        string pair = StringTrim(parts[0]);
        string orderType = StringTrim(parts[1]);
        double entry = StringToDouble(StringTrim(parts[2]));
        double sl = StringToDouble(StringTrim(parts[3]));
        string tps = StringSubstr(parts[4], 1, StringLen(parts[4])-2);

        string tpArray[];
        int tpCount = StringSplit(tps, ',', tpArray);
        
        if(tpCount == 0) continue;

        // Calculează LOT TOTAL pentru toate TP-urile
        double point = MarketInfo(pair, MODE_POINT);
        double tickValue = MarketInfo(pair, MODE_TICKVALUE);
        double slDistance = MathAbs(entry - sl)/point;
        
        if(slDistance == 0 || tickValue == 0) continue;
        
        double totalLot = RiskAmount / (slDistance * tickValue);
        totalLot = NormalizeDouble(totalLot, 2);
        
        // Împarte lotul total în părți egale pentru fiecare TP
        double lotPerTP = totalLot / tpCount;
        lotPerTP = NormalizeDouble(lotPerTP, 2);

        // Plasează un singur ordin cu TP progresiv
        int cmd = GetAdjustedOrderType(pair, orderType, entry);
        if(cmd != -1) {
            PlaceOrderWithMultipleTPs(pair, cmd, totalLot, entry, sl, tpArray);
        }
    }
    FileClose(handle);
}

//+------------------------------------------------------------------+
//| Plasează un ordin cu TP-uri multiple                             |
//+------------------------------------------------------------------+
void PlaceOrderWithMultipleTPs(string pair, int cmd, double lot, double price, double sl, string &tpArray[]) {
    if(MarketInfo(pair, MODE_TRADEALLOWED) == 0) return;
    
    // Plasează ordinul principal fără TP
    int ticket = OrderSend(pair, cmd, lot, price, 3, sl, 0, "MULTI_TP", 0);
    
    if(ticket > 0) {
        // Adaugă TP-uri ca ordine separate
        for(int i = 0; i < ArraySize(tpArray); i++) {
            double tp = StringToDouble(StringTrim(tpArray[i]));
            OrderModify(ticket, 0, sl, tp, 0, clrNONE);
        }
    }
}

//+------------------------------------------------------------------+
//| Verifică atingerea TP-urilor și închide parțial                  |
//+------------------------------------------------------------------+
void CheckForTP() {
    for(int i = 0; i < OrdersTotal(); i++) {
        if(OrderSelect(i, SELECT_BY_POS)) {
            if(StringFind(OrderComment(), "MULTI_TP") != -1) {
                double currentTP = OrderTakeProfit();
                double currentPrice = MarketInfo(OrderSymbol(), MODE_BID);
                
                if((OrderType() == OP_BUY && currentPrice >= currentTP) ||
                   (OrderType() == OP_SELL && currentPrice <= currentTP)) {
                    // Închide jumătate din poziție
                    double closeLot = OrderLots() / 2;
                    OrderClose(OrderTicket(), closeLot, currentPrice, 3, clrNONE);
                }
            }
        }
    }
}

// ... (Restul funcțiilor rămân identice cu versiunea anterioară)
 
SAMURATY: I will be very happy if someone could help me!
  1. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

  2.    int handle = FileOpen(FilePath, FILE_READ|FILE_TXT);

    You haven't specified if your file is ANSI or Unicode.