Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1050

 

How do I add minutes to the advisor's block of hours?

//input parametrs
input uchar                InpStartHour            = 1;           // Start hour
input uchar                InpEndHour              = 23;           // End hour

//---------------------------

void OnTick()
  { 
   MqlDateTime STimeCurrent;
   TimeToStruct(TimeCurrent(),STimeCurrent);
  
   if(STimeCurrent.hour<InpStartHour || STimeCurrent.hour>InpEndHour)
      return;
   }

 
Vladimir Baskakov:

How do I add minutes to the hourly block of an EA?

High Low Strategy On Time 2:

The bool TimeControl() is a function responsible for checking the time. It can work in two states: both dates within a day or dates over a day.

//--- input parameters
***
input bool     InpTimeControl       = true;        // Use time control
input uchar    InpStartHour         = 10;          // Start Hour 
input uchar    InpStartMinute       = 01;          // Start Minute 
input uchar    InpEndHour           = 15;          // End Hour 
input uchar    InpEndMinute         = 02;          // End Minute 
***
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(!TimeControl())
      return;
  }
//+------------------------------------------------------------------+
//| TimeControl                                                      |
//+------------------------------------------------------------------+
bool TimeControl(void)
  {
   if(!InpTimeControl)
      return(true);
   MqlDateTime STimeCurrent;
   datetime time_current=TimeCurrent();
   if(time_current==D'1970.01.01 00:00')
      return(false);
   TimeToStruct(time_current,STimeCurrent);
   if((InpStartHour*60*60+InpStartMinute*60)<(InpEndHour*60*60+InpEndMinute*60)) // intraday time interval
     {
/*
Example:
input uchar    InpStartHour      = 5;        // Start hour
input uchar    InpEndHour        = 10;       // End hour
0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20 21 22 23 0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15
_  _  _  _  _  +  +  +  +  +  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  _  +  +  +  +  +  _  _  _  _  _  _
*/
      if((STimeCurrent.hour*60*60+STimeCurrent.min*60>=InpStartHour*60*60+InpStartMinute*60) && 
         (STimeCurrent.hour*60*60+STimeCurrent.min*60<InpEndHour*60*60+InpEndMinute*60))
         return(true);
     }
   else if((InpStartHour*60*60+InpStartMinute*60)>(InpEndHour*60*60+InpEndMinute*60)) // time interval with the transition in a day
     {
/*
Example:
input uchar    InpStartHour      = 10;       // Start hour
input uchar    InpEndHour        = 5;        // End hour
0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20 21 22 23 0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15
_  _  _  _  _  _  _  _  _  _  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  _  _  _  _  _  +  +  +  +  +  +
*/
      if(STimeCurrent.hour*60*60+STimeCurrent.min*60>=InpStartHour*60*60+InpStartMinute*60 || 
         STimeCurrent.hour*60*60+STimeCurrent.min*60<InpEndHour*60*60+InpEndMinute*60)
         return(true);
     }
   else
      return(false);
//---
   return(false);
  }
 

Please advise,

In MQL5 I need to close half of a position, but I need to check if half of the position is less than the minimum lot and then close the whole volume, is that correct?

double volume=MathMax(PositionGetDouble(POSITION_VOLUME)/2,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN)/AccountInfoInteger(ACCOUNT_LEVERAGE));
 
Evgeny Dyuka:

Please advise,

In MQL5 I need to close half of a position, but I need to check if half of the position is less than the minimum lot, then close the whole volume, is that correct?

Maybe it is easier to check before dividing, if the lot is less than 2x the minimum, then there is no need to bother the terminal?

 

I can't pass the test for the marketplace, it returns an error, but there is no error in the report

What to do?


 
Evgeny Dyuka:

can't pass the test for the marketplace, it returns an error, but there is no error in the report

What to do?


Please try again later.
 

How do I get the closing price of an order (trade, position - anything at all)?

For orders, only ORDER_PRICE_OPEN is available, but ORDER_PRICE_CLOSE is not.

The positions have only POSITION_PRICE_OPEN.

The trades don't have anything abstract at all: DEAL_PRICE.

Googled the forum, didn't find it.

 
secret:

How do I get the closing price of an order (trade, position - anything at all)?

For orders, only ORDER_PRICE_OPEN is available, but ORDER_PRICE_CLOSE is not.

The positions have only POSITION_PRICE_OPEN.

The trades don't have anything abstract at all: DEAL_PRICE.

I searched through the forum, didn't find it.

To make understanding and working in MQL5 easier:

1. ***

2. If you need a closing price, you cannot do without accessing the trading history. TheHistorySelect is responsible for requesting the trading history

3. The example of working with the history, with output of information either in a file or in the "Experts" tab, is in theHistory Deals and Orders code

To understand what deal this is, you need to know

ENUM_DEAL_ENTRY-direction of the deal - entry into the market, exit from the market or reversal

ENUM_DEAL_ENTRY

Identifier

Description

DEAL_ENTRY_IN

Entry into market

DEAL_ENTRY_OUT

Market exit

DEAL_ENTRY_INOUT

U-turn

DEAL_ENTRY_OUT_BY

Close counter position


ENUM_DEAL_TYPE-Type of deal

ENUM_DEAL_TYPE

Identifier

Description

DEAL_TYPE_BUY

Buy

DEAL_TYPE_SELLSell

***



These are the basics.

 
Vladimir Karputov:

Thanks for the reply, I've looked at both the documentation and your example, but still haven't found how to get a parameter similar to OrderClosePrice() in MT4.

 
secret:

Thanks for the reply, I looked at both the documentation and your example but still couldn't find how to get a parameter similar to OrderClosePrice() in MT4.

alternatively openhttps://www.mql5.com/ru/code/16006

and look at@fxsaber's implementation

or just connect the above library and transfer the code from MT4 to MT5, in 99% of cases you won't have to tweak anything, everything will work the same as in MT4

MT4Orders
MT4Orders
  • www.mql5.com
Данная библиотека позволяет работать с ордерами в MQL5 (MT5-hedge) точно так же, как в MQL4. Т.е. ордерная языковая система (ОЯС) становится идентичной MQL4. При этом сохраняется возможность параллельно использовать MQL5-ордерную систему. В частности, стандартная MQL5-библиотека будет продолжать полноценно работать. Выбор между ордерными...
Reason: