EA not executing trades but shows no errors

 

Hello everyone,

im building my first EA, it uses a custom indicator that is a two lines cross indicator, i have also made the EA so it calculates the StopLoss and TakeProfit level using the ATR multiplier, the problem that i am having is that the EA does't take trades, it shows no errors in the journal or in the metaeditor. Here is the code, can someone please give me some advice on what to do?

//+------------------------------------------------------------------+
//|                                                    system01h.mq4 |
//|                                      Copyright 2020, Kristijan O |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, Kristijan O"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//-------------------------------------------------------------------+
//--- input parameters
input double   Risk=0.0125;            //Risk per trade
input double   Lots=0.01;              //Volume
input    int      StopLoss = 0;
input   bool           ATR = false;
input    int ATRMultiplier = 1.5;      //StopLoss ATR multiplier

input    int      TakeProfit = 0;
input    int ATRMultiplier2 = 1;       //TakeProfit ATR multiplier
//+------------------------------------------------------------------+
//|Stop Loss Calculation                                                                  |
//+------------------------------------------------------------------+
double StpLoss(int i)
  {
   double SL=0;
   if(StopLoss==0 && !ATR)
      SL=0;
   else
      if(StopLoss>0 && !ATR)
        {
         double MyPoint=Point;
         if(Digits==3 || Digits==5)
            MyPoint=Point*10;
         if(i==0)
            SL=Ask-(StopLoss*MyPoint);
         if(i==1)
            SL=Bid+(StopLoss*MyPoint);
        }
      else
         if(ATR)
           {
            double AvTR=iATR(Symbol(),30,14,0);
            if(i==0)
               SL=Ask-(ATRMultiplier*AvTR);
            if(i==1)
               SL=Bid+(ATRMultiplier*AvTR);
           }
   return(SL);
  }
//+------------------------------------------------------------------+
//|Take Profit Calculation                                                                |
//+------------------------------------------------------------------+
double TakeProfit(int k)
  {
   double TP=0;
   if(TakeProfit==0 && !ATR)
      TP=0;
   else
      if(TakeProfit>0 && !ATR)
        {
         double MyPoint=Point;
         if(Digits==3 || Digits==5)
            MyPoint=Point*10;
         if(k==0)
            TP=Ask+(TakeProfit*MyPoint);
         if(k==1)
            TP=Bid-(TakeProfit*MyPoint);
        }
      else
         if(ATR)
           {
            double AvTR=iATR(Symbol(),30,14,0);
            if(k==0)
               TP=Ask+(ATRMultiplier2*AvTR);
            if(k==1)
               TP=Bid-(ATRMultiplier2*AvTR);
           }
   return(TP);
  }

//+------------------------------------------------------------------+
// for market excuting orders Buy(i=0)-->(StpLoss(0)) / Sell(i=1)-->(StpLoss(1))---> vpiši v OrderSend za OP_BUY StpLoss(0), za OP_SL StplLoss(1)
// in obratno za Take profit
//
// OR for OrderModify() you can put StopLoss= StpLoss(OrderType())
//-------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() 
  {
   return(0);
  }
//+------------------------------------------------------------------+
int start()                                  // Special function start()
  {
   double Blau1 = iCustom(NULL,0,"Blau - smi averages",12,23,1,MODE_EMA,5,MODE_EMA,PRICE_CLOSE,0,1,0); // Firs variable of indicator---> Green line
   double Blau2 = iCustom(NULL,0,"Blau - smi averages",12,23,1,MODE_EMA,5,MODE_EMA,PRICE_CLOSE,0,2,0); // Second vaiable of indicator---> Yellow line
//--------------------------------------------------------------------+   
//--------------------------------------------------------------------+
// Trade criteria and execution
   if(Blau1 > Blau2 && OrdersTotal()==0)
      OrderSend(NULL,OP_BUY,Lots,Ask,3,StpLoss(0),TakeProfit(1));

   if(Blau1 < Blau2 && OrdersTotal()==0)
      OrderSend(NULL,OP_SELL,Lots,Bid,3,StpLoss(1),TakeProfit(0));
   return(INIT_SUCCEEDED);                                   // Exit start()
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
 
  1. KristijanO: can someone please give me some advice on what to do?

    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?

  2.             TP=Ask+(TakeProfit*MyPoint);

    You buy at the Ask and sell at the Bid.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using the Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134.

  3. int start()                                  // Special function start()
      {
    ⋮
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason){}
    //+------------------------------------------------------------------+
    //| Expert tick function                                             |
    //+------------------------------------------------------------------+
    void OnTick()
      {
      }
    You should stop using the old event handlers and IndicatorCounted() and start using new event handlers. You can not use both.
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 2016.05.11