mql5 - vertical line after a certain time since the last trade - page 3

 
renatmt5:
I have correctly understood that the last_time and result variables are the values we are looking for. The result determines by how much time the line will be shifted (redrawn) into the future. Then the code block "Profit for the period" should be put before the block "Move the vertical line" to move the line taking into account data obtained from the last deal.
Is this correct or am I confusing something?

These are internal variables of the LastProfitForPeriod function.

We want to get the value of the profit of the last trade, right? Here LastProfitForPeriod() gives us the profit of the last trade. It only remains to move the vertical line depending on these profits.

 
Vladimir Karputov:

So, the final touch is to move the line depending on the profit made.

Do you remember what the moving rules are?

oops, sorry - just to clarify:

- if the result of the last trade is negative and the result of the day is negative, the vertical line is drawn 24 hours (24 hours) into the future.
- if the result of the last transaction is negative and the result of the day is positive, the vertical line is drawn at a distance of 2 hours into the future.
- if the result of the last transaction is positive, the vertical line is drawn at a distance of 1 hour into the future.

 
Vladimir Karputov:

Here's an explanation of why the 'before' parameter needs to be done in the future:


Thank you!

 

The terms require the result of the day on which the last transaction was made (if there were several transactions on that day)

 
renatmt5:

Oops, sorry - just to clarify:

- if the result of the last trade is negative and the result of the day is negative, the vertical line is drawn 24 hours (a day) into the future.
- if the result of the last transaction is negative and the result of the day is positive, the vertical line is drawn at a distance of 2 hours into the future.
- if the result of the last transaction is positive, the vertical line is drawn at a distance of 1 hour into the future.

Ah, so we also need to get profit for the current day separately.


To make corrections to LastProfitForPeriod() - we remove the input time parameters "from" and "to" and form these parameters inside the function: form the time of day beginning (it will be "from"), and "to" we get the current time + day.


As a result, we will pass two parameters into LastProfitForPeriod() by reference: the profit for the day and the profit of the last trade.


The beginning of the day is obtained usingiTime

   datetime from_date=iTime(Symbol(),PERIOD_D1,0);

- i.e., it is the time of opening of the current daily bar.

 

Compiled - great!
There are only a few issues:
1) When imposing the indicator, the Profit last day variable value is not assigned to the last day of the last trade, but to the final profit of the account in general. Then, however, when recalculating the indicator (in about 1-2 minutes) the value changes to the correct one (the total profit of the day of the last trade). I am only judging by the account where the last trade was today.
2) When deleting the indicator from the chart, the Comment in the upper left corner is not deleted. When clearing the list of objects they are not deleted either. I restart the terminal to make the values disappear, which is not convenient, of course. How to make it easier - I do not know :)

Maybe, it would be more reasonable to place the blocks with the code of line creation, line movement and line deletion (Create the vertical line, Move the vertical line and Delete the vertical line) after the block of calculation of the last deal (Profit for the period). To draw the line taking into consideration the shift in future by n-hours, calculated on the basis of profit_last_day and profit_last_deal.

Like

if (profit_last_day<=0 and profit_last_deal<=0){n=24;}

else (profit_last_day>0 and profit_last_deal<=0){n=2;}

else {n=1;}
//---
time = last_time + n;
//---
then draw the line with a shift in time relative to the last trade, using the calculated time value...

 

Version 1.002 introduces protection: if the opening time of the day bar returns "0" - then it's no fate and we exit.

//+------------------------------------------------------------------+
//| Profit for the period                                            |
//+------------------------------------------------------------------+
void LastProfitForPeriod(double &profit_last_day,double &profit_last_deal)
  {
   datetime from_date=iTime(Symbol(),PERIOD_D1,0);
   if(from_date==D'1970.01.01 00:00')
      return;
   datetime to_date=TimeCurrent()+60*60*24;

   long last_time=0;


Now there will be no request for the lifetime of the trading account.

 
Vladimir, thank you very much again for your work!
I'll try to do the code myself, so that I don't get sick with conscience and practice :) I'll report the results, if there are any
 
renatmt5:
Vladimir, thank you very much again for your work!
I'll try to do the code myself, so that I don't get sick with conscience and practice :) I'll report the results, if there are any

Good.

 
By the way, on the protection you added there is the following point. Since I have a delay of 1-2 minutes before the correct value is calculated, during which the variables are zero, I switch the current timeframe to another one for a quick update - the values are immediately recalculated. Probably, it is possible to make some software crutch on this principle?