Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 400

 
Link_x:

Thank you, Yuri.
I will try to use your code, but later, as I need to take it apart and understand the principle of operation.
Above described step is not difficult, then I will have to take apart each custom function of Mr. "N", and this has the highest degree of complexity, respectively, will take a lot of time, from 3 to 10 hours (as they say: - One day. -).

I'll finalise my code, it's "my habitat" and there's nothing to study in it.

Thanks again, Yuri.






You don't have to go into the code of every function to begin with. It is enough to understand the parameters used in the function, its purpose and use. I did not actually go into the innards of each function myself. I delved into it only when I had to change it in some way. I mean, you successfully use mobile phones, computers and televisions, without knowing their exact schemes and how they work, but that doesn't stop you from using them for your own purposes. In this case, the main thing is to know how to use these functions. All the functions and their functions are described here . You will learn how to use them from the tests, which are given for each function. You will become a programmer faster if you follow this path. But reinventing your own bicycle is a long and unproductive path. Building an expert - according to your version - is like building a house with no building materials. You have to invent everything yourself. It is much faster to build a house when there are building blocks (functions).
 

Good afternoon!

Could you please tell me, does the AccountEquity() function make a request to the terminal or to the broker?

The question is prompted by the assumption that calling this function on every tick may irritate the broker (especially when running the EA on several charts at the same time) and consequently block the account?

 
yan720:

Good afternoon!

Can you tell me, does the AccountEquity() function make a request to the terminal or to the broker?

The question is caused by the assumption that calling this function on every tick may irritate the broker (especially when running the EA on several charts simultaneously) and consequently block the account?


Yes to the broker of course)))

The terminal doesn't care.... Will give you the last known data...

 
vadynik:
The question is whether we should pass Magic into the functionor not.

This can be understood if you know what the wizard is for. It is needed for the EA to be able to distinguish its own orders from the orders of another EA or manually opened orders. If you have several buy-stop orders and there are various magicians or manual orders (without a magician) among them, the magician is needed for the function. In general, it would be better to set a magik as a parameter for a function to universalize its functions. For instance, it should be set to -1 by default.

double BuystopPrice(int Magic = -1)
{
double Price=0;
  for (int i=OrdersTotal()-1; i>=0; i--) 
     {
        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
          if(OrderMagicNumber()==Magic && OrderType()==OP_BUYSTOP)
          {
           Price = OrderOpenPrice();
          break;
          }
        }
     }
    return(Price);
}

Actually, since your function's code determines the setting price of the first buy-stop order in the loop only, the loop itself is not needed in principle.

 
khorosh:
It is not necessary to go into the code of each function to begin with. It is enough to understand the parameters that are used in the function, its purpose and use. I did not actually go into the innards of each function myself. I delved into it only when I had to change it in some way. I believe that you successfully use mobile phones, computers and televisions, without knowing their exact schemes and how they work, but that doesn't stop you from using them for your own purposes. In this case, the main thing is to know how to use these functions. All the functions and their functions are described here . You will learn how to use them from the tests, which are given for each function. You will become a programmer faster if you follow this path. But reinventing your own bicycle is a long and unproductive path. Building an expert - according to your version - is like building a house with no building materials. You have to invent everything yourself. It is much faster to build a house when there are building blocks (functions).


You are a wise man, able to explain and change your mind if need be. :)
That said, I thank you again.

In that case, I leave the construction of a house from eukaryotic cell organoids and use ordinary building materials for its construction.
 

Please check two functions for errors in them.

The essence of the first: should calculate a lot required to exit the drawdown after closing a grid of orders (open on margin), if the price passes a certain number of points (TP-points) in the right direction.

The essence of the second: it should close half of the orders of the grid, starting with the oldest.

double FindRightLot (int otype) // функция поиска лота, необходимого для выхода из просадки после 
                               //закрытия сетки ордеров
{
  double Lot=0; double TotalLot=0;
  for (int i = OrdersTotal()-1; i>0; i--)
  {
    if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
    {
       if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType() == otype)
       {
         if (otype == OP_BUY)
         {
           Lot = NormalizeDouble ((OrderOpenPrice()-Bid)*OrderLots()/TP,2); 
           if (Lot>0)
           {
              TotalLot= NormalizeDouble (TotalLot+Lot,2);
           }
         }
           
       
         else if (otype == OP_SELL)
         {
           Lot = NormalizeDouble ((Ask-OrderOpenPrice())*OrderLots()/TP,2);
           if (Lot>0)
           {
            TotalLot= NormalizeDouble (TotalLot+Lot,2);
           }
           
         }
       }
     }
   }
   return (TotalLot);
   
 }
//+------------------------------------------------------------------+

void CloseHalfOrders (int otype)// ф-ция закрытия половины ордеров сетки
{
  int count = 0;
  for (int i = 0; i<= OrdersTotal(); i++)
  {
    if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
    {
       if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType() == otype)
       {
         if (otype == OP_BUY)
         { 
           if (count<CountTrades(OP_BUY)/2 && CountTrades(OP_BUY)>3 )
           
             OrderClose(OrderTicket(),OrderLots(),Bid,0,Black);
             count++;
           
         }
       
       
         else if (otype == OP_SELL)
         {
           if (count<CountTrades(OP_SELL)/2 && CountTrades(OP_SELL)>3)
           
           OrderClose(OrderTicket(),OrderLots(),Ask,0,Black);
           count++;
           
         }
       }
     }
   }
   
 }
 
Guys, you can't do that... You can go straight to MQL5, but the entire POSITION is opened there....
 
yan720:


Can you tell me, does AccountEquity() query the terminal or the broker?

to the terminal
 
vadynik:


I may not be asking exactly, I mean will the function see a magik which is set in a global variable

or should it be passed into a function, although I suspect it shouldn't since it's global

If it is in a global variable, yes, it will. But the function should have versatility and work with more than one wizard, and for this it's better to pass it as a function parameter.
 
vadynik:


I may not have asked exactly what I meant, I mean, will the function see a magik that is set in a global variable

of course it will.

Global variables are global because they are globally visible.

what's not clear?

----

but following the good manners - pass all the parameters into the function which will make it more independent of the calling environment.

The reason for this is to abstract the names of the variables inside the function from the global variable names.

Reason: