Trix indicator EA zero divide error

 

Hi i am keep getting zero divide error on my EA with Trix indicator. can you help me?

Indicator is attached below

and this is my EA:

//+------------------------------------------------------------------+
//|                                                         test.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#include <FinalCustomFunctions.mqh>

input double riskPerTrade = 0.02;

int magicNB = 55555;

//trix index
extern int  TRIX_Period    =13;
extern int  Signal_Period  =8;
extern bool Signals        =true;
extern int  CountBars      =1500;


//ATR

input int InpAtrPeriod=14;


int openOrderID;




//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---


   

   //ATR
   double ATR = iCustom(_Symbol, _Period, "ATR", InpAtrPeriod, 0,1);
   int TrailingStop = ATR *2;
   
   
   double blue = iCustom(_Symbol, _Period, "Entry//TRIX",TRIX_Period, Signal_Period,Signals, CountBars, 0,1);
   double red = iCustom(_Symbol, _Period, "Entry//TRIX",TRIX_Period, Signal_Period,Signals, CountBars, 1,1);
   
   
   
   
   
   
   
   
   
   
   if(!CheckIfOpenOrdersByMagicNB(magicNB)){
   
   
   
    if(blue >red ){
    
         Print( "Sending buy order");

         double stopLossPrice = Bid - ATR * 1.5;

         double takeProfitPrice = Bid + ATR;

         //Print("Entry Price = " + Ask);

         //Print("Stop Loss Price = " + stopLossPrice);

         //Print("Take Profit Price = " + takeProfitPrice);

         

         double lotSize = OptimalLotSize(riskPerTrade,Bid,stopLossPrice);

         

         openOrderID = OrderSend(NULL,OP_BUYLIMIT,lotSize,Bid,10,stopLossPrice,takeProfitPrice,NULL,magicNB);
         

         if(openOrderID < 0) Alert("Buy order rejected. Order error: " + GetLastError());
    
    
    
    }else if( red > blue ){
         Print(" Sending short order");

         double stopLossPrice = Ask + ATR * 1.5;

         double takeProfitPrice = Ask - ATR;

         //Print("Entry Price = " + Bid);

         //Print("Stop Loss Price = " + stopLossPrice);

         //Print("Take Profit Price = " + takeProfitPrice);

          

          double lotSize = OptimalLotSize(riskPerTrade,Ask,stopLossPrice);



          openOrderID = OrderSend(NULL,OP_SELLLIMIT,lotSize,Ask,10,stopLossPrice,takeProfitPrice,NULL,magicNB);
          
         

          if(openOrderID < 0) Alert(" Sell order rejected. Order error: " + GetLastError());
    
    }
  }
  
 }
//+------------------------------------------------------------------+
Files:
Trix.mq4  5 kb
 

Highlight the line(s) where you are getting the error.

Please remove all the unnecessary empty lines in your codes. It makes it easier for others to read.

Reason: