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

 

Last deal Move Vertical line

version "1.004"

Now the line is moved according to the requirements.

   long offset_seconds=60*60*1;
   if(profit_last_day<=0.0 && profit_last_deal<=0.0)
     {
      offset_seconds=60*60*24;
     }
   else if(profit_last_day>0.0 && profit_last_deal<=0.0)
     {
      offset_seconds=60*60*2;
     }

   VLineMove(0,InpVLineName,time[rates_total-1]+offset_seconds);


After removing the indicator from the chart, the chart comment is cleared and the line is deleted.

//+------------------------------------------------------------------+ 
//| Custom indicator deinitialization function                                 | 
//+------------------------------------------------------------------+ 
void OnDeinit(const int reason)
  {
   Comment("");
   VLineDelete(0,InpVLineName);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
 
Vladimir Karputov:

Last deal Move Vertical line

version "1.004"

Now the line is moved according to the requirements.


After removing the indicator from the chart, the chart comment is cleared and the line is deleted.

Great!
Only, as I understand it, there is an inaccuracy in the definition of the required time, namely the shift is added to the current time, while it should be added to the closing time of the last trade.
As a result, the line may end up in the future as well as in the past:
- in the future. For example, the last trade was 10 minutes ago with negative results for the trade itself and for the day as a whole - the line has shifted by 23 hours 50 minutes relative to the current time.
- in the past. For example, the last deal was last night at 8:00 pm, as a result plus on the deal and plus on the day - the line was drawn on yesterday's bar corresponding to the time 21:00

 
I do not trade on this indicator while the line is in the future - emotionally recovering to make the next trading decision with a cool head
 
renatmt5:

Great!
But, as far as I see, there is an inaccuracy in specification of the required time, namely, the shift is added to the current time while the shift should be added to the time of closing of the last trade.
As a result, the line may end up in the future as well as in the past:
- in the future. For example, the last trade was 10 minutes ago with negative results for the trade itself and for the day as a whole - the line shifted by 23 hours 50 minutes relative to the current time.
- in the past. For example, the last deal was last night at 8:00 pm, as a result plus on the deal and plus on the day - the line was drawn on yesterday's bar corresponding to the time 21:00

It's not the time that is defined inaccurately, it's the Terms of Reference that keeps getting refined :)

So, we need to modify the LastProfitForPeriod function and add a third argument to it - the time of the last trade. But I will do this at lunchtime.

 
Vladimir Karputov:

It's not the time that is defined inaccurately, it's the Terms of Reference that keeps getting refined :)

So, we need to modify the LastProfitForPeriod function and add a third argument to it - the time of the last trade. But I will do it at lunchtime.

Vladimir, I will definitely take into account the inaccuracy of the requirement specification in the future!

 
Yes, I also just noticed - Profit last day and Profit last deal are no longer counted in Comments - they are shown as zeros.
My last trade was 19 hours ago, i.e. within +-24 hours of current time
 
Just in case - between the last transaction yesterday and the current time there was a brokerage operation ACID_NW - commission as I understand it. But you never know - maybe it somehow "broke" the algorithm of calculation
 
After closing the order, theProfit last day and Profit last deal datawas updated and the result of the new last deal and the current day were displayed correctly.
 
renatmt5:
Just in case - between last deal yesterday and current time there was ACID_NW broker's operation - commission, as I understand. And who knows - maybe it somehow "broke" the algorithm of calculation

I will not change anything, as there are more and more subtleties depending on the type of account: netting or hedging.


I will not change anything, because there are more and more nuances depending on the account type: netting or hedging.

 
Vladimir Karputov:

I will not change anything, as there are more and more subtleties depending on the type of account: netting or hedging.


The rest is up to you.

Ok.
Thank you very much for your help, Vladimir!

Reason: