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

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

I hate the word 'crutch'.


I've already thought of everything beforehand and it's very good that you asked. We need to turn LastProfitForPeriod from void into bool. If there is an error - for example, the date is not found or something else, we return false and so on.

Thus, there will be no loss of minutes.

 

If you get "false", reset the time:

   double profit_last_day=0.0,profit_last_deal=0.0;
   if(!LastProfitForPeriod(profit_last_day,profit_last_deal))
     {
      ExtLastMove=0;
      return(rates_total);
     }

   Comment("Profit last day: ",DoubleToString(profit_last_day,2),"\n",
           "Profit last deal: ",DoubleToString(profit_last_deal,2));


Version 1.003

 
Vladimir Karputov:

I hate the word 'crutch'.


I've already thought of everything beforehand and it's very good that you asked. We need to turn LastProfitForPeriod from void into bool. If there is an error - for example, the date is not found or something else, we return false and so on.

Thus, there will be no loss of minutes.

About "crutch" - yes, there is some careless attitude to programming in this word :)

Yes, the lost minute effect is gone in v.3 of the script.

 
renatmt5:

As for "crutch" - yes, there is some careless attitude to programming in that word :)

Yes, the lost minute effect is gone in v.3 of the script.

It's an indicator:)

 
Vladimir Karputov:

It's an indicator:)

Yes, that's right - still getting confused.

 

I have added a block to calculate the time offset in relation to the closing of the last transaction. When trying to use last_time and n for line offset later on, I get a compile-time error :(

.....

                    {

                     last_time=deal_time;

                     profit_last_deal=full_profit;

                    }

                 }

        }

     }

//-------------//     

// MY CODE     //   

//-------------//

if (profit_last_day<=0 && profit_last_deal<=0){uint n=60*60*24;}

else if (profit_last_day>0 && profit_last_deal<=0){uint n=60*60*2;}

else {uint n=60*60*1;}

//-------------//     

// MY CODE END //   

//-------------//

   return(true);

  }

.......
 
Somehow I'm not inserting the code snippet correctly :)
 
When creating ObjectCreate (chart_ID,name,OBJ_VLINE,sub_window,time,0), I need to change time from TimeCurrent() tolast_time with an offset to the future by a period equal to n.
Or maybe there is a function that shifts an object forward/backward by specified number of bars? What is better? I confess that so far my independent efforts have been unsuccessful :(
 
renatmt5:
When creating ObjectCreate (chart_ID,name,OBJ_VLINE,sub_window,time,0), I want to change time value so it would not be TimeCurrent(), butlast_time with an offset for the period equal to n.
Or maybe there is a function that shifts an object forward/backward by specified number of bars? What is better? I confess that so far my independent efforts have been unsuccessful :(

The line is created once - in OnInit().

Then it is only moved -VLineMove

 

Do I understand correctly that I need to make changes in the last line of the code snippet (time=0 in particular)?

//+------------------------------------------------------------------+ 
//| Move the vertical line                                           | 
//+------------------------------------------------------------------+ 
bool VLineMove(const long   chart_ID=0,   // chart's ID 
               const string name="VLine", // line name 
               datetime     time=0)       // line time 


Or VLineMove is a function, which still needs to be initiated in some place (e.g. in OnCalculate) and pass the incoming parameters to it?
I'm completely confused :)

Reason: