MqlDateTime: Where is the mistake?

 

Hi all,

ich wrote the following code, but i don't work somehow. I check if a position in the current symbol exists. Then i would like to have the "day of the year" for the recent moment (for ab) and the "day of the year" when the position has been opened (for ba). The difference of this two data points should be saved in "delta". Could anyone help me with this? THX

 if (PositionSelect(Symbol()))
   { 
   long  delta;
   long  ab;
   long  ba;  
   datetime date1=TimeCurrent();
   datetime date2=PositionGetInteger(POSITION_TIME);
   MqlDateTime str1,str2;
   TimeToStruct(date1,str1);
   TimeToStruct(date2,str2);
   ab=str1.day_of_year;
   ba=str2.day_of_year;
   delta=ab-ba;
   }

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Position Properties - Documentation on MQL5
 
northquant:

Hi all,

ich wrote the following code, but i don't work somehow. I check if a position in the current symbol exists. Then i would like to have the "day of the year" for the recent moment (for ab) and the "day of the year" when the position has been opened (for ba). The difference of this two data points should be saved in "delta". Could anyone help me with this? THX


The code seems ok. How did you check it?
 
Your code works fine. What's wrong? Where is mistake?
 

Well, then number from "delta" i use to generate exit orders. But the exit order with the following code don't execute in the strategy tester...


   if(delta>0)
     {
      trReq.price=tick.bid;
      trReq.type=ORDER_TYPE_SELL;
      OrderSend(trReq,trRes);
     }

 
northquant:

Well, then number from "delta" i use to generate exit orders. But the exit order with the following code don't execute in the strategy tester...


   if(delta>0)
     {
      trReq.price=tick.bid;
      trReq.type=ORDER_TYPE_SELL;
      OrderSend(trReq,trRes);
     }


Is the open position a POSITION_TYPE_BUY?

An BUY position is closed by a SELL order and vice versa.

Are all required fields in trReq have been set?

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Position Properties - Documentation on MQL5
 
fireflies:

Is the open position a POSITION_TYPE_BUY?

An BUY position is closed by a SELL order and vice versa.

Are all required fields in trReq have been set?

Yes, the open position is a buy order und all fields in trReq are from my point of view allright...