Can Someone help me to calculate the "Expire Time" for this code ?

 

In this code, all I need to do is calculate the expire time to send the order. I did search for a method to do this, but I could not find it. Can someone please help me to figure out this?.

I need to add 1 minute to the current time

I checked with a comment (The way I did in bellow code) it's just added additional two numbers to the seconds of current time.

ex - True Time = 2024.04.04 23:15:20 

       After My modification it shows like  = 2024.04.04 23:15:2060 


       double SL = OpenPrice - NormalizeDouble((Stop_Loss *Point()_Digits)); // Calculate the stop loss price for the BUY order
       datetime expiration = TimeCurrent() + 60;  // << ------------------------------------------------------------------------------------- No Idea about how to add 01 minute to the current Time 

            
       MqlTradeRequest request {};

       request.action = TRADE_ACTION_PENDING;
       request.magic = Magic_Number;
       request.sl = SL;
       request.price = OpenPrice;
       request.symbol = Symbol();
       request.type = ORDER_TYPE_BUY_STOP;
       //request.type_time = ORDER_TIME_SPECIFIED;       
       //request.expiration = expiration;
       request.volume = Lots_ize;
       request.magic = Magic_Number;

       MqlTradeResult results {};

       processed = OrderSend(request,results); // Sends order to the server 
       PlaySound("ok.wav");
Documentation on MQL5: Date and Time / TimeCurrent
Documentation on MQL5: Date and Time / TimeCurrent
  • www.mql5.com
Returns the last known server time, time of the last quote receipt for one of the symbols selected in the "Market Watch" window. In the...
 

I really don't see what you did wrong. If you're printing the value, that may be the issue - you may be doing it like Print(TimeCurrent(), 60). This will print the date time as you shown.

I tested a simple script written like this:


void OnStart()
{
    Print("TimeCurrent() = ", TimeCurrent());
    Print("TimeCurrent() + 60 = ", TimeCurrent() + 60);
}


The correct value is returned.

 

Just check your setting in the debugger - it is made for this!!

Code debugging:  https://www.metatrader5.com/en/metaeditor/help/development/debug

Code debugging - Developing programs - MetaEditor Help
  • www.metatrader5.com
MetaEditor has a built-in debugger allowing you to check a program execution step by step (by individual functions). Place breakpoints in the code...
 
Hapu Arachchilage Tharindu Lakmal:

In this code, all I need to do is calculate the expire time to send the order. I did search for a method to do this, but I could not find it. Can someone please help me to figure out this?.

I need to add 1 minute to the current time

I checked with a comment (The way I did in bellow code) it's just added additional two numbers to the seconds of current time.

ex - True Time = 2024.04.04 23:15:20 

       After My modification it shows like  = 2024.04.04 23:15:2060 


you can use the TimeLocal function to get the current time in seconds since January 1, 1970, and then add the number of seconds representing one minute to it.
This website uses cookies. Learn more about our Cookies Policy.