Please Repair My own EA

 

i am on my way to learn mql4...but it is so difficult......so itry to combine from 1 EA to another EA to create my EA...

i want my EA work at specific time...like example at 12.00 it will buy or sell and only doing 1 trade perday....and also added SMA that is 175 SMA, the rule when SMA upp than the price, it will order sell at the specific time and only once......and on the contrary


here is my code........please help me...

extern double Lots=0.1;
extern int StopLoss=100;
extern int TakeProfit=150;
extern string txComment="Order";
extern int MagicNumber=12345;
extern int Slippage=5;
extern int EntryHour = 0;
extern int EntryMinute = 1;
bool Signal = False;
bool bTrade = True; 
extern int GMToffset=0;
double  high_price, low_price , high_price2, low_price2, dLots;
int   iTicket, iTotalOrders,trend,Status,signal, BarCount, TradePerBar, var2;


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----if(CheckTodaysOrders() >= 1){
return(0); // abort

      if (OrdersTotal()==0) // if(Long_Entry==true && Hour()==Hour_For_Long_Entry && Minute()>=Minute_For_Long_Entry && IsTradeAllowed()==true)
       bool bTrade = True;//one day one trade
        
        
       {
      if(TimeHour(TimeCurrent()) == EntryHour && EntryMinute == TimeMinute(TimeCurrent())) Signal = True;
         if (iClose(Symbol(),0,1) > iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE,1) )
         {
            OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,txComment,MagicNumber);
         }
         else if (iClose(Symbol(),0,1) < iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE,1) )
         {
            OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,txComment,MagicNumber);
             //one day one trade
         

         }
         
      } 
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

You probably need to get rid of that return(0) immediately after int start(){

 

yes thank you sir..it can...but it make 10 trades consecutive.......how to make it only 1 trade perday...

i think need to add this logic...but where to put.....


bool isNewDay()

{
static int dow = -1;
if (dow != Day())
{
dow = Day();
return(true);
}
return(false);
}
 
This can be improved, but it should give you the idea...


bool AlreadyTookATradeToday = false;

int start(){
   for(i = OrdersTotal()-1; i >= 0; i--){
      OrderSelect(i, SEL_BY_POSITION, MODE_TRADES){
      if(OrderSymbol() == OrderSymbol()){
         if(TimeDayOyYear(OrderOpenTime()) == TimeDayOfYear(TimeCurrent()){
            AlreadyTookATradeToday = true;
         }
      }
   }

   ...
   ... your code above
   if(AlreadyTookATradeToday  == false) OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,txComment,MagicNumber);
   ...
   if(AlreadyTookATradeToday  == false) OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,txComment,MagicNumber);
   ...
   ...
   AlreadyTookATradeToday = false; // reset the flag at the end
   return(0)
}
 
thank you very much sir.....i will try.....
Reason: