Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1519

 
does the final result in the profit in optimising parameters in the strategy tester take into account the money withdrawn via TesterWithdrawal or is it not a fixed profit at the end of the tests for the period that was still in the expenditure
 
maxvoronin74 #:

Perhaps it is because I have i >= 0. Yours is greater than zero. And the concatenation I was asking about is not accepted by MetaEditor. Although I took it from MetaQuotes article(https://www.mql5.com/ru/articles/12103)...

Why don't you check posTicket for equality to zero? After all, equality to zero according to the documentation indicates an error?

I don't understand the unnecessary checking of magik yet. The point of the code is to be sure that a position is not opened by this particular Expert Advisor on this instrument. There are several Expert Advisors on an instrument. Each of them has its own window. Experts are distinguished by magik.

I wrote it right away

Forum on trading, automated trading systems and testing trading strategies.

Questions from MQL5 MT5 MetaTrader 5 beginners

Alexey Viktorov, 2024.04.15 08:21

This willbe almost correct.

    for(int i = PositionsTotal(); i-- > 0;)
     {
      ulong posTicket = PositionGetTicket(i);
      long posMagic = PositionGetInteger(POSITION_MAGIC);
      string posSymbol = PositionGetString(POSITION_SYMBOL);
      if(posSymbol == _Symbol && posMagic == Magic_m)
       {

Everyone has his own programming principle and in my opinion this line of your code looks somehow strange

      if(total = 0 || (ticket > 0 && position_symbol==Symbol() && magic != Magic_m))

Why check if(total = 0 ......... because if there are no open positions, the loop will not be executed.

And the check if(.........magic != Magic_m)) does not give anything. After all, if a position has a different magic, it will simply start a new iteration of the loop without additional commands.

But it's all for amateurs. If you like it this way, write it this way...

that's why I don't check a ticket for equality with zero. I want it that way and nothing else...

Regarding the magik check, I was talking about something else. You can check for equality and inequality... So, someone likes to check for inequality and forcibly start a new iteration of the loop. But this approach is simply disgusting to me... I prefer checking for equality. If it is the magician I need, then all commands enclosed in curved brackets after the condition are executed. If the magician is someone else's, then a new iteration of the loop will start without additional stress.

The organisation of the loop can be any. The main thing is that the loop should be complete... This variant works without errors as well as the one in all the documentation examples. You just need to debug the loop organised in the same way as in the documentation examples and watch the loop counter change. Then everything will be clear.

 
AkaEdie TesterWithdrawal in the optimisation of parameters in the strategy tester, or is it not a fixed profit at the end of the tests for the period that was still in use?

Minus, as far as I remember, and all statistics changes with the account of this withdrawal. I used it a couple of years ago, but I didn't like the way the statistics was calculated, so I stopped using it, maybe now something has changed.

 
is there any article with a source for calculating the curve in the strategy tester other than the one I gave a few posts earlier, it is not compiled and my knowledge is not enough
 
how to add an indicator to a chart in an Expert Advisor and redraw it
 

Comrades, I have sorted out the topic, but now I have a new question, when I add an indicator to the chart in this way in the OnInit function, I get error 4114.

Here are the parameters and code of the Expert Advisor.

User
input ENUM_TIMEFRAMES ProfitTimeFrame = PERIOD_H1;//Временной интервал для вычислений
input ENUM_APPLIED_PRICE ProfitPriceAlligator = PRICE_CLOSE;//Цена для расчета Alligator
input int jawPeriod = 13;   // Период для Челюсти
input int jawShift = 8;     // Сдвиг для Челюсти
input int teethPeriod = 8;  // Период для Зубов
input int teethShift = 5;   // Сдвиг для Зубов
input int lipsPeriod = 5;   // Период для Губ
input int lipsShift = 3;    // Сдвиг для Губ
input ENUM_MA_METHOD maMethod = MODE_SMMA; // Метод скользящей средней (SMMA) для для Alligator

//----------------------------------------------------------------------------------------------------------------------------------------

// Создаем дескриптор индикатора Alligator
    int indicator_handle_Alligator = iAlligator(_Symbol, ProfitTimeFrame, jawPeriod, teethPeriod, lipsPeriod, jawShift, teethShift, lipsShift, maMethod, ProfitPriceAlligator);

    // Добавляем индикатор Alligator на график
    if(indicator_handle_Alligator != INVALID_HANDLE)
    {
        if(!ChartIndicatorAdd(chart_id, 0, indicator_handle_Alligator))
        {
            Alert("Ошибка при добавлении Alligator: ", GetLastError());
        }
        else
        {
            Alert("Alligator успешно добавлен на график");
        }
    }

question why?

 
    currentTF = Period();
    // Получаем ID текущего графика
    long chart_id = ChartID();
    // Создаем дескриптор индикатора Alligator
    int indicator_handle_Alligator = iAlligator(_Symbol, currentTF, jawPeriod, teethPeriod, lipsPeriod, jawShift, teethShift, lipsShift, maMethod, ProfitPriceAlligator);

    // Добавляем индикатор в основное окно (sub_window = 0) текущего графика
    if(!ChartIndicatorAdd(chart_id, 0, indicator_handle_Alligator))
    {
        Print("Ошибка при добавлении Alligator: ", GetLastError());
    }
    else
    {
        Print("Alligator успешно добавлен на график");
    }

how to remove indicators from the chart in an Expert Advisor if I have declared them like this in OnInit

 

and when updating the Expert Advisor for some reason one of the indicators is added again in the same way, but the old ones are not deleted.

not hide but delete

 
AkaEdie #:

and when updating the Expert Advisor for some reason one of the indicators is added again in the same way, but the old ones are not deleted

not hide but delete

I think it is better to check its existence on the chart before adding an indicator....

 

can there be someone in one code and whether in the article, the full code of adding and deleting,

or getting an existing one and adding it if it doesn't exist.

In the manual it's in parts, I don't know how to put it together.