Download MetaTrader 5

MqlDateTime: Where is the mistake?

To add comments, please log in or register
Launch your trading signal and add account monitoring!
northquant
18
northquant 2011.09.20 16:42 

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
Jimmy
490
Jimmy 2011.09.21 05:01  
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?
Alexey Da
Moderator
6605
Alexey Da 2011.09.21 10:42  
Your code works fine. What's wrong? Where is mistake?
northquant
18
northquant 2011.09.21 14:30  

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);
     }


Jimmy
490
Jimmy 2011.09.21 14:58  
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
northquant
18
northquant 2011.09.22 10:32  
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...

To add comments, please log in or register