HI everyone EA coding issue please help!

 

I would like to ask for some help.

 am trying to make EA that will open pending buystop and sell stop orders in particular time let say at 07:30 AM above or below the candle by 3 pips, if one order fulfill it will close the other pending order and 

add takeprofit for the open order by 20 pips.

that all.

i try this one but i have some error, Please check and help.


//+------------------------------------------------------------------+

//|                                          EA CANDLETIME 10.30.mq4 |

//|                        Copyright 2019, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2019, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

extern double lot = 1.0;

extern int takeprofit = 10;

extern int stoploss = 10;

extern string s = "candle number at whitch you want to place orders 0, 1, 2";

extern int OpenTime = 4; //candle timing which we will place the order 

extern string r = "candle number at whitch you want to close market orders 0, 1, 2";

extern int closetime = 20; // close trading candle timing hours

int magic = 3247;

extern double g = 2; // pips number up or down the cadle price

bool check=true;

// Epert initialization function

int init()

  {

  

  return(0);

  }

  

  int deinit()

    {

    

    return(0);

    

    }



// Epert start function

int start()



{



  bool t = checktime();

  

  if(OrdersTotal()==0)

  {

    if(t==true&&check==true)

    {  

       openbuystop();

       opensellstop();

       check=false;

     

 

    else if(t==false)


    {

      closebuy();

      closesell();

      deletepending();

      check=true;

      }

      

    }

    else if(OrdersTotal()==1)

    {

      deletepending();

    }

    

    return(0);

    }









// function for opening buystop and sellstop

void openbuystop()

{

    if(orderSend(symbol(),OP_BUYSTOP,lot,Ask+g*Point,3,Bid+g*Point-stoploss*Point,Ask+g*Point+takeprofit*Point,NULL,magic,0,Blue)==true)

                     Alert("Order sent!!");

  

  else

  fun_error(GetLastError());

}



voidopensellstop()

{

    if(orderSend(symbol(),OP_SELLSTOP,lot,Bid-g*Point,3,Ask-g*Point+stoploss*Point,Bid-g*Point-takeprofit*Point,NULL,magic,0,Red)==true)

    {

      Alert("order sent!!"); 

    }

    else

    fun_error(GetLastError());

    }                      

//////////////////////



void closebuy()

{

     for(int j=1; j<=OrderTotal(); j++)

     {

          OrderSelect(j-1, SELECT_BY_POS, MODE_TRADES);

          if(OrderType()==OP_BUY&&OrderMagicNumber()==magic)

             {

             

                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);

                 PlaySound("alert2.wav");

                 

              }

              

      }

      

      

}





void closesell()

{

   for(int j-1; j<=OrdersTotal(); j++)

   {

         OrderSelect(j-1, SELECT_BY_POS,MODE_TRADES);

         if(OrderType()==OP_SELL&&OrderMagicNumber()==magic)

            {

                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);

                 PlaySound("news.wav");

            }

      }

 }

 

 

 int fun_error(int Error)               //Function of processing errors

  {

    switch(Error)

     {                                  // not crucial errors

       case 4: Alert ("Trade server is busy. Trying once Again...");

               Sleep(3000);                     //simple solution

               return(1);                       // Exit function

       case 135: Alert ("Price changd.e Trying once again..");

               RefreshRates();                 //Refresh rates

               return(1);                      //Exit Function

       case 136: Alert("No Prices. Waiting for a new tick..");

               while(RefreshRates()==false)        //Till a new tick

                 Sleep(1);       // Pause the loop

               return(1);      //Exit the function

       case 137: Alert("Broker is busy. Trying once again...");

               Sleep(3000);

               return(1);

               

               

                

                

          }

  }

  

  // checking time , for placing any orders

  

bool checktime()

{

  int i =0;

  int hourtime = TimeHour(Time[i]);

  if(hourtime==opentime)

    {

       return (true);

    }

    else if(hourtime==closetime)

    {

       return (false);

    }

    else

       return (EMPTY_VALUE);

    }

    

bool deletepending()

{

  for(int w=0; w<OrdersTotal(); w++)

  {

     OrderSelect(w, SELECT_BY_POS, MODE_TRADES);

     if(OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP)

     {

        OrderDelete(OrderTicket());

     }

   }

}


 

You may find that many people can't be bothered to look at code with so much white space.

Why so many empty lines?

Reason: