![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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.
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.
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)
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
- 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.
Now there will be no request for the lifetime of the trading account.
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
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.