Questions from Beginners MQL4 MT4 MetaTrader 4 - page 246

 
Valeriy Yastremskiy:

Thank you. I'll give it a try. I don't know if it'll work.)

 
I have open and closed orders.
1. When opening an order, I need to write its Ticket to an array, if the array is unoccupied (probably =0), so that I can report from it later in the overshoot.
2. After the order is closed (it may not be closed), report on the profit of the closed orders should be started. When a certain profit is reached, i.e.: profit + Take Profit >= profit of an open order (let us call it Order 123), opened earlier than all others, or with a maximal loss (I have not decided yet).
3. if the conditions are met: "sum of profit + taka profit >= profit of the open order(let's call order 123)", order 123 is closed and the array is zeroed out(probably becomes = 0 ).

1. When you place an EA, do you already have open and closed orders you want to take into account or not and the EA always starts without open orders and does not take into account orders already closed?

2. It is not clear at all. You have several orders. When an order is closed, the total profit is calculated and there is the profit data of the closed order. And there is the data about the profits of the orders which are not closed; you can calculate them. What is compared to what. For example, we have 3 orders. 1 is closed, 2 is being closed, 3 is open. We have the profiles Pr1, Pr2 and the estimated Pr3. We compare what we have with what. We understand that we don't take into account the commissions and swaps when the order is not closed.

3. Actually, if you zeroize the array with the tickets, what will happen next? The market orders will remain in the market. How would you close them?

 
Oksana_Timakova:
Question: how do I keep the value of High bar aand Low bar b in order toconnect them with an indicator line?
Do I need to create two additional arrays for that?
Yes. Buffer arrays.
 
Valeriy Yastremskiy:
Yes. Buffer arrays.
So it's the same as in ZigZag. And you have to apply some special function to not draw two of them?
 
Oksana_Timakova:
So, it turns out like in ZigZag. And you have to apply some special function to not draw two of them?
The line type is the same. I do not understand what would not draw. You declare 2 buffer arrays. You set the properties. This is type of line, thickness colour. And you assign the first price high and the second low by bar from the time series.
 
Valeriy Yastremskiy:

1. When you place an EA, do you already have open and closed orders that you want to take into account or not, and every time the EA starts without open orders and does not take into account previously closed orders?

2. It is not clear at all. You have several orders. When an order is closed, the total profit is calculated and there is the profit data of the closed order. And there is the data about the profits of the orders which are not closed; you can calculate them. What is compared to what. For example, we have 3 orders. 1 is closed, 2 is being closed, 3 is open. We have the profiles Pr1, Pr2 and estimated Pr3. We compare what with what. We understand that we don't take into account the commissions and swaps when the order is not closed.

3. Actually, if you zeroize the array with the tickets, what will happen next? The market orders will remain in the market. How do you close them?

Once again ))))

We have open orders, let's assume 5 orders that are all negative. The first one (123) with 0.5 lots has fallen into minus. We open a new order (456) with 0.1 lot, the ticket of this order is written to the array when it is opened. Then we proceed with another series of orders with the same lot; we gain some profits and lose some. But order 123 remains negative and open. Once the profit of all the closed orders after order 456 (it is also closed) is higher than the profit of order 123, we find order 123 as it is the first order that is still open, close it and zero out the array.

If we have several open orders, we open one more under certain conditions. Suppose if ordertotal>=5

ordersend (ticket 456)

if the order is successfully opened

if the array is not occupied

ticket 456 is written to the array

Order 456 closed on profit (no matter what the profit or loss is), after that other orders were opened and closed, but the array stores ticket 456.


CalCloseProfi () - this function checks the profit of the closed orders

goes through the closed orders by magic, buy, sell, starting from the order with ticket 456 (taken from the array) and upwards, and counts their profit


FirstOrder() - this function searches for the first open order (it should find 123)

If theCalCloseProfi profile> FirstOrder, then close order 123 and zeroize the array, so that it would be able to write there again when the conditions are met.


I do not know how else to explain it)

The conditions under which it will be executed this function, I can write, but I'm not faced with arrays.
I need an example, how to get information in the array, namely OrederTicket when open, and how to get it afterwards.
It is desirable to use a double array and write the magician in one part of it, so that when working on one account at different settings are not mixed (or maybe not, I'm not good at arrays).

Thanks in advance

 
makssub:

Once again ))))

