need help in ea code

 

need help in ea code

ea has to open one order per candle and close the position after candle is closed

so need help to close the position as soon as candle closed


extern double lotsize = 1;
datetime order_time = 0;

int init()
  {   return(0);  }

int deinit()
  {   return(0);}

int start()
{

   double current_openprice = iOpen(Symbol(), NULL, 0);
   
   double previous_highprice_3 = iHigh(Symbol(), NULL, 3);
   
   double previous_highprice_4 = iHigh(Symbol(), NULL, 4);
   
   double previous_lowprice_3 = iLow(Symbol(),NULL , 3);
   
   double previous_lowprice_4 = iLow(Symbol(),NULL , 4);
  
   datetime current_time = iTime(Symbol(),NULL , 0);
  

   if( Bid > previous_highprice_3  && current_time != order_time)
   
     {
       int ticket = OrderSend(Symbol(), OP_SELL, lotsize, Bid, 3, previous_highprice_4,previous_lowprice_4,"sell", 555, 0, Red);
      
       order_time = iTime(Symbol(),NULL , 0);
              
     }

   if( Bid  < previous_lowprice_3  && current_time != order_time)   
   
     {
       ticket = OrderSend(Symbol(), OP_BUY, lotsize, Ask, 3, previous_lowprice_4,previous_highprice_4 ,"BUY", 55555, 0, Blue);
       
       order_time = iTime(Symbol(),NULL, 0);
       
     }

   return(0);
}
 
  1. BABABABA10:
    so need help to close the position as soon as candle closed
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    &&  Time[0]             >  OrderOpenTime()      // New Candle
    ){
        if (!OrderClose( OrderTicket(), OrderLots, OrderClosePrice(), 
                        Slippage.Pips*pips2points)
            Alert("OrderClose(ticket=", OrderTicket(), ", ...) failed: ", 
                    GetLastError());
    }

  2. Why use the more complicated function calls
    double current_openprice = iOpen(Symbol(), NULL, 0);    // Open[0]
    double previous_highprice_3 = iHigh(Symbol(), NULL, 3); // High[3]
    datetime current_time = iTime(Symbol(),NULL , 0);       // Time[0]
    

 
WHRoeder:
  1. BABABABA10:
    so need help to close the position as soon as candle closed

  2. Why use the more complicated function calls

to WHRoeder


he i am new to mql4 prg. so don't have more knowldge about complicated function calls


can u tell me pleas where i can post that code into ea int start() ya define a new funcation can u pleas help me to put that code into ea please

so ea will work fine .. please help

 
You used:
double current_openprice = iOpen(Symbol(), NULL, 0);
The simpler version:
double current_openprice = Open[0];
likewise the others mentioned.
 
WHRoeder:
You used: The simpler version: likewise the others mentioned.

i got that u point but i am asking

about this code u given me where i can post that code in to ea so ea will work fine i am confuse about it so asking u . pleas help

for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
    OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
&&  OrderMagicNumber()  == magic.number             // my magic number
&&  OrderSymbol()       == Symbol()                 // and my pair.
&&  Time[0]             >  OrderOpenTime()      // New Candle
){
    if (!OrderClose( OrderTicket(), OrderLots, OrderClosePrice(), 
                    Slippage.Pips*pips2points)
        Alert("OrderClose(ticket=", OrderTicket(), ", ...) failed: ", 
                GetLastError());
}
 
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
}
int start(){
    int count=0;
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol() ){              // and my pair.
        if (Time[0]          >  OrderOpenTime()){       // New Candle since open
            if (OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(),
                            Slippage.Pips*pips2points)){// Successful closing.
                RefreshRates();                         // About to open new.
                continue;                               // No count, it's closed
            }
            Alert("OrderClose(ticket=", OrderTicket(), ", ...) failed: ",
                    GetLastError());                    // Complain and count.
        }
        count++;    // Order is still open.
    }   // For
    if (count != 0) return(0); // Order(s) open, wait for a new candle.
   
    // No open orders, open a new one.
    double current_openprice = Open[0];             // iOpen(Symbol(), NULL, 0);
    ...
 
WHRoeder:

thank you fore reply :)
Reason: