EA Not Taking Trade

 

Hi,

I created this EA but somehow I noticed its not taking trade.

I do not know what I am missing.

Please can some one help?

Thank you

//+------------------------------------------------------------------+
//|                                           Strategy: Zima 222.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+

#property version   "1.00"
#property description ""
#property tester_indicator "icustom_OsMA_Color_xb4__1"

#include <stdlib.mqh>
#include <stderror.mqh>

extern int GP_lauer_GrossPeriod = 5;
extern int Length = 10;
extern int GP_lauer_GrossPeriod1 = 15;
extern int GP_lauer_GrossPeriod2 = 30;
extern int GP_lauer_GrossPeriod3 = 60;
extern int LinearReg = 20;
extern int PERIOD_CURRENT1 = 5;
extern double TP_Pips = 10;
extern double SL_Pips = 10;
extern int SR_Interval = 8;
extern int SR_Shift = 0;
extern double Pending_pip = 5;
extern double Trail_PIP = 30;
extern double Trail_Step = 10;
extern int Length2 = 20;
extern int TGG_TF = 5;
extern int TGG_TF2 = 15;
extern int TGG_TF3 = 30;
extern int TGG_TF4 = 60;
extern int Candle_MA_Period1 = 20;
extern int lreg = 34;
extern int HMAPeriod = 34;
extern double Trail_PIPS = 10;
extern int TF1h = 60;
extern int GP_lauer_GrossPeriod4 = 5;
extern int Length3 = 15;
extern int SR_Bar_Interval = 12;
extern int SR_Shift1 = 0;
extern double SL_SR_PIP = 5;
extern int Candle_MA_Period2 = 49;
extern int ADX_TF = 15;
extern int CCF_TF = 15;
extern int Vix1 = 6;
extern int Candle_SMA_Period2 = 100;
int LotDigits; //initialized in OnInit
extern int MagicNumber = 301;
extern double TradeSize = 0.1;
extern double MaxSpread = 30;
extern int MaxSlippage = 15; //adjusted in OnInit
extern int MaxOpenTrades = 1;
int MaxLongTrades = 1000;
int MaxShortTrades = 1000;
extern int MaxPendingOrders = 1;
int MaxLongPendingOrders = 1000;
int MaxShortPendingOrders = 1000;
bool Hedging = false;
int OrderRetry = 5; //# of retries if sending order returns error
int OrderWait = 5; //# of seconds to wait if sending order returns error
double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | Zima 222 @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

int TradesCount(int type) //returns # of open trades for order type, current symbol and magic number
  {
   int result = 0;
   int total = OrdersTotal();
   for(int i = 0; i < total; i++)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) continue;
      if(OrderMagicNumber() != MagicNumber || OrderSymbol() != Symbol() || OrderType() != type) continue;
      result++;
     }
   return(result);
  }

int myOrderSend(int type, double price, double volume, string ordername) //send order, return ticket ("price" is irrelevant for market orders)
  {
   if(!IsTradeAllowed()) return(-1);
   int ticket = -1;
   int retries = 0;
   int err = 0;
   int long_trades = TradesCount(OP_BUY);
   int short_trades = TradesCount(OP_SELL);
   int long_pending = TradesCount(OP_BUYLIMIT) + TradesCount(OP_BUYSTOP);
   int short_pending = TradesCount(OP_SELLLIMIT) + TradesCount(OP_SELLSTOP);
   string ordername_ = ordername;
   if(ordername != "")
      ordername_ = "("+ordername+")";
   //test Hedging
   if(!Hedging && ((type % 2 == 0 && short_trades + short_pending > 0) || (type % 2 == 1 && long_trades + long_pending > 0)))
     {
      myAlert("print", "Order"+ordername_+" not sent, hedging not allowed");
      return(-1);
     }
   //test maximum trades
   if((type % 2 == 0 && long_trades >= MaxLongTrades)
   || (type % 2 == 1 && short_trades >= MaxShortTrades)
   || (long_trades + short_trades >= MaxOpenTrades)
   || (type > 1 && type % 2 == 0 && long_pending >= MaxLongPendingOrders)
   || (type > 1 && type % 2 == 1 && short_pending >= MaxShortPendingOrders)
   || (type > 1 && long_pending + short_pending >= MaxPendingOrders)
   )
     {
      myAlert("print", "Order"+ordername_+" not sent, maximum reached");
      return(-1);
     }
   //prepare to send order
   while(IsTradeContextBusy()) Sleep(100);
   RefreshRates();
   if(type == OP_BUY)
      price = Ask;
   else if(type == OP_SELL)
      price = Bid;
   else if(price < 0) //invalid price for pending order
     {
      myAlert("order", "Order"+ordername_+" not sent, invalid price for pending order");
          return(-1);
     }
   int clr = (type % 2 == 1) ? clrRed : clrBlue;
   if(MaxSpread > 0 && Ask - Bid > MaxSpread * myPoint)
     {
      myAlert("order", "Order"+ordername_+" not sent, maximum spread "+DoubleToStr(MaxSpread * myPoint, Digits())+" exceeded");
      return(-1);
     }
   while(ticket < 0 && retries < OrderRetry+1)
     {
      ticket = OrderSend(Symbol(), type, NormalizeDouble(volume, LotDigits), NormalizeDouble(price, Digits()), MaxSlippage, 0, 0, ordername, MagicNumber, 0, clr);
      if(ticket < 0)
        {
         err = GetLastError();
         myAlert("print", "OrderSend"+ordername_+" error #"+IntegerToString(err)+" "+ErrorDescription(err));
         Sleep(OrderWait*1000);
        }
      retries++;
     }
   if(ticket < 0)
     {
      myAlert("error", "OrderSend"+ordername_+" failed "+IntegerToString(OrderRetry+1)+" times; error #"+IntegerToString(err)+" "+ErrorDescription(err));
      return(-1);
     }
   string typestr[6] = {"Buy", "Sell", "Buy Limit", "Sell Limit", "Buy Stop", "Sell Stop"};
   myAlert("order", "Order sent"+ordername_+": "+typestr[type]+" "+Symbol()+" Magic #"+IntegerToString(MagicNumber));
   return(ticket);
  }

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {   
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
      MaxSlippage *= 10;
     }
   //initialize LotDigits
   double LotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
   if(NormalizeDouble(LotStep, 3) == round(LotStep))
      LotDigits = 0;
   else if(NormalizeDouble(10*LotStep, 3) == round(10*LotStep))
      LotDigits = 1;
   else if(NormalizeDouble(100*LotStep, 3) == round(100*LotStep))
      LotDigits = 2;
   else LotDigits = 3;
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int ticket = -1;
   double price;   
   int mb_ret; //MessageBox
   
   
   //Open Buy Order (buy momo 0)
   if(iCustom(NULL, PERIOD_CURRENT, "icustom_OsMA_Color_xb4__1", 0, 1) != 0 && iCustom(NULL, PERIOD_CURRENT, "icustom_OsMA_Color_xb4__1", 0, 1) != EMPTY_VALUE //icustom_OsMA_Color_xb4__1 is not equal to fixed value
   && iCustom(NULL, PERIOD_CURRENT, "icustom_OsMA_Color_xb4__1", 0, 0) != 0 && iCustom(NULL, PERIOD_CURRENT, "icustom_OsMA_Color_xb4__1", 0, 0) != EMPTY_VALUE //icustom_OsMA_Color_xb4__1 is not equal to fixed value
   )
     {
      RefreshRates();
      price = Ask;   
      if(IsTradeAllowed())
        {
         mb_ret = MessageBox("Open Buy Order (buy momo 0) "+DoubleToString(TradeSize)+" lots? [Zima 222 @ "+Symbol()+","+IntegerToString(Period())+"]", "Manual Order Confirmation", MB_YESNO);
         if(mb_ret == IDYES)
            ticket = myOrderSend(OP_BUY, price, TradeSize, "buy momo 0");
         if(ticket <= 0) return;
        }
      else //not autotrading => only send alert
         myAlert("order", "buy momo 0");
     }
   
   //Open Sell Order (buy momo 0)
   if(iCustom(NULL, PERIOD_CURRENT, "icustom_OsMA_Color_xb4__1", 1, 1) != 0 && iCustom(NULL, PERIOD_CURRENT, "icustom_OsMA_Color_xb4__1", 1, 1) != EMPTY_VALUE //icustom_OsMA_Color_xb4__1 is not equal to fixed value
   && iCustom(NULL, PERIOD_CURRENT, "icustom_OsMA_Color_xb4__1", 1, 0) != 0 && iCustom(NULL, PERIOD_CURRENT, "icustom_OsMA_Color_xb4__1", 1, 0) != EMPTY_VALUE //icustom_OsMA_Color_xb4__1 is not equal to fixed value
   )
     {
      RefreshRates();
      price = Bid;   
      if(IsTradeAllowed())
        {
         mb_ret = MessageBox("Open Sell Order (buy momo 0) "+DoubleToString(TradeSize)+" lots? [Zima 222 @ "+Symbol()+","+IntegerToString(Period())+"]", "Manual Order Confirmation", MB_YESNO);
         if(mb_ret == IDYES)
            ticket = myOrderSend(OP_SELL, price, TradeSize, "buy momo 0");
         if(ticket <= 0) return;
        }
      else //not autotrading => only send alert
         myAlert("order", "buy momo 0");
     }
  }
//+------------------------------------------------------------------+
Reason: