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

 
Vitalie Postolache:


If you compare it to the balance, that's how it is:

Thank you.

 
trader781:

OK, then as I understand it, we get three different custom functions with the return of the right one (if we look for three different parameters)

ArraySort

then

ArrayBsearch by the right number

and then how to deal with it?

Exactly the transition from an array to a structure element

You don't understand.

You need to make a single function that will populate and sort the array declared globally. The array will need to be passed to the function by reference.

And you need additional functions that will take out the data you need from this array.

 
Artyom Trishkin:

You don't understand.

You need to make a single function that fills and sorts the array declared globally. The array will need to be passed to the function by reference.

And you need additional functions that will take the data you need from this array.

ok, can you demonstrate how to take something out of an array of structures? let's say it's full and sorted

how to transfer by reference and write

 

Please advise how the condition should look like. If a stop loss is triggered, then the lot is multiplied by 2, and if the next order triggers a take profit, the lot would return to the original lot, which was before the stop loss.

I understand it like this, but I don't know how to go on...

for (int i=OrdersHistoryTotal()-1; i>=0; i--)
   {
   if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)
      {
      if (OrderMagicNumber()==magic)
         {
         if (OrderStopLoss()==OrderClosePrice())
            {
            lot=lot*4;
            }
         }
      }

   } 

 

another question, what did I write wrong in the block on deleting orders? it does not always delete orders, in the log it says

OrderDelete error 4108
market order #1 cannot be deleted

if (Hour()==23 && Minute()==59)            
         {
         for(int n=OrdersTotal()-1;n>=0;n--)
            {
            if(OrderSelect(n,SELECT_BY_POS))
               {
               if(OrderMagicNumber()==magic)
                  {
                  bool del=OrderDelete(OrderTicket());
                  if (del==true)
                     {
                     otl_b=0; otl_s=0; //обнуляем переменные отложек
                     }
                  
                  }  
               }  
            }
         }
 
wishmast:

Another question, what did I write wrong in the block to delete orders? It doesn't always delete orders, in the log it says

OrderDelete error 4108
market order #1 cannot be deleted

if (Hour()==23 && Minute()==59)            
         {
         for(int n=OrdersTotal()-1;n>=0;n--)
            {
            if(OrderSelect(n,SELECT_BY_POS))
               {
               if(OrderMagicNumber()==magic)
                  {
                  bool del=OrderDelete(OrderTicket());
                  if (del==true)
                     {
                     otl_b=0; otl_s=0; //обнуляем переменные отложек
                     }
                  
                  }  
               }  
            }
         }


You are trying to delete a market order, they are not deleted, they are closed using the OrderClose() function. For the loop to delete or close correctly, we have to distinguish the order by its type.

if(OrderType()<=OP_SELL) - for market orders, if(OrderType()>OP_SELL) - for pending orders.

 

There's a thing calledCHARTEVENT_MOUSE_MOVE

Question: does this work on mobile devices where there is no mouse?

 
wishmast:

Please advise how the condition should look like. If a stop loss is triggered, then the lot is multiplied by 2, and if the next order triggers a take profit, the lot would return to the original lot, which was before the stop loss.

I understand it like this, but I don't know how to go on...

for (int i=OrdersHistoryTotal()-1; i>=0; i--)
   {
   if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)
      {
      if (OrderMagicNumber()==magic)
         {
         if (OrderStopLoss()==OrderClosePrice())
            {
            lot=lot*4;
            }
         }
      }

   } 

If you've done it quickly, the last losing order will show up, what to do with it and what parameters to correct, I think you'll understand.
Files:
last1.mq4  4 kb
 
wishmast:

Please advise how the condition should look like. If a stop loss is triggered, then the lot is multiplied by 2, and if the next order triggers a take profit, the lot would return to the original lot, which was before the stop loss.

I understand it like this, but I don't know how to go on...

for (int i=OrdersHistoryTotal()-1; i>=0; i--)
   {
   if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)
      {
      if (OrderMagicNumber()==magic)
         {
         if (OrderStopLoss()==OrderClosePrice())
            {
            lot=lot*4;
            }
         }
      }

   } 

The solution to this problem depends on the Expert Advisor's full logic, you can trace the triggering of stoploss or takeprofit by its comment.

  if(StringFind(OrderComment(),"sl")>=0)// сработал стоплосс
  if(StringFind(OrderComment(),"tp")>=0)// сработал тейкпрофит

...

 
Artyom Trishkin:

You don't understand.

You need to make a single function that fills and sorts the array declared at global level. The array will need to be passed to the function by reference.

And you need additional functions that will take out the data you need from this array.

Artem, you are wrong. The array, declared on a global level is visible in all parts of the program, and you don't have to pass it somewhere from somewhere. It's just filled in one place in the program, sorted in another, and read in the third, it doesn't matter.