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

 
MakarFX #:

Can you tell me how to do it correctly

not to enter all elements that I want to add up, but just specify 5 elements

#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
int Label1Buffer[];
int Label2Buffer[];
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   int i=0,
       f=0,
       limit=9;
   ArrayResize(Label1Buffer,limit);
   ArrayResize(Label2Buffer,limit);
   for(i=limit-1; i>=0; i--)
     {
Label1Buffer[i]= 3;
 if(i<=4) f+=Label1Buffer[i];
Label2Buffer[i]= f;
      Print(Label2Buffer[i]);
     }
Print("   !  ",Label2Buffer[0]);
  }
//+------------------------------------------------------------------+
 
Galim_V #:

No, that's not it. So far I've done this

   for(i=limit;i>=0;i--)
     {
      Label1Buffer[i] = MathRand();
      tmp = 0.0; 
      for(int a=Input1; a>0; a--)
        {
         tmp +=  Label1Buffer[i+a];
        } 
      Label2Buffer[i] = tmp;
     }
 
iHigh(NULL,PERIOD_H1,i) and double H=iHigh(NULL,PERIOD_H1,i); are not the same thing?

For some reason they give different results after the while loop.

I wanted to optimize it so I would not constantly write a long line iHigh(NULL,PERIOD_H1,i) but would store it in a variable. Changed it to a variable in the loop, the result is different.
 
Ivan Butko iHigh(NULL,PERIOD_H1,i) and double H=iHigh(NULL,PERIOD_H1,i); are not the same thing?

For some reason they give different results after the while loop.

I wanted to optimize it so I would not constantly write a long line iHigh(NULL,PERIOD_H1,i) but would store it in a variable. Changed it to a variable in the loop, the result is different.

depends on what context to consider...

If your while loop plays with i, theniHigh(NULL,PERIOD_H1,i) and H will be different... Because H stores the data of the other i

 
Nikolay Ivanov iHigh(NULL,PERIOD_H1,i) and H will be different... Because H stores data of another i

Yes, you're right, it plays with i. I mean, thank you.

 
Is there any way to cut the history? When you download it, it's 20 years old, but you need it 2-3 years ago...
 
Ivan Butko #:
Is there any way to cut the history? When you download it, it's 20 years old, but you need it 2-3 years ago...

Use the "Shift" key to select the data you don't want and delete it

 
MakarFX #:

Use the "Shift" key to select the data you don't want and delete it.

Thank you

 
Good afternoon.
void CloseAll()
{
   for (int i=OrdersTotal()-1; i>=0; i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
         {
            if (OrderType() == OP_BUY)
            {
               if (!OrderClose(OrderTicket(),OrderLots(), Bid, Slippage))
               Print (" Не удалось закрыть ордер на покупку!");
            }
            if (OrderType() == OP_SELL) 
            {
               if (!OrderClose(OrderTicket(),OrderLots(), Ask, Slippage))
               Print (" Не удалось закрыть ордер на продажу!");
            }
         }
      }
   }
}
I use this code to close all orders. But I noticed that if there are a lot of them, not all of them are closed. What can I add to close all of them, even if not the first time. If possible, please give us an example.
 

Good afternoon, again)

Second question:
I want to close orders partially. But there is a problem, when partially closing orders, as I understand it, the order ticket changes, and from this the last becomes the first, and the main thing for me is to keep the order of opening. In order for the last ones to stay last. How we may track the previous order. Does the opening price change? If possible, with examples)
Thanks in advance

Reason: