Please help, no trades in backtest.

 

//+------------------------------------------------------------------+
//|                                                          CCI.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                                    CCI Bot.mq5   |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property strict

input int cciLength = 20             // CCI Period
input double lotSize = 0.5;           // Lot size
input int takeProfit = 1000;           // Take Profit in points
input int stopLoss = 1000;             // Stop Loss in points
input string startTradeTime = "07:30";     // Trading start time
input string endTradeTime = "09:30";       // Trading end time

double cciValue;
bool tradeToday = false;
datetime lastTradeDay = 0;

//+------------------------------------------------------------------+
//| Expert initialization function                                  |
//+------------------------------------------------------------------+
int OnInit()
{
    // Initialization here (if necessary)
    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert tick function                                            |
//+------------------------------------------------------------------+
void OnTick()
{
    // Current time and date
    datetime currentTime = TimeCurrent();
    MqlDateTime strTime;
    TimeToStruct(currentTime, strTime);

    // Checking if the current time is within the trading window
    bool timeAllowed = TimeInRange(strTime, startTradeTime, endTradeTime);

    // Calculating CCI value
    cciValue = iCCI(_Symbol, PERIOD_M30, cciLength, PRICE_CLOSE);
    
    // Checking if trading has already occurred today
    if (lastTradeDay < iTime(_Symbol, 0, 0))
        tradeToday = false;

    // Trading conditions
    bool longCondition = cciValue > 120 && timeAllowed && !tradeToday;
    bool shortCondition = cciValue < -120 && timeAllowed && !tradeToday;

    // Trade logic
    if (longCondition)
    {
        // Open Long Position
        OpenTrade(ORDER_TYPE_BUY);
        tradeToday = true;
        lastTradeDay = currentTime;
    }
    else if (shortCondition)
    {
        // Open Short Position
        OpenTrade(ORDER_TYPE_SELL);
        tradeToday = true;
        lastTradeDay = currentTime;
    }
}

//+------------------------------------------------------------------+
// Helper functions and further implementation
//+------------------------------------------------------------------+

// Function to check if the current time is within the specified time interval
bool TimeInRange(MqlDateTime &time, string start, string end)
{
    // Time conversion
    int startTime = ConvertStringToTime(start);
    int endTime = ConvertStringToTime(end);
    int currentTime = TimeToMinutes(time.hour, time.min);

    return (currentTime >= startTime && currentTime <= endTime);
}

// Helper function to convert hours and minutes to minutes since midnight
int TimeToMinutes(int hour, int minute)
{
    return (hour * 60 + minute);
}

// Helper function to convert a time string to minutes since midnight
int ConvertStringToTime(string time)
{
    StringReplace(time, ":", "");
    long hour = StringToInteger(StringSubstr(time, 0, 2));
    long minute = StringToInteger(StringSubstr(time, 2, 2));
    return TimeToMinutes(int(hour), int(minute));
}

// Function to open trades
void OpenTrade(ENUM_ORDER_TYPE orderType)
{
    // Setting order parameters
    MqlTradeRequest tradeRequest;
    tradeRequest.action = TRADE_ACTION_DEAL;
    tradeRequest.type = orderType;
    tradeRequest.symbol = _Symbol;
    tradeRequest.volume = lotSize;
    tradeRequest.price = (orderType == ORDER_TYPE_BUY) ? SymbolInfoDouble(_Symbol, SYMBOL_ASK) : SymbolInfoDouble(_Symbol, SYMBOL_BID);
    tradeRequest.sl = (orderType == ORDER_TYPE_BUY) ? tradeRequest.price - stopLoss * _Point : tradeRequest.price + stopLoss * _Point;
    tradeRequest.tp = (orderType == ORDER_TYPE_BUY) ? tradeRequest.price + takeProfit * _Point : tradeRequest.price - takeProfit * _Point;
    tradeRequest.deviation = 10;
    tradeRequest.magic = 0;
    tradeRequest.comment = "CCI Bot Trade";

    // Debugging information before sending the order
    Print("Attempting to open trade: ", (orderType == ORDER_TYPE_BUY) ? "BUY" : "SELL");
    Print("Price: ", tradeRequest.price);
    Print("SL: ", tradeRequest.sl);
    Print("TP: ", tradeRequest.tp);

    // Sending the order
    MqlTradeResult tradeResult;
    if (!OrderSend(tradeRequest, tradeResult))
    {
        Print("Trade Error: ", tradeResult.comment);
    }
    else
    {
        Print("Trade successful: ", (orderType == ORDER_TYPE_BUY) ? "BUY" : "SELL", " Ticket: ", tradeResult.order);
    }
}

Hello guys, could anyone tell me why my script doesn't do a trade in the backtest? Need help pleeease. Und same conditions, I can do some random scripts, but my own one doesn't work. (I speak German as well.)

Files:
SCRIPT.PNG  27 kb