simple question - page 2

 
Ais:

Please check "Dist" value

check? How? I copied the code (the part with the distance variable) from the book of MQL4:

int start()                                     // Special function 'start'
  {
   string Symb=Symbol();                        // Symbol
   double Dist=1000000.0;                       // Presetting
   int Real_Order=-1;                           // No market orders yet
   double Win_Price=WindowPriceOnDropped();     // The script is dropped here
//-------------------------------------------------------------------------------- 2 --
   for(int i=1; i<=OrdersTotal(); i++)          // Order searching cycle
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {                                       // Order analysis:
         //----------------------------------------------------------------------- 3 --
         if (OrderSymbol()!= Symb) continue;    // Symbol is not ours
         int Tip=OrderType();                   // Order type
         if (Tip>1) continue;                   // Pending order  
         //----------------------------------------------------------------------- 4 --
         double Price=OrderOpenPrice();         // Order price
         if (NormalizeDouble(MathAbs(Price-Win_Price),Digits)< //Selection
            NormalizeDouble(Dist,Digits))       // of the closest order       
           {
            Dist=MathAbs(Price-Win_Price);      // New value
            Real_Order=Tip;                     // Market order available
            int Ticket=OrderTicket();           // Order ticket
            double Lot=OrderLots();             // Amount of lots
           }
         //----------------------------------------------------------------------- 5 --
        }                                       //End of order analysis
     }                                          //End of order searching
//-------------------------------------------------------------------------------- 6 --
   while(true)                                  // Order closing cycle
     {
      if (Real_Order==-1)                       // If no market orders available
        {
         Alert("For ",Symb," no market orders available");
         break;                                 // Exit closing cycle        
        }
      //-------------------------------------------------------------------------- 7 --
      switch(Real_Order)                        // By order type
        {
         case 0: double Price_Cls=Bid;          // Order Buy
            string Text="Buy ";                 // Text for Buy
            break;                              // Из switch
         case 1: Price_Cls=Ask;                 // Order Sell
            Text="Sell ";                       // Text for Sell
        }
      Alert("Attempt to close ",Text," ",Ticket,". Awaiting response..");
      bool Ans=OrderClose(Ticket,Lot,Price_Cls,2);// Order closing
see also: https://book.mql4.com/trading/orderclose
 
Ais:

1. Make sure that initial value of "Dist" is correct

2. Insert alert to check value of "Dist" in the beginning of cycle: "Alert ( " Dist = ", Dist ) ; "

is there any way to select the right order without using the variable "dist"?

 
Ais:

Answer 1

Signs ">" and "<" in the samples are in different directions for the same expression

See line 22 of closeorder.mq4 and line 6 of previous sample

I think in the second sample it must be a mistake...what do you think?

 
Ais:

Answer 2

Depends on meaning of "the right order"

I need to select (and close) the order OP_BUY that has the lower openprice and this selection must start when there are 2 orders OP_BUY...the same thing for OP_SELL...is this so difficult to implement? I'm so confused...

 
Ais:

ordinary work

so what am I doing wrong? How would you select the OP_BUY with the lower openprice? I tried even without "Dist"...


if (CheckFirstOP(OP_BUY) > 1) {      
      for(int i = OrdersTotal() - 1; i >= 0; i--) {
          OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
          if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber || OrderType() != OP_BUY) continue;     
          double Price = OrderOpenPrice();
          if (Price < Price), Digits) {                                            
             int Ticket = OrderTicket();           
             double Lot = OrderLots();                          
             OrderClose(Ticket, Lot, OrderClosePrice(), 3); 
         }    
      }   
   }
without any results
 

What's the intention with the line " if (Price < Price), Digits) " ??

Looks nuts to me.


CB

 
cloudbreaker:

What's the intention with the line " if (Price < Price), Digits) " ??

Looks nuts to me.

not only thats.

how could this compile errorfree, with a missing left bracket.

i am tired of this code-grabbing-null-insight-full-idiots-and-full-wasicus-and-not-want-to-pay-a-cent-asking-for-help-guys

 
Ais:

all humans make mistakes

if (a_human_made_a_mistake==true)

{human_learn_next_lesson();}

else

{reincarnate_as_plant=true;}

 
meikel:

{human_learn_next_lesson();}

If only we had MT5. Then we could do human->learnNextLesson() instead.

 
jjc:

If only we had MT5. Then we could do human->learnNextLesson() instead.

i have never been familiar with OOP.

i hate that. too much hassle about nothing.

in such cases, i refuse to learn... ;-)

this->repeat->this->repeat->this->repeat->this->repeat->this->repeat->this->repeat->this->repeat->this;

Reason: