Ea don't work, can' open or close position

 

can you help me, what's wrong in my EA:

#include <ErrorDescription.mqh>
string symbols[] = { "EURUSD","GBPUSD"}; //
string symbol;
double investedCapital = 1000;
double riskPercent = 0.01; // 1% de risque
double Ask;
double Bid;
double potentialProfit;
double Karray[];
double Darray[];
int trend;


void OnTick()
  {
   ArraySetAsSeries(Karray, true);
   ArraySetAsSeries(Darray, true);

//filling arrays with price data


   for(int i = 0; i < ArraySize(symbols); i++)
     {

      // Définir le symbole actuel
      symbol = symbols[i];

      // Déterminer la tendance pour le symbole actuel
      trend = iStochastic(symbol, _Period, 14, 3, 3,MODE_SMA,STO_LOWHIGH);
      CopyBuffer(trend,0,0,3,Karray);
      CopyBuffer(trend,1,0,3,Darray);

      //calculating value of %K and %D line of cuurent data
      double KValue0 = Karray[0];
      double DValue0 = Darray[0];
      double KValue1 = Karray[1];
      double DValue1 = Darray[1];

      // Obtenir les cotations pour le symbole actuel
      Ask = SymbolInfoDouble(symbol, SYMBOL_ASK);
      Bid = SymbolInfoDouble(symbol, SYMBOL_BID);

      // Calcule le potentiel de profit pour le symbole actuel
      potentialProfit = 0;
      if(KValue0>80 && DValue0>80)
        {
         potentialProfit = Ask - Bid;
        }
      else
         if(KValue0<20 && DValue0<20)
           {
            potentialProfit = Bid - Ask;
           }

      // Ouvrir une position dans la direction de la tendance pour le symbole avec le meilleur rendement potentiel
      if(potentialProfit > 0)
        {
         trend = iStochastic(symbol, _Period, 14, 3, 3,MODE_SMA,STO_LOWHIGH);
         CopyBuffer(trend,0,0,3,Karray);
         CopyBuffer(trend,1,0,3,Darray);
         MqlTradeRequest request = {};
         MqlTradeResult result;
         request.symbol = symbol;
         request.volume =0.01; //(investedCapital * riskPercent);// / potentialProfit;
         request.sl = 0;
         request.tp = 0;
         request.comment = "";
         request.magic = 0;
         request.expiration = 0;
         //Print("request.volume: ", request.volume, " & investedCapital: ", investedCapital, " & riskPercent: ", riskPercent, " & potentialProfit: ", potentialProfit);
         if(KValue0>80 && DValue0>80 && KValue0<DValue0 && KValue1>DValue1)
           {
            request.type = ORDER_TYPE_BUY;
            request.price = Ask;
            if(OrderSend(request, result) && TRADE_RETCODE_DONE==result.retcode)
              {
               // Mettre à jour le capital investi
               investedCapital -= request.volume * (Ask - Bid);
              }
            else
              {
               // Gérer le cas d'erreur lors de l'envoi de la commande
               Print("Erreur lors de l'envoi de l'ordre d'achat : ", ErrorDescription(GetLastError()));
              }
           }

         else
            if(KValue0<20 && DValue0<20 && KValue0>DValue0 && KValue1<DValue1)
              {
               request.type = ORDER_TYPE_SELL;
               request.price = Bid;
               if(OrderSend(request, result) && TRADE_RETCODE_DONE==result.retcode)
                 {
                  // Mettre à jour le capital investi
                  investedCapital -= request.volume * (Bid - Ask);
                 }
               else
                 {
                  // Gérer le cas d'erreur lors de l'envoi de la commande
                  Print("Erreur lors de l'envoi de l'ordre de vente : ", ErrorDescription(GetLastError()));
                 }
              }
        }
     }
  }
//+------------------------------------------------------------------+
 
      trend = iStochastic(symbol, _Period, 14, 3, 3,MODE_SMA,STO_LOWHIGH);
      CopyBuffer(trend,0,0,3,Karray);

Perhaps you should read the manual, especially the examples.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
          MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
          How to call indicators in MQL5 - MQL5 Articles (2010)

 

thanks for links, they are very helpful.

i found the problem, this line is missing: 

request.action = TRADE_ACTION_DEAL;