We have open orders, let's assume 5, all negative. The very first one (123) with 0.5 lots was negative. We open a new order (456) with 0.1 lot, the ticket of this order is written to the array when it is opened. Then we proceed with another series of orders with the same lot; we gain some profits and lose some. But order 123 remains negative and open. Once the profit of all the closed orders after order 456 (it is also closed) is higher than the profit of order 123, we find order 123 as it is the first order that is still open, close it and zero out the array.

If we have several open orders, we open one more under certain conditions. Suppose if ordertotal>=5

ordersend (ticket 456)

if the order is successfully opened

if the array is not occupied

ticket 456 is written to the array

Order 456 closed on profit (no matter what the profit or loss is), after that other orders were opened and closed, but the array stores ticket 456.


CalCloseProfi () - this function checks the profit of the closed orders

goes through the closed orders by magic, buy, sell, starting from the order with ticket 456 (taken from the array) and upwards, and counts their profit


FirstOrder() - this function searches for the first open order (it should find 123)

If theCalCloseProfi profile> FirstOrder, then close order 123 and zeroize the array, so that it would be able to write there again when the conditions are met.


I do not know how else to explain it)

The conditions under which it will be executed this function, I can write, but I'm not faced with arrays.
I need an example, how to put the information in the array, namely OrederTicket when opening, and how to get it afterwards.
It is desirable to use a double array and write the magician in one part of it, so that when working on one account at different settings are not mixed (or maybe not, I'm not good at arrays).

Thanks in advance

Write the conditions for the functions.
 

Good afternoon. Can you tell me why there is an error: array out of range in '.......' (152,41)


ticket = OrderSend (Symbol(), OP_SELL, lastlot, Bid, Slippage, 0, tpl, Magic, 0, Red);
if (ticket <1)
{
Print("Sell open error");
}
if (ticket >1 && SaveTick[1] <= 0 && SaveTick[0] == Magic)
{
FindTicket();
Print(" Ticket order: ", FindTicket(), " Order Array: ", SaveTick[1], " Array Magic: ", SaveTick[0]);
}

int FindTicket()
{
int oldticket;
int tick=0;
ticket=0;
ArrayResize( SaveTick, 2 );
for(int cnt = OrdersTotal ()-1; cnt>=0; cnt--)
{
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
oldticket = OrderTicket();
if (oldticket > ticket)
{
ticket = oldticket;
tick = OrderTicket();
SaveTick[1] = tick;
SaveTick[0] = Magic;
}
}
}
}
return(tick);
}

 
makssub #:

Good afternoon. Can you tell me why there is an error: array out of range in '.......' (152,41)


ticket = OrderSend (Symbol(), OP_SELL, lastlot, Bid, Slippage, 0, tpl, Magic, 0, Red);
            if (ticket <1)
            {
               Print("Ошибка открытия на продажу");
            }
               if (ticket >1 && SaveTick[1] <= 0 && SaveTick[0] == Magic)
            {
               FindTicket();
               Print(" Тикет ордера: ", FindTicket(), " Массив ордера: ", SaveTick[1], " Магик массива: ", SaveTick[0]);
    }

int FindTicket()
   {
   int oldticket;
   int tick=0;
   ticket=0;
   ArrayResize( SaveTick, 2 );
   for(int cnt = OrdersTotal ()-1; cnt>=0; cnt--)
      {
      if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
         {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
            {
            oldticket = OrderTicket();
            if (oldticket > ticket)
               {
               ticket = oldticket;
               tick = OrderTicket();
               SaveTick[1] = tick;
               SaveTick[0] = Magic;
               }
            }
         }
      }
   return(tick);
  }              

Insert the code correctly, alt S or by icon, hint code.

Why do you needSaveTick array?

You only use 2 elements of the array. Replace them with global or static variables if you declare them in a function.

It's not sensible to use an array for 2 variables.

And you seem to call arrays before theFindTick() function is called, where the size of the SaveTick array is set. And there is an overrun of the array.

 
Has it stopped working 🤖?
Reason: