Help with my first EA - it's kind of jacked...

 

Hi everyone.  I have working (searching the forum) the last few weeks and managed to pull together an EA that does not compile errors any more but the structure of it is all wrong and because is not executing at the proper times.  I was hoping some kind soul could take a look and help me to restructure my EA and maybe give some explanation of the changes.  Thanks in advance for any help, I will pass it on as I learn. 


Here is what I am trying to accomplish with my EA:


I have these extern inputs:

Lots=0.03;
Target_In_Dollars=5; This is the target where that I shoot for on the pair with all open orders (max 3) that tells the trailing stop to kick
Trailing_Stop=50;
Max_Orders=3;
Closed_Bars=0;
Distance_Back=24;
ADX=75; The trade will not open if 8period ADX is above 75
extern int Magic=717171;

Here is what is "supposed" to happen.... When a bar closes the EA check back 24 bars to for the signal, if its a go (signal is met and ADX < 75 and not exceeds max orders per) it opens the order of .03 lots at the ask price (no SL or TP at the time of order).  When the total price of all open orders on that chart with same magic number (717171) total $5 or greater it is supposed to then modify all open orders on that chart with that magic number with the trailing stop.


While there are no "errors" the EA does not function quite like explained.  I'm sure it's based on the structure and parentheses etc...


Thanks in advance for anyone taking the time to hold my hand this one time. Here is the code:

//+------------------------------------------------------------------+
//|                                                    MyFirstTestEA.mq4 |
//+------------------------------------------------------------------+

extern double Lots=0.03;
extern double Target_In_Dollars=5;
extern int Trailing_Stop=50;
extern int Max_Orders=3;
extern int Closed_Bars=0;
extern int Distance_Back=24;
extern int ADX=75;
extern int Magic=9348670;

int start() {
int EAOrdersTotal=0;
int mTotal = OrdersTotal();
for(int i = mTotal-1; i>=0; i--)
  {
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   if(OrderMagicNumber() ==Magic && OrderSymbol() ==Symbol()) EAOrdersTotal++;
  }
 
   if(OrderProfit() >=Target_In_Dollars)
   
  {
    {
     OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
     RefreshRates();
     if(OrderType()==OP_BUY && OP_SELL && OrderMagicNumber()==Magic && OrderSymbol()==Symbol())
     if (OrderStopLoss() ==0)
     OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*Trailing_Stop,Digits),OrderTakeProfit(),0,Blue);
     //OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue);
    }
  }
  
 
  
 double sig = Lowest(NULL,0,MODE_LOW,Distance_Back,0);
 if(EAOrdersTotal < Max_Orders)
 if (iADX(NULL, 0, 8, PRICE_CLOSE, MODE_MAIN, 0) < ADX)
 if(Closed_Bars!=Bars && sig==1)
  {
   RefreshRates();
   OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"DoppkeEA",Magic,0,Blue);
   string AN="ArrBuy "+TimeToStr(CurTime());
   ObjectCreate(AN,OBJ_ARROW,0,Time[1],Low[1]-6*Point,0,0,0,0);
   ObjectSet(AN, OBJPROP_ARROWCODE, 233);
   ObjectSet(AN, OBJPROP_COLOR , Blue);
  }
   
   
 
 sig = Highest(NULL,0,MODE_HIGH,Distance_Back,0);
 if(EAOrdersTotal < Max_Orders)
 if (iADX(NULL, 0, 8, PRICE_CLOSE, MODE_MAIN, 0) < ADX)
 if(Closed_Bars!=Bars && sig==1)
  {
   RefreshRates();
   OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"DoppkeEA",Magic,0,Magenta);
   AN="ArrSell "+TimeToStr(CurTime());
   ObjectCreate(AN,OBJ_ARROW,0,Time[1],High[1]+6*Point,0,0,0,0);
   ObjectSet(AN, OBJPROP_ARROWCODE, 234);
   ObjectSet(AN, OBJPROP_COLOR , Magenta);
  }

 Closed_Bars=Bars;
 
 return(0);
}