Hi anyone help me please

 

I copied some ea from somewhere long time ago. It is just Pending Order EA. I want it to help me open order.

EA is a Buy STop EA No indicator at all. What I want is only one more function to add in it is when the current price fall lower than xx pip far from last order just send another buystop order. when the lastest order closed just sent another buy stop order? That is it...

Help me plzz

-----------------------------

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

//| Buystop EA v1.mq4 |

//| |

//| |

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


int order_total;

int cs = 0;

int csl = 0;

extern int TP = 10;

extern int pip_pendig = 10;

extern double Lots = 0.1;

double op_sl;

int ticket_sl;


int init(){

if(MarketInfo("EURUSD",MODE_DIGITS)==5){

TP = TP*10;

pip_pendig = pip_pendig*10;

}

return(0);

}


int start()

{

order_total = OrdersTotal();

cs = false;

csl = false;


for(int i = order_total; i >= 0; i--){

if(OrderSelect(i,SELECT_BY_POS) == true && OrderSymbol() == Symbol()){

if(OrderType() == OP_BUY){

cs = true;

}

if(OrderType() == OP_BUYSTOP){

op_sl = NormalizeDouble(OrderOpenPrice(), Digits);

ticket_sl = OrderTicket();

csl = true;

}

}

}

Open_orders();

Modify_orders();


return(0);

}

void Open_orders(){

if(cs==false){

OrderSend(Symbol(),OP_BUY,Lots,Bid,2,0,Bid-TP*Point,"",0,0,CLR_NONE);

}

if(csl==false){

OrderSend(Symbol(),OP_BUYSTOP,Lots,Bid+pip_pendig*Point,2,0,Bid,"",0,0,CLR_NONE);

}

}


void Modify_orders(){

if(csl==true){

if(NormalizeDouble(op_sl-Bid,Digits)>=(pip_pendig+TP)*Point){

OrderModify(ticket_sl,Bid+pip_pendig*Point,0,Bid,0,DeepSkyBlue);

}

}

}

 
lancelot:

I copied some ea from somewhere long time ago. It is just Pending Order EA. I want it to help me open order.

EA is a Buy STop EA No indicator at all. What I want is only one more function to add in it is when the current price fall lower than xx pip far from last order just send another buystop order. when the lastest order closed just sent another buy stop order? That is it...

Help me plzz

-----------------------------


Why not modifie the current pending order when that happens....

This way you can get a lot of (pending) trades

Use SRC or (Ctrl+Alt+M) to show code of program

//+------------------------------------------------------------------+
//| Buystop EA v1.mq4                                                |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+


int order_total;
int cs = 0;
int csl = 0;

extern int TP = 10;
extern int pip_pendig = 10;
extern double Lots = 0.1;

double op_sl;
int ticket_sl;




int init(){

if(MarketInfo("EURUSD",MODE_DIGITS)==5){
TP = TP*10;
pip_pendig = pip_pendig*10;
}
return(0);
}




int start()
{
  order_total = OrdersTotal();
  cs = false;
  csl = false;

  for(int i = order_total; i >= 0; i--){
    if(OrderSelect(i,SELECT_BY_POS) == true && OrderSymbol() == Symbol())
       {
        if(OrderType() == OP_BUY)
          {
           cs = true;
          }
        if(OrderType() == OP_BUYSTOP)
          {
           op_sl = NormalizeDouble(OrderOpenPrice(), Digits);
           ticket_sl = OrderTicket();
           csl = true;
          }
       }
    }

  Open_orders();

  Modify_orders();

  return(0);
}

void Open_orders(){
   if(cs==false)
     {
      OrderSend(Symbol(),OP_BUY,Lots,Bid,2,0,Bid-TP*Point,"",0,0,CLR_NONE);
     }
   if(csl==false)
     {
      OrderSend(Symbol(),OP_BUYSTOP,Lots,Bid+pip_pendig*Point,2,0,Bid,"",0,0,CLR_NONE);
     }
  }




void Modify_orders(){

if(csl==true){

if(NormalizeDouble(op_sl-Bid,Digits)>=(pip_pendig+TP)*Point){

OrderModify(ticket_sl,Bid+pip_pendig*Point,0,Bid,0,DeepSkyBlue);

}

}

}

 
(-/\-) thank alot..
 
int init(){

if(MarketInfo("EURUSD",MODE_DIGITS)==5){
TP = TP*10;
pip_pendig = pip_pendig*10;

Each time you change timeframes, pairs, etc, you go through a deinit/init cycle. so TP becomes 10x 100x 1000x... Don't modify externals, treat them as constants and modify where used. You must also adjust slippage.

//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
     if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//---- These are adjusted for 5 digit brokers.
    /* On ECN brokers you must open first and THEN set stops
    int ticket = OrderSend(..., 0,0,...)
    if (ticket < 0)
       Alert("OrderSend failed: ", GetLastError());
    else if (!OrderSelect(ticket, SELECT_BY_TICKET))
       Alert("OrderSelect failed: ", GetLastError());
    else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
       Alert("OrderModify failed: ", GetLastError());
     */
 
WHRoeder:

Each time you change timeframes, pairs, etc, you go through a deinit/init cycle. so TP becomes 10x 100x 1000x... Don't modify externals, treat them as constants and modify where used. You must also adjust slippage.


Ohh great thank you for you knowledge that helps me lots
Reason: