Download MetaTrader 5

ADD LOT Problem

To add comments, please log in or register
Stanislav Ivanov
1453
Stanislav Ivanov  

Hi Guys,

i`m struggling upon something -  its an add lot function. Can you help me make it start only one additional order per main order? Mine starts like a million additional orders. I`d really appreciate the help.

Best Regards

whroeder1
18257
whroeder1  
  1. Do you really expect an answer? We can't see your broken code. There are no mind readers here and our crystal balls are cracked.

  2. Don't looking at a signal. Act on a change of signal.
              MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum
Stanislav Ivanov
1453
Stanislav Ivanov  
void addlot_execute(double lot_step,double lot_size,double pnt)
{
bool already_added;

//===================================================
for (int i=OrdersTotal()-1; i>=0; i--)
   {
   if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   continue;
   if( OrderMagicNumber()== magic && OrderSymbol()==Symbol()) 
   {
//-------------------------------------
if(OrderType()==OP_BUY && Bid>OrderOpenPrice()+ lot_step *pnt && already_added==false) // BUY
{
int tkt = OrderSend(Symbol(),OP_BUY,lot_size,Ask,5,OrderStopLoss(),OrderTakeProfit(),NULL,magic+1,0,clrGreen);
if(tkt > 0) Print("Additional Order BUY Opened !!! ");
else Print("Error Opening Additional order BUY !!!");
}
//-----------------------------------------
else if(OrderType()==OP_SELL && Bid<OrderOpenPrice()- lot_step *pnt && already_added==false) // SELL
{
 int tkt = OrderSend(Symbol(),OP_SELL,lot_size,Bid,5,OrderStopLoss(),OrderTakeProfit(),NULL,magic+1,0,clrRed);
if(tkt > 0) Print("Additional Order SELL Opened !!! ");
else Print("Error Opening Additional order SELL !!!");
}
   }     
 }
 return;  
}// END 
nicholi shen
1751
nicholi shen  
Stanislav Ivanov:

whroeder's gonna say you need to program your EA to recover, and he's right. You need to count how many orders in the pool. 

bool canTrade(int order_type, int max_number_of_orders)
{
    int count=0;
    for (int i = OrdersTotal() - 1; i >= 0; i--)
        if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == _Symbol && OrderMagicNumber() == MAGIC && OrderType()==order_type)
           count++;
    return count < max_number_of_orders;
}
Stanislav Ivanov
1453
Stanislav Ivanov  
Mark Watkins:

whroeder's gonna say you need to program your EA to recover, and he's right. You need to count how many orders in the pool. 

thanks

To add comments, please log in or register