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

 
Taras Slobodyanik:

- Look at the time of the last bar
- add up everything that was closed on this bar
- subtract from the current balance

and so on, one bar at a time.

Can't you do it without arithmetic? Maybe you could write some kind of user-defined function?

 
novichok2018:
I probably did not phrase my question correctly, since the answers are off-topic. I do not care whether the positions have closed or not, and I am not interested in the value of a tick. I need to know what the account balance was at the time of closing 1, 2, 3 bars of a particular symbol for comparison. Positions on these bars were opened and closed, including positions on other symbols: some positions were closed on the plus side, some were closed in the minus side, some were not closed yet, therefore the balance has changed. I need to know the specific values. Thank you.

there are no standard functions, as well as no search through the forum or any other way

In the tester, you can simulate the following situation: when trading using several Expert Advisors, you can not know what balance was at that time. Of course, you can try to count orders that were opened, and then look for a time when there were no open orders in terminal history ... And the final result does not mean that everything will be taken into account

in the tester you can easily simulate this situation - describe in the global scope a variable and check condition in OnTick if(OrderTotal()==0) StartBalance = AccountBalance();

and then, when opening orders in the tester, you have the initial value of balance.... You can add to it each bar the value of profit orders, you can add these values to an array or a list


But if you want to use this code for an account with several Expert Advisors, you have to formulate your task not as a search of the balance n-bars ago, but as a total profit of the open orders; you don't write any open orders, you open an order - start adding profit every bar to the array. It means you are looking for an opportunity to change the logic of your TS not in connection with the balance, but with the open order profit and/or the closed order profit in the terminal history for a period (day, hour?)

 
Igor Makanu:

there are no standard functions, as well as no search through the forum or any other way

In the tester, you can simulate the following situation: when trading using several Expert Advisors, you can not know what balance was at that time. Of course, you can try to count orders that were opened, and then look for a time when there were no open orders in terminal history ... And the final result does not mean that everything will be taken into account

in the tester you can easily simulate this situation - describe in the global scope a variable and check condition in OnTick if(OrderTotal()==0) StartBalance = AccountBalance();

and then, when opening orders in the tester, you have the initial value of balance.... You can add to it each bar the value of profit orders, you can add these values to an array or a list


But to work with this code on an account with several EAs, the task should not be to search for the balance n-bars ago, but to sum up the total profit of the open orders, no open orders, open order - start recording profit every bar in the array. It means you are looking for possibility to change the logic of your TS not related to the balance, but to the open orders profit and/or closed orders profit in the terminal history for a period (day, hour?)

Understood. Thanks for the detailed reply.

 

Hello! How do I get the input parametersAFTER creating a technical indicator handle that was created using iCustom.

For example

iCustom(NULL,0, "name_indicator",1,2,3) - how to get the input parameters 1,2 and 3?

 
Hello, could you please tell me how to find out the current drawdown percentage?
 
nalyk:
Hello, could you please tell me how to find out the current drawdown percentage?

Keep an account of equity

 
nalyk:
Hello, could you please tell me how to find out the current drawdown percentage?
double drawdown = AccountProfit()*100/AccountBalance();
 

Is it possible to apply a template to a structure and a class to declare variables of a template type inside them in order to later work with these variables and refer to them? I tried this with a structure.

templ(T)struct A
{
  T val;
  int ind;
};

It compiles, but does not allow to assign a name to the structure.

 
Hello! Help me do the following:
It is necessary to make a target profit for each open position in the market, but not total, but separate!
Example: EURUSD opened and has a target profit of $1 in its settings, and as soon as it reached it, the position closed by itself, only it!
Each currency pair should work by itself, not by the total profit!

I found the code for the total profit for all pairs:
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает суммарный профит открытых позиций в валюте депозита |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
double GetProfitOpenPosInCurrency(string sy="", int op=-1, int mn=-1) {
  double p=0;
  int    i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (mn<0 || OrderMagicNumber()==mn) {
            p+=OrderProfit()+OrderCommission()+OrderSwap();
          }
        }
      }
    }
  }
  return(p);
}
help redo for each currency pair separately......Thank you very much!
 
ponochka:
Hello! Please help me to do the following:
It's necessary to make a target profit for each open position in the market, but not total, but separate!
Example: EURUSD opened and has a target profit of $1 in its settings and as soon as it reached it, the position closed by itself, just that one!
Each currency pair should work by itself, not by the total profit!

I found the total profit code for all pairs:
help redo for each currency pair separately......Thank you very much!

Pass in the first parameter of this function the string with your pair and it will only count profits on this pair.

Pass in the second parameter of this function the type of operation (buy or sell) and it will count profit only on this operation.

And so will the magic number. This is a universal function.

Reason: