I'm trying to write a function that determines the profit for the current day:
Can you tell me how in the function
Specify period starting from current day. It is clear that end of period to_date=TimeCurrent(), how to correctly specify start of period from_date, so that it starts from 00h:00m:00c of current day?
intCopyTime(
string symbol_name, // имя символаENUM_TIMEFRAMES timeframe, // период PERIOD_D1int start_pos, // откуда начнем 0int count, // сколько копируем 1datetime time_array[] // массив для копирования времени открытия. Объявить заранее
Or the most, the most. Which has already been suggested.
Assuming that there was at least one tick today, the algorithm is as follows: the current time is sent to theMqlDateTime structure. Then set the hours, minutes and seconds to zero in this structure. It remains to convert the edited structure into a time:
Result:
Thank you! Another question, if I add a function
//+------------------------------------------------------------------+//|Функция возвращает прибыль за текущие сутки |//+------------------------------------------------------------------+double Day_Profit()
{
//--Запрашиваем историю сделок за последнии суткиHistorySelect(TimeCurrent()-PeriodSeconds(PERIOD_D1),TimeCurrent());
uint total =HistoryDealsTotal(); // количество сделок в историиulong ticket =0; // тикет сделки в историиlong type =0; // тип сделкиdouble profit =0.0; // финансовый результат сделкиdouble commission =0.0; // коммиссия по сделкеdouble DayProfit =0.0; // прибыль за текущие сутки//--- for all dealsfor(uint i=0; i<total; i++)
{
if((ticket=HistoryDealGetTicket(i))>0) //--- если имеются сделки, то...
{
profit =HistoryDealGetDouble(ticket,DEAL_PROFIT);
commission =HistoryDealGetDouble(ticket,DEAL_COMMISSION);
if(HistoryDealGetInteger(ticket,DEAL_TYPE)!=DEAL_TYPE_BALANCE)
{
DayProfit+=(profit+commission);
}
}
}
return (DayProfit);
}
//+------------------------------------------------------------------+
to the Expert Advisor, how will the period for which trades are analyzed be updated? For example, if my Expert Advisor works for a couple of days, then when the next day comes, the period will be updated?
Implementation of the above function in the Expert Advisor:
Thank you! Another question, if I add the function:
to the Expert Advisor, how will the period for which trades are analysed be updated? For example, if the Expert Advisor works for a couple of days, then with the next day the period will be updated?
The implementation of the above function in the Expert Advisor:
The time should be set from the beginning of a day to the current time + day or + three days.
You already know how to determine the beginning of day.
There is a need to determine the spread for a symbol before placing an order on it. The standard MQL5 library includes CSymbolInfo class. That's when I started wondering, which way is better to implement this check - via CSymbolInfo or using a function? Please, expert, advise me on what to do! If this question has already been raised, I will be very grateful if you direct me in the right direction.
I am in need of some advice. How bars are calculated when an EA contains signal modules from different timeframes?
For example, I have a simple Expert Advisor that has two signal modules based on stochastic (when the main line is above the signal line on 0 and 1 bars - BUY, below the signal line on 0 and 1 bars - SELL) - one on H1 and the other on M15. Weights of both modules are the same and in the Expert Advisor the threshold for opening of a deal is set in such a way that signals from both modules should be considered simultaneously. The Expert Advisor works on the chart at timeframe H1. If you look at the screenshot of H1, everything is clear - the main line is higher than the signal line on the last and penultimate bars and that is why we buy. But on the chart of M15 I cannot understand which bar should be considered as 0 and which as 1? The deal is open - it means that on M15 the condition for the deal should be fulfilled as well.
For example, there is a simple Expert Advisor that includes two signal modules based on stochastic (when the main line is above the signal line on 0 and 1 bars - BUY, below the signal line on 0 and 1 bars - SELL) - one for H1, the other for M15.
Zero bar is evil! The indicator on the history you see calculated as if on 1 bar - closed (well, simplified, if not taking into account the possibility of re-crossing). Accordingly, the strategy is built on a closed bar and in the tester, the indicator from the major TF in MT4 will show the result of even a zero bar, as a closed one - i.e., from the future.
The result is disappointment: one thing is different in the tester, while the opposite is true in real time.
Take my word for it - I've lost half of my life while trying to figure out where the system error is. For correct mapping of indicators of higher TFs on a lower one special approach is needed. Usually with Pushka, for example, everything is simple - multiply period by TF ratio and the order, but if there are non-linear calculations, then there is only imitation of calculation on 0 bar.
I was breaking RSI for a year to get it to correctly display the major TF on the chart.
I do not insist, I recommend as a minimum to use signals from closed bars, especially from higher in relation to the current timeframe, and also check especially custom indicators for re-rating.
I am in need of some advice. How bars are calculated when an EA contains signal modules from different timeframes?
For example, I have a simple Expert Advisor that has two signal modules based on stochastic (when the main line is above the signal line on 0 and 1 bars - BUY, below the signal line on 0 and 1 bars - SELL) - one on H1 and the other on M15. Weights of both modules are the same and in the Expert Advisor the threshold for opening of a deal is set in such a way that signals from both modules should be considered simultaneously. The Expert Advisor works on the chart at timeframe H1. If you look at the screenshot of H1, everything is clear - the main line is higher than the signal line on the last and penultimate bars and that is why we buy. But on the chart of M15 I cannot understand which bar should be considered as 0 and which as 1? The deal is open, it means that on M15 the condition for the deal should be met as well.
On the history you see already closed bars and the zero bar is not an evil, but it is mobile and we have to take it into account, because it is formed depending on the current price and stochastic changes of direction are possible when prices jump, soit is more sensitive, it can close for example.
Try adding one more bar just to open 0 && 1 && 2. maybe the plums will be reduced.
Приказы на проведение торговых операций оформляются ордерами. Каждый ордер имеет множество свойств для чтения, информацию по ним можно получать с помощью функций Идентификатор позиции, который ставится на ордере при его исполнении. Каждый исполненный ордер порождает сделку, которая открывает новую или изменяет уже существующую позицию...
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Good afternoon!
I'm trying to write a function that determines the profit for the current day:
Can you tell me how in the function
Specify period starting from current day. It is clear that end of period to_date=TimeCurrent(), how to correctly specify start of period from_date, so that it starts from 00h:00m:00c of current day?Choose to taste:
Or the most, the most. Which has already been suggested.
Assuming that there was at least one tick today, the algorithm is as follows: the current time is sent to theMqlDateTime structure. Then set the hours, minutes and seconds to zero in this structure. It remains to convert the edited structure into a time:
Result:
Thank you! Another question, if I add a function
to the Expert Advisor, how will the period for which trades are analyzed be updated? For example, if my Expert Advisor works for a couple of days, then when the next day comes, the period will be updated?
Implementation of the above function in the Expert Advisor:
Thank you! Another question, if I add the function:
to the Expert Advisor, how will the period for which trades are analysed be updated? For example, if the Expert Advisor works for a couple of days, then with the next day the period will be updated?
The implementation of the above function in the Expert Advisor:
The time should be set from the beginning of a day to the current time + day or + three days.
You already know how to determine the beginning of day.
Good afternoon!
There is a need to determine the spread for a symbol before placing an order on it. The standard MQL5 library includes CSymbolInfo class. That's when I started wondering, which way is better to implement this check - via CSymbolInfo or using a function? Please, expert, advise me on what to do! If this question has already been raised, I will be very grateful if you direct me in the right direction.
Good afternoon!
I am in need of some advice. How bars are calculated when an EA contains signal modules from different timeframes?
For example, I have a simple Expert Advisor that has two signal modules based on stochastic (when the main line is above the signal line on 0 and 1 bars - BUY, below the signal line on 0 and 1 bars - SELL) - one on H1 and the other on M15. Weights of both modules are the same and in the Expert Advisor the threshold for opening of a deal is set in such a way that signals from both modules should be considered simultaneously. The Expert Advisor works on the chart at timeframe H1. If you look at the screenshot of H1, everything is clear - the main line is higher than the signal line on the last and penultimate bars and that is why we buy. But on the chart of M15 I cannot understand which bar should be considered as 0 and which as 1? The deal is open - it means that on M15 the condition for the deal should be fulfilled as well.
For example, there is a simple Expert Advisor that includes two signal modules based on stochastic (when the main line is above the signal line on 0 and 1 bars - BUY, below the signal line on 0 and 1 bars - SELL) - one for H1, the other for M15.
Good afternoon!
I am in need of some advice. How bars are calculated when an EA contains signal modules from different timeframes?
For example, I have a simple Expert Advisor that has two signal modules based on stochastic (when the main line is above the signal line on 0 and 1 bars - BUY, below the signal line on 0 and 1 bars - SELL) - one on H1 and the other on M15. Weights of both modules are the same and in the Expert Advisor the threshold for opening of a deal is set in such a way that signals from both modules should be considered simultaneously. The Expert Advisor works on the chart at timeframe H1. If you look at the screenshot of H1, everything is clear - the main line is higher than the signal line on the last and penultimate bars and that is why we buy. But on the chart of M15 I cannot understand which bar should be considered as 0 and which as 1? The deal is open, it means that on M15 the condition for the deal should be met as well.
On the history you see already closed bars and the zero bar is not an evil, but it is mobile and we have to take it into account, because it is formed depending on the current price and stochastic changes of direction are possible when prices jump, soit is more sensitive, it can close for example.
Try adding one more bar just to open 0 && 1 && 2. maybe the plums will be reduced.