Need a correction hand with a loop for consecutive orders

 

I need to opened a market buy order above the 1 pip above the last order. Just a one trade and continue same if price goes up. I'm using the following code and problem with that is, it is opening multiple orders at a one price whereas I needed open  a one buy trade for 1 pip up. Please help me with the code.

//Sending Next Buy Orders

   int lastOpenTime = 0; double LastBuyOrderOpenPrice = 0;
   
   for(int i = (OpenBuyOrders-1); i >= 0; i --)
   {
   OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      
   int curOpenTime = OrderOpenTime();
      
   if(curOpenTime > lastOpenTime)
   {
   lastOpenTime = curOpenTime;
   LastBuyOrderOpenPrice = OrderOpenPrice();
   }
   }
   

   
   if ( Current_Ask >= LastBuyOrderOpenPrice + 1*Point*10)
   {
   
   for(int i=0;i<OrdersTotal(); i++ )
   {
   if(OrderSelect(i, SELECT_BY_POS)==true)
   {
   if(OrderType()==OP_BUY)
   {
   if(OrderOpenPrice() != LastBuyOrderOpenPrice + Pip*Point*10)
   {
   OrderSend(Symbol(), OP_BUY, Lots, Ask, 10*10, 0,0);
   }
   }
   }
   }
   
   }
 
  1. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. if(OrderOpenPrice() != LastBuyOrderOpenPrice + Pip*Point*10)
    Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

  3.    OrderSend(Symbol(), OP_BUY, Lots, Ask, 10*10, 0,0);
    Check your return codes.

    Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

    You would know that if you had used strict. Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.

 
William Roeder:
  1. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

  3. Check your return codes.

    Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

    You would know that if you had used strict. Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.

  1. I didn't notice it until you point the fact that I've posted in the wrong path.
  • For the other points I'll go through and will try to understand and update my code. If any development or if I needed further clarification I'll will post here. Thank you very much for your valuable time.
 
In future please post in the correct section
I will move this topic to the MQL4 and Metatrader 4 section.
Reason: