Converting seconds to date and time?

 
I'm wanting to understand how to change seconds into date and time?

Short_Trade_Send = OrderSend(Symbol(),OP_SELL,LotSize_Sell,Bid,3,Short_Stop_Price,stp1,NULL,MagicNumber,0,Green);
if( Short_Trade_Send > 0 )TradeOpenTime = GlobalVariableSet(" Open Time ", OrderOpenTime());
double Get_Open_Time = GlobalVariableGet(" Open Time ");
datetime OpenTime_Format = StrToTime( " Open Time " );
string OpenTime_Format1 = TimeToStr(OpenTime_Format, TIME_DATE|TIME_MINUTES);

"Get_Open_Time" is simply storing the open position time (incase platform has crashed and reboots it remembers).

When I am printing this all it shows is:

2014.08.05 15:24:02.312 2009.01.28 20:07  Quant Research EURUSD,H1: OpenTime_Format1  = 2009.01.28 00:00

 Any help on where I am being an idiot :) 

 
I don't understand why the hours and minutes are not populating? Is it something to do with tester mode?
 
DomGilberto: I don't understand why the hours and minutes are not populating? Is it something to do with tester mode?
Short_Trade_Send = OrderSend(Symbol(), OP_SELL, LotSize_Sell, Bid, 3, Short_Stop_Price, stp1, NULL, MagicNumber, 0, Green);
if( Short_Trade_Send > 0 ) TradeOpenTime = GlobalVariableSet(" Open Time ", OrderOpenTime());
  1. It has nothing to do with "tester mode."
  2. It has to do with NOT selecting the order before calling OOT()
 
DomGilberto:
I'm wanting to understand how to change seconds into date and time?
. . .

Any help on where I am being an idiot :) 


  1. Short_Trade_Send = OrderSend(Symbol(),OP_SELL,LotSize_Sell,Bid,3,Short_Stop_Price,stp1,NULL,MagicNumber,0,Green);
    if( Short_Trade_Send > 0 )TradeOpenTime = GlobalVariableSet(" Open Time ", OrderOpenTime());
    You must use OrderSelect() before attempting to use OrderOpenTime().
  2. datetime OpenTime_Format = StrToTime( " Open Time " );
    Why are you doing this?  You are converting the string "  Open Time  " to Time.  I don't think that is what you meant/want to do.


.

 

Damn it I knew that! God that annoys me! I think I had been looking at it too much today tbh. Thanks for pointing that out!

I don't even know why I am doing it this way anyway for what I am trying to achieve!

 

Just quickly playing around with it now, this is what I am trying to do! V 

//+------------------------------------------------------------------+
//|Select Open Trade to work on                                      |
//+------------------------------------------------------------------+
void Manage_OpenTrade()
{

bool Time_Close;

int PositionIndex; 
int TotalNumberOfOrders;  
TotalNumberOfOrders  = OrdersTotal();

for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --) 
  {  
   if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue;
     if( OrderMagicNumber() == MagicNumber )   
      if ( OrderSymbol() == Symbol() )       
         {
         RefreshRates();
         
           if( OrderOpenTime() == iTime(NULL,Quant_TimeFrame, 2)  && OrderType()== OP_BUY )
           
            {
            RefreshRates();
            Time_Close = OrderClose(OrderTicket(),OrderLots(), Bid, 5, clrRed);
            if( Time_Close )Print("Buy position closed due to one hour limit");
            }
           
           if( OrderOpenTime() == iTime(NULL,Quant_TimeFrame, 2) && OrderType()== OP_SELL )
            {
            RefreshRates();
            Time_Close = OrderClose(OrderTicket(),OrderLots(), Ask, 5, clrRed);
            if( Time_Close )Print("Sell position closed due to one hour limit");
            }


         }
   }
}  

 I am wanting to close the open position BEFORE the NEXT immediate 1 hour bar opens (i.e. 1 second before it opens is the deadline). The trade will either hit it's profit target or close based upon a 1 hour limit from the time it OrderOpenTime().

 I know I am doing something wrong here. Are you able to shed some light?

 

Thanks!! 

 

UPDATE: THE ABOVE WORKS. 

 
if( OrderOpenTime() == ( iTime(NULL,Quant_TimeFrame, 2) - 1 ) && OrderType()== OP_BUY )
It is extremely unlikely that the OrderOpenTime will exactly equal the open time of a bar minus 1 second
 
Yea you're right! I realised that due to the fact that ticks come in intermittently, it's not a fair test in an "if" statement. Thanks for your comment!
Reason: