Seeking Opinions/Comments on EA Template

 

Hi!

Would like to ask for your opinions and comments on the structure of the following code. 

My main concerns are as on the:

1. The code is a template. The specifics of Open & Close conditions are negligible. So are the values of extern variables. My main goal is to create a template where I can plug and play any number and manner of indicators and parameters I can conceive of.

2. The code will be launched in around 30 currency pairs. It must be able to distinguish and OrderSelect() and OrderClose() only the orders that are initiated by the same EA on the same pair.

3. NormalizeDouble() is used for lack of an alternative that I have understood. I may use MathRound() if I found more reason to do so. However, the difference between the 2 has proven to be elusive for me.

4. I only aim to run this in currency pairs. Not on indices or stocks. Though in the future, I may try to run them at commodities, metals and oil. Means to make it applicable to the aforementioned are welcome.

5. A main consideration is reduced processing power and processing time. Means to make it faster and to streamline its processes are most welcome.

As always, thank you for your support.

#property strict

extern int MagicNumber=10001;
extern double Lots =0.1;
extern double StopLoss=0;
extern double TakeProfit=0;
extern int TrailingStop=50;
extern int Slippage=3;

void OnTick()
{
   double MyPoint=Point;
   if(Digits==3 || Digits==5) MyPoint=Point*10;
   
   int Indi1Time=14;
   int Indi1Level=30;
   if(OrdersTotal()==0 ) 
   {
      int result=0;
      if((iADX(NULL,PERIOD_CURRENT,Indi1Time,PRICE_CLOSE,0,2)<Indi1Level)&&(iADX(NULL,PERIOD_CURRENT,Indi1Time,PRICE_CLOSE,0,1)>Indi1Level)&&(Close[1]>iMA(NULL,PERIOD_CURRENT,Indi1Time,0,MODE_SMA,PRICE_CLOSE,1)))
      {
         result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,NULL,MagicNumber,0,Blue);
         if(result>0)
         {
            if((TakeProfit>0) || (StopLoss>0))
            {
               if(!OrderSelect(result,SELECT_BY_TICKET))
               Print("Error select "+string(GetLastError()));
               if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask-StopLoss*MyPoint,Digits),NormalizeDouble(Ask+TakeProfit*MyPoint,Digits),0,Green))
               Print("Error modify stop loss / take profit "+string(GetLastError()));
            }
         }
      }
      if((iADX(NULL,PERIOD_CURRENT,Indi1Time,PRICE_CLOSE,0,2)<Indi1Level)&&(iADX(NULL,PERIOD_CURRENT,Indi1Time,PRICE_CLOSE,0,1)>Indi1Level)&&(Close[1]<iMA(NULL,PERIOD_CURRENT,Indi1Time,0,MODE_SMA,PRICE_CLOSE,1)))
      {
         result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,NULL,MagicNumber,0,Red);
         if(result>0)
         {
            if((TakeProfit>0) || (StopLoss>0))
            {
               if(!OrderSelect(result,SELECT_BY_TICKET))
               Print("Error select "+string(GetLastError()));
               if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid+StopLoss*MyPoint,Digits),NormalizeDouble(Bid-TakeProfit*MyPoint,Digits),0,Green))
               Print("Error modify stop loss / take profit "+string(GetLastError()));
            }
         }
      }
   }
  
   for(int cnt=0;cnt<OrdersTotal();cnt++)
   {
      if(!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      Print("Error select "+string(GetLastError()));
      {
            if((OrderType()==OP_BUY) && (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber))  
            {
               if((iADX(NULL,PERIOD_CURRENT,Indi1Time,PRICE_CLOSE,0,2)>Indi1Level)&&(iADX(NULL,PERIOD_CURRENT,Indi1Time,PRICE_CLOSE,0,1)<Indi1Level))
               {
                  if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red))
                  Print("Error close order "+string(GetLastError()));
               }
               if((TrailingStop>0) && (Bid-OrderOpenPrice()>MyPoint*TrailingStop) && (Bid-OrderStopLoss()>MyPoint*TrailingStop))
               {
                  if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-TrailingStop*MyPoint,Digits),OrderTakeProfit(),0,Green))
                  Print("Error modify trailing stop "+string(GetLastError()));
               }
            }
         else 
         {
            if((OrderType()==OP_SELL) && (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber))
            {
               if((iADX(NULL,PERIOD_CURRENT,Indi1Time,PRICE_CLOSE,0,2)>Indi1Level)&&(iADX(NULL,PERIOD_CURRENT,Indi1Time,PRICE_CLOSE,0,1)<Indi1Level))
               {
                  if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red))
                  Print("Error close order "+string(GetLastError()));
               }
               if((TrailingStop>0) && (OrderOpenPrice()-Ask>MyPoint*TrailingStop) && (((MathAbs(OrderStopLoss()-Ask))>MyPoint*TrailingStop)))
               {
                  if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+MyPoint*TrailingStop,Digits),OrderTakeProfit(),0,Red))
                  Print("Error modify trailing stop "+string(GetLastError()));
               }
            }
         }
      }
   }
}

Nothing follows.

Reason: