Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 424

 
novichok2018:

Yes, thanks, I read the page. Only my knowledge in MKL4 was enough only to notice that in my loop the positions go from zero to the last, while in the example vice versa, from last to zero.I still don't know where to insertthe break. When I changed the loop to reverse, positions stop closing at all.

When closing positions, the loop must be reversed to avoid skipping positions. The break operator is not needed in this loop - it is the loop break and exit from its body. What you need is continue - the transition to the next loop iteration.

And only you know why it is not closing and what you have done for it.

 
Artyom Trishkin:

When closing positions, the loop must be reversed so that no positions are skipped. You do not need break operator in this loop - it is an interruption and exit from the loop's body. What you need is continue - the transition to the next loop iteration.

Only you know why it cannot close, and what you did to fix it.


I followed the instructions exactly. Here is the corrected code:

void ClosePoz()
  { int total=OrdersTotal();
  if(total>0)
   {
      for(int i=OrdersTotal()-1;i>=0;i--)
      {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         {double WPR0 = iWPR(NULL,PERIOD_M5,bars,0);
         if(OrderType()==OP_BUY && MathAbs(WPR0)>80)
           OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),int(MarketInfo(OrderSymbol(),MODE_DIGITS))),slippage,clrNONE);                  
         }
         continue;
      }
    } 
  } 
  

Now it closes both positions but it won't close one but waits for the second. It's nuts. I thought maybe I inserted theClosePoz() function in a wrong place. The result is zero. I am crying out for help. It cannot be that no one is able to solve the problem.

 

how to cash out the original account ($100)?

 
novichok2018:

Did exactly as instructed. Here is the corrected code:

Now it closes both positions, but it doesn't close one, it waits for the other. This is nuts. I thought maybe I inserted theClosePoz() function in a wrong place. The result is zero. I am crying out for help. It cannot be that no one is able to solve the problem.

I do not know. I drew it on my knee. Of course I can't check it - your conditions are not enough, so it's up to you.

//+------------------------------------------------------------------+
void ClosePoz(const string symbol_name,const int magic_number,const double wpr_buy,const double wpr_sell)
  { 
   int total=OrdersTotal();
   for(int i=total-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS))
        {
         ENUM_ORDER_TYPE type=OrderType();
         if(type>ORDER_TYPE_SELL)               continue;
         if(OrderMagicNumber()!=magic_number)   continue;
         if(OrderSymbol()!=symbol_name)         continue;
         int digits=(int)SymbolInfoInteger(OrderSymbol(),SYMBOL_DIGITS);
         if(type==ORDER_TYPE_BUY)
           {
            double close_price=SymbolInfoDouble(OrderSymbol(),SYMBOL_BID);
            if(iWPR(NULL,PERIOD_M5,bars,0))>wpr_buy)
              {
               ResetLastError();
               if(!OrderClose(OrderTicket(),OrderLots(),close_price,slippage,clrNONE);
                  Print(__FUNCTION__" > Позиция Buy #",OrderTicket()," не закрыта. Ошибка: ",GetLastError());
              }
           }                
         else
           {
            double close_price=SymbolInfoDouble(OrderSymbol(),SYMBOL_ASK);
            if(iWPR(NULL,PERIOD_M5,bars,0))<wpr_sell)
              {
               ResetLastError();
               if(!OrderClose(OrderTicket(),OrderLots(),close_price,slippage,clrNONE);
                  Print(__FUNCTION__" > Позиция Sell #",OrderTicket()," не закрыта. Ошибка: ",GetLastError());
              }
           }                
        }
     }
  } 
//+------------------------------------------------------------------+
And WPR inside of function to check - it is somehow not normal. WPR should be one of the conditions of call of closing function
 
It is not possible to modify the number of lots on a pending order.
 
igrok333:
I understand that you cannot modify the number of lots in a pending order.

Only open an additional one, with the volume you need.

 
Alekseu Fedotov:

Only open an additional one with the volume you want

It may be easier to delete an existing one and set up a new one. After all, the required volume does not have to be larger than the one already placed. And it is easier to follow one order.

 

Good day I have a question, I will explain how I understand it

Is there a written algorithm for Expert Advisors that buy candles at the very bottom and sell candles at the very top ?

how do i adapt it into an EA ?
 
iisvlg: Is there a written algorithm for EAs that puts a buy candle at the very bottom and a sell candle at the very top and how to adapt it into an EA ?

That would be great !!!

 
iisvlg:

Good day I have a question, I will explain how I understand it

Is there a written algorithm for Expert Advisors which buy candles at the very bottom and sell candles at the very top?

And how do you adapt it into an EA ?

Put BUY LIMIT on Low, and SELL LIMIT on High.

About the algorithms, dig the base