MetaTrader 5 herunterladen

MQL5 Timestamp

Einloggen oder registrieren, um einen Kommentar zu schreiben
amando
467
amando  

Hello,

 

i want to try take all my orders out at a specific time on the day, for this i used normaly this code till now 

 

int OnInit()

  {// in welcher Häufigkeit (Sekunden) das Event vorkommen soll



   EventSetTimer(60);



   return(0);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {//--- destroy timer

   EventKillTimer();

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void OnTimer()

  {

//---



   if(Hour()>=End && Minute()==Ende_Minute)

     {



      Print("TAGESENDE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");



      if(PositionSelect(_Symbol)==true)

        {



         if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)

           {

            Print("OPEN BUY ORDER");

            OrderAsync(_Symbol,ORDER_TYPE_SELL,PositionGetDouble(POSITION_VOLUME),PositionGetString(POSITION_COMMENT),PositionGetInteger(POSITION_MAGIC));

           }



         if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)

           {

            Print("OPEN SELL ORDER");

            OrderAsync(_Symbol,ORDER_TYPE_BUY,PositionGetDouble(POSITION_VOLUME),PositionGetString(POSITION_COMMENT),PositionGetInteger(POSITION_MAGIC));

           }

        }



      // Pending Orders löschen.

      int ord_total=OrdersTotal();

      if(ord_total>0)

        {

         for(int i=ord_total-1;i>=0;i--)

           {

            ulong ticket=OrderGetTicket(i);

            if(OrderSelect(ticket) && OrderGetString(ORDER_SYMBOL)==Symbol() && OrderGetString(ORDER_COMMENT)==Text)

              {



               OrderDelete(ticket);



              }

           }

        }

      } 

     }  

 

 for explanation, the Hour and minutes will be generated by this code

int Hour()
  {
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.hour);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int DayOfWeek()
  {
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.day_of_week);
  }
//+------------------------------------------------------------------+
int TimeDayOfWeek(datetime date)
  {
   MqlDateTime tm;
   TimeToStruct(date,tm);
   return(tm.day_of_week);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int Minute()
  {
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.min);
  }

 

now, in the backtest area, the EA will start at this time, but it ignors, that it should be only run in once

is there a mistake?

 

thanks for help

amando 

 

 

Carl Schreiber
Moderator
7943
Carl Schreiber  

1.) Sprich doch deutsch hier?

2.) Kriegst Du keinen Compilefehler hier:

TimeCurrent(tm);

Du meinst wahrscheinlich

datetime tm = TimeCurrent();

3.) Ich würde nie schreiben:

Minute()==Ende_Minute

was wenn länger als eine Minute kein Tick kommt?

Mach lieber so etwas wie:

datetime myEoD = StringToTime("22:58");

(So weit ich mich erinnere wird das dann zu einer Zeit des aktuellen Tages - aber probiers besser mal aus.)

Christian
2056
Christian  

Carl hat schon beschrieben wie es sinnvoller geht , aber falls du es noch nicht gefunden hast hier ein Artikel über Zeit.

https://www.mql5.com/en/articles/599 

 

 

Um die Lokale PC Zeit zu gewinnen nutze :

datetime TimeOfMyPc=TimeLocal();

 

Gruß Christian 

MQL5 Programming Basics: Time
MQL5 Programming Basics: Time
  • 2013.04.26
  • Dmitry Fedoseev
  • www.mql5.com
The article focuses on standard MQL5 functions for working with time, as well as programming techniques and practically useful functions for working with time that are required when creating Expert Advisors and indicators. Particular attention is paid to the general theory of time measurement. This article should be of interest primarily to novice MQL5 programmers.
Einloggen oder registrieren, um einen Kommentar zu schreiben