Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1521

 
maxvoronin74 #:
Thank you. Got it. Does it only show today's prints or can it be configured to show prints for other days?

I've never asked that question as I've never needed to. Look on the site, maybe someone is already interested in something similar. Search for expert tab or something similar.

Regards, Vladimir.

 
Good afternoon. Can anyone advise on the code, I make an advisor it should open from the current price of the deal to buy and sell, but the order of opening should be such that the deal Sell always above the deal Buy. But tried a lot of variations always get first buy and below comes sell. I tried to open at the current Buy and pending Sell after say 10 points. but to loop this function did not work Here is a code fragment
void OnTick()
{
double currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double currentSpread = SymbolInfoInteger(_Symbol, SYMBOL_SPREAD);

MqlTradeResult result; // Переменная result объявляется здесь

// Проверяем, есть ли открытые позиции и спред не превышает максимальное значение
if (PositionsTotal() == 0 && currentSpread <= MaxSpread)
{
// Открываем позицию на продажу
MqlTradeRequest request_sell;
ZeroMemory(request_sell);

request_sell.action = TRADE_ACTION_DEAL;
request_sell.symbol = _Symbol;
request_sell.volume = 0.01;
request_sell.type = ORDER_TYPE_SELL;
request_sell.price = currentPrice;
request_sell.sl = 0;//currentPrice + 300 * _Point;
request_sell.tp = 0;//currentPrice — 300 * _Point;

OrderSend(request_sell, result);


// Открываем позицию на покупку
MqlTradeRequest request_buy;
ZeroMemory(request_buy);

request_buy.action = TRADE_ACTION_DEAL;
request_buy.symbol = _Symbol;
request_buy.volume = 0.01;
request_buy.type = ORDER_TYPE_BUY;
request_buy.price = currentPrice + 200 * _Point;
request_buy.sl = 0;//currentPrice — 300 * _Point;
request_buy.tp = 0;//currentPrice + 300 * _Point;

OrderSend(request_buy, result);

}
 
maxvoronin74 #:
Thank you. Got it. Does it only show today's prints or can it be set to show prints from other days?

If you have a lot of prints, not all of them are displayed for today. But it's better to see the latest ones here. After all, you have to open the log file, but here you can see it at once.

 
harrison90 current price of the deal to buy and sell, but the order of opening should be such that the deal Sell always above the deal Buy. But tried a lot of variations always get first buy and below comes sell. I tried to open on the current Buy and pending Sell after say 10 points. but to loop this function did not work Here is a fragment of code

If it were possible, I would not be sitting here...

 
harrison90 current price of the deal to buy and sell, but the order of opening should be such that the deal Sell always above the deal Buy. But tried a lot of variations always get first buy and below comes sell. I tried to open the current Buy and pending Sell in 10 points, but I could not loop this function. Here is a code fragment
You probably mean the corridor between support and resistance levels? From the lower level - buy, from the upper level - sell. There are experts in the Market, I think even free ones, who offer such a feature. But you need to draw the levels yourself. There are indicators that suggest the direction of a deal with greater or lesser accuracy. The code can be based on them.
.


 

Good day and good cheer everyone!

Questions from a beginner in programming:

  1. What is the fundamental difference between a user-defined structure and globally declared variables?
  2. Is the speed of accessing a structure and global variables different or approximately the same?
  3. Apart from convenience in programming, does a custom structure have any other useful property?

Regards, Vladimir.
 
MrBrooklin global variables different or approximately the same?
  • Apart from convenience in programming, does a custom structure have any other useful property?
  • Regards, Vladimir.

    I am not a professional programmer, so do not judge me strictly and my answer may be inaccurate.

    A structure is an OOP element. Unlike a simple variable, it contains several data types and allows you to describe some object.
    For example, we are programming a computer game and we need to describe a monster that has several lower limbs (int),
    several upper limbs (int), some strength (float, double), time of birth (datetime), coordinates in space and other characteristics.

    You can create an array of structures, a structure element can also be an array or a structure. In some cases it is almost impossible to do without
    structures.

    As for speed, I think that the difference with ordinary variables is minimal. You can test it - it is not difficult.

     
    Grigori.S.B #:
    You can test it - it's not difficult.

    Thank you. I was just thinking about this topic - why create a structure when you can easily do without it with global variables. Well, this is my unprofessional opinion.

    I have a complete problem with speed measurement, as I have never done it and have no idea how to do it. ))

    Regards, Vladimir.

     
    MrBrooklin #:

    Thank you. I was just thinking about this topic - why create a structure if you can easily do without it with global variables. Well, this is my unprofessional opinion.

    I have a complete problem with speed measurement, as I have never done it and have no idea how to do it. ))

    Regards, Vladimir.

    I can't imagine how you can implement the appearance of a new object with several different properties without structures / OOP.
    Disappearance of one of the old objects (for example, a monster was killed).
    Especially if the number of objects changes dynamically and is not known in advance.

    There are a lot of examples of measuring speed / comparing execution of different code fragments here.
    The same saber posts several examples every day.
    1. Create a high-resolution timer
    2. Print its value before the operation is executed.
    3. After the operation is executed.
    The difference is the time of the operation execution.

    Do it for a regular variable and for a structure and compare.

     
    MrBrooklin #:
    and why would you create a structure

    for example, to put it together,

    /*struct PriceData
      {
       double            open[];
       double            high[];
       double            low[];
       double            close[];
      };*/

    or to create structures for monsters in the game

    //--- базовая структура для описания монстров
    struct Animal
      {
       int               head;          // кол-во голов
       int               legs;          // кол-во ног
       int               wings;         // кол-во крыльев
       bool              tail;          // наличие хвоста
       bool              fly;           // летает
       bool              swim;          // плавает  
       bool              run;           // бегает
      };

    further

    //--- создадим объект базового типа Animal и опишем его 
       Animal some_monster_small; 
       some_monster_small.head=1; 
       some_monster_small.legs=4; 
       some_monster_small.wings=0; 
       some_monster_small.tail=true; 
       some_monster_small.fly=false; 
       some_monster_small.swim=false; 
       some_monster_small.run=true; 
    
    и далее
    
       Animal some_monster_bigboss; 
       some_monster_bigboss.head=3; 
       some_monster_bigboss.legs=8; 
       some_monster_bigboss.wings=1; 
       some_monster_bigboss.tail=true; 
       some_monster_bigboss.fly=true; 
       some_monster_bigboss.swim=true; 
       some_monster_bigboss.run=true; 
    
    
    example from the help... names changed