EA in MT5 Buy and Sell won't trigger when using Strategy Tester. Can you please help?

 
//+------------------------------------------------------------------+
//|                                                    HelloMQL5.mq5 |
//|                                                           TarikR |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "TarikR"
#property link      ""
#property version   "1.00"
//+------------------------------------------------------------------+
//| Include                                                          |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>

//--- available signals
#include <Expert\Signal\SignalRSI.mqh>
#include <Expert\Signal\SignalMACD.mqh>
#include <Expert\Signal\SignalSAR.mqh>
#include <Expert\Signal\SignalMA.mqh>

//--- available trailing
#include <Expert\Trailing\TrailingNone.mqh>

//--- available money management
#include <Expert\Money\MoneyFixedLot.mqh>
#include <Trade/Trade.mqh>

int handle_iRSI;
double buffer_iRSI[];
int handle_iMACD;
double buffer_iMACD[];
int handle_iCustom;
double buffer_iCustom[];
int handle_iMA;
double buffer_iMA[];
int handle_iSAR;
double buffer_iSAR[];
int handle_iFractals;
double buffer_iFractals[];

bool m_init_error = false;
CTrade trade;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
void OnInit() {
    m_init_error = false;
    
    handle_iRSI = iRSI(_Symbol, Period(), 14, PRICE_CLOSE);
    ArrayResize(buffer_iRSI, 1);
    
    handle_iMACD = iMACD(_Symbol, Period(), 12, 26, 9, PRICE_CLOSE);
    ArrayResize(buffer_iMACD, 1);
    
    handle_iCustom = iCustom(_Symbol, Period(), "Donchian Channels");
    ArrayResize(buffer_iCustom, 1);
    
    handle_iMA = iMA(_Symbol, Period(), 200, 0, MODE_SMA, PRICE_CLOSE);
    ArrayResize(buffer_iMA, 1);
    
    handle_iSAR = iSAR(_Symbol, Period(), 0.02, 0.2);
    ArrayResize(buffer_iSAR, 1);
    
    handle_iFractals = iFractals(_Symbol, Period());
    ArrayResize(buffer_iFractals, 1);
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {
    if (m_init_error)
        return;

    MqlRates PriceArray[];
    double upper[], lower[];
    ArraySetAsSeries(upper, true);
    ArraySetAsSeries(lower, true);
    ArraySetAsSeries(PriceArray, true);

    int start_pos = 0, count = 6;
    int Data = CopyRates(_Symbol, Period(), start_pos, count, PriceArray);
    if(!iGetArray(handle_iFractals,UPPER_LINE,start_pos,count,upper) || !iGetArray(handle_iFractals,LOWER_LINE,start_pos,count,lower))
      return;

    bool buyConditionsMet = 0;
    bool sellConditionsMet = 0;

    // Buy conditions
    
    if (buffer_iRSI[0] < 30)
        buyConditionsMet++;
    if (buffer_iMACD[0] > 0)
        buyConditionsMet++;
    if (PriceArray[0].close > buffer_iCustom[0])
        buyConditionsMet++;
    if (PriceArray[0].close > buffer_iMA[0])
        buyConditionsMet++;
    if (PriceArray[0].close > buffer_iFractals[0])
        buyConditionsMet++;
    if (PriceArray[0].close < buffer_iSAR[0])
        buyConditionsMet++;
    if (iCustom(_Symbol, Period(), "Chaikin Money Flow", 0, 0) > 0)
        buyConditionsMet++;

    // Sell conditions
    if (buffer_iRSI[0] > 70)
        sellConditionsMet++;
    if (buffer_iMACD[0] < 0)
        sellConditionsMet++;
    if (PriceArray[0].close < buffer_iCustom[1])
        sellConditionsMet++;
    if (PriceArray[0].close < buffer_iMA[0])
        sellConditionsMet++;
    if (PriceArray[0].close < buffer_iFractals[0])
        sellConditionsMet++;
    if (PriceArray[0].close > buffer_iSAR[0])
        sellConditionsMet++;
    if (iCustom(_Symbol, Period(), "Chaikin Money Flow", 0, 0) < 0)
        sellConditionsMet++;

    // Trade execution based on conditions
    double Ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
    double Bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);

    if (buyConditionsMet >= 3 && PositionsTotal() < 1)
        trade.Buy(0.1, NULL, Ask, (Ask - 200 * _Point), (Ask + 150 * _Point), NULL);
        

    if (sellConditionsMet >= 3 && PositionsTotal() < 1)
        trade.Sell(0.1, NULL, Bid, (Bid + 200 * _Point), (Bid - 150 * _Point), NULL);

    string text = "";
    for (int i = 0; i < count; i++) {
        string text_upper = DoubleToString(upper[i], Digits());
        string text_lower = DoubleToString(lower[i], Digits());
        text = text + IntegerToString(i) + "#: " + "Upper " + text_upper + ", Lower " + text_lower + "\n";
    }
    Comment(text);
}

//+------------------------------------------------------------------+
//| Get value of buffers                                             |
//+------------------------------------------------------------------+
bool iGetArray(const int handle, const int buffer, const int start_pos,
    const int count, double &arr_buffer[]) {
    bool result = true;
    if (!ArrayIsDynamic(arr_buffer)) {
        PrintFormat("ERROR! EA: %s, FUNCTION: %s, this a no dynamic array!", __FILE__, __FUNCTION__);
        return (false);
    }
    ArrayFree(arr_buffer);
    ResetLastError();

    int copied = CopyBuffer(handle, buffer, start_pos, count, arr_buffer);
    if (copied != count) {
        PrintFormat("ERROR! EA: %s, FUNCTION: %s, amount to copy: %d, copied: %d, error code %d",
            __FILE__, __FUNCTION__, count, copied, GetLastError());
        return (false);
    }
    return (result);
}
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Reason: