Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1832

 

Good afternoon!!!

Can you please tell me if the Hour() function returns the current hour of the last known server time in Greenwich or the current time called on the computer???

 
EVGENII SHELIPOV the current time called on the computer???


 
Tretyakov Rostyslav #:


What is the answer to the question ?

 
EVGENII SHELIPOV #:

What's the answer to the question?

I'm sorry. I thought you could read.


 
EVGENII SHELIPOV current time called on computer???

And who told you that server time must be GMT?

 

Function for mt4 and mt5 - start, stop and .....

//+------------------------------------------------------------------+
//|                                                   time Start.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//--- input parameters
input datetime InpHoursFrom = D'1970.01.01 02:00'; // Start (Only time)
input datetime InpHoursTo   = D'1970.01.01 23:00'; // Stop (Only time)
input bool     InpClose     = true;                // Close Time
input datetime InpHoursTo1  = D'1970.01.01 23:00'; // Close (Only time)
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(TimeStartStop(InpHoursFrom,InpHoursTo))
     {
      Print("Start time :",InpHoursFrom," || ","Stop time :",InpHoursTo);
     }
   if(TimeClose(InpHoursTo1))
     {
      if(InpClose)
         Print("close_time :",InpHoursTo1);
     }
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
bool TimeStartStop(datetime HoursFrom,datetime HoursTo)
  {
//---
   MqlDateTime currTime;
   TimeToStruct(TimeLocal(),currTime);
   long hour0=currTime.hour*60*60+currTime.min*60+currTime.sec;
   if((HoursFrom<HoursTo && hour0>=HoursFrom && hour0<HoursTo) ||
      (HoursFrom>HoursTo && (hour0<HoursTo || hour0>=HoursFrom)))
      return(true);
   return(false);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
bool TimeClose(datetime HoursTo)
  {
//---
   MqlDateTime currTime;
   TimeToStruct(TimeLocal(),currTime);
   long hour0=currTime.hour*60*60+currTime.min*60+currTime.sec;
   if(hour0<HoursTo)
      return(false);
   if(hour0>HoursTo+1*10)
      return(false);
   return(true);
  }
//+------------------------------------------------------------------+
 

Guys, I need pending orders to update their value every minute, modification of something was crooked, decided to delete and set every minute in both directions, in the tester works fine, but in real life, somehow does not deliver. Correct or help instead of deletion, modification to do.


      if(TimeCurrent()>TimeCheck_sn && TimeCurrent()<TimeCheck_en && Ogranichitel > 0)
        {

         if(IsNewCandle())
           {

            if(OrderOfSymbol>0 && OrderType() ==  OP_BUYSTOP)
               ticket2 =  OrderDelete(OrderTicket(),Violet);

            if(OrderOfSymbol>0 && OrderType() ==  OP_SELLSTOP)
               ticket2 =  OrderDelete(OrderTicket(),Violet);


            if(Close[1]>Open[1] && CountOrders()==0)
               if(NewsSellAllow == true)
                  ticket2 = OrderSend(Symbol(),OP_SELLSTOP, LotSk, Bid-(Skachok*Point), Slippage, 0, Bid-((Skachok+TPsk)*Point), "открыт ордер на продажу", Magic, 0, Red);
                  Print("OpenOrderSuccess");
                  
            if(Close[1]>Open[1] && CountOrders()==0)
               if(NewsBuyAllow == true)
                  ticket2 = OrderSend(Symbol(),OP_BUYSTOP, LotSk, Ask+(Skachok*Point), Slippage, 0, Ask+((Skachok+TPsk)*Point), "открыт ордер на покупку", Magic, 0, Blue);
                  Print("OpenOrderSuccess");


            if(OrderType() ==  OP_BUYSTOP && OrderOfSymbol>0)
               ticket2 = OrderModify(OrderTicket(), (Ask+(Skachok*Point)), 0, (Ask+((Skachok+TPsk)*Point)), 0);

            if(OrderType() ==  OP_SELLSTOP && OrderOfSymbol>0)
               ticket2 = OrderModify(OrderTicket()+1, (Bid-(Skachok*Point)), 0, (Bid-((Skachok+TPsk)*Point)), 0);
           }
        }


      if(TimeCurrent() == TimeCheck_en)
        {


         if(IsNewCandle())
           {
            if(OrderOfSymbol>0 && OrderType() ==  OP_BUYSTOP)
               ticket2 =  OrderDelete(OrderTicket(),Violet);

            if(OrderOfSymbol>0 && OrderType() ==  OP_SELLSTOP)
               ticket2 =  OrderDelete(OrderTicket(),Violet);
           }


        }
 
Порт-моне тв pending orders to update their value every minute, modification of something was crooked, decided to delete and set every minute in both directions, in the tester works fine, but in real life, somehow does not deliver. Correct or help instead of deletion, modification to do.


Better get back to the modification, explain what is needed
 
Tretyakov Rostyslav #:
Better go back to the modification, explain what is needed

The order should be modified each time on a new candlestick in both directions with a set indent in points and on takeprofit (like a classic), if it penetrates (a breakthrough on news), then the order opens (the second order can be closed automatically), but until it opens, then modify again and again; and all this within a given time frame specified in the parameters of the advisor.

 
Порт-моне тв #:

The order should be modified each time on a new candlestick in both directions with a specified indent in points and on takeprofit (like a classic), if it penetrates (a breakthrough on news), then the order opens (the second order can be closed automatically), but until it opens, then modify again and again; and all this within a given time frame specified in the EA's parameters.

And how are the first orders placed?