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

 
Valeriy Yastremskiy:

If there are 1440 orders a day, there should be a check at the start of the minute, or more simply at the appearance of the minute bar. And at this point to open. You don't have it, so the EA opens a position at every tick, which is a strict condition in itself, according to the condition on our symbol at the current quote. This condition may be not fulfilled, and the ticks will be missed. And at some point, a critical error will occur.

Also, the type of order execution (order to perform a trade to create a position) All or nothing.

I understand. Thanks for the help.

I also thought it was difficult for my EA to open so many orders. I tried to limit the number of orders with this code

MqlDateTime time_now;
TimeCurrent(time_now);
if(time_now.hour==10&&&&time_now.min==0)
{
//открыть ордер
}

That is, open an order only at 10:00. But the result is the same.

2020.10.27 10:25:17.548 Core 1 272 Mb memory used including 36 Mb of history data, 64 Mb of tick data


input int      StopLoss=30;      // Stop Loss
input int      TakeProfit=100;   // Take Profit
input double   Lot=0.1;          // Количество лотов для торговли
int A;    //

//+------------------------------------------------------------------+
void OnTick()
  {
//Print( "====================================================",  TimeCurrent() )   ;
//--- Объявляем структуры, которые будут использоваться для торговли
   MqlTick latest_price;       // Будет использоваться для текущих котировок
   MqlTradeRequest mrequest;   // Будет использоваться для отсылки торговых запросов
   MqlTradeResult mresult;     // Будет использоваться для получения результатов выполнения торговых запросов
   MqlDateTime time_now;     // Будет использоваться для
   
 TimeCurrent(time_now);  
 if(!SymbolInfoTick(_Symbol,latest_price))
 if(time_now.hour==10&&time_now.min==0)
   {
         mrequest.action = TRADE_ACTION_DEAL;                                  // немедленное исполнение
         mrequest.price = NormalizeDouble(latest_price.bid,_Digits);           // последняя цена Bid
         mrequest.sl = NormalizeDouble(latest_price.ask + StopLoss*_Point,_Digits); // Stop Loss
         mrequest.tp = NormalizeDouble(latest_price.ask - TakeProfit*_Point,_Digits); // Take Profit
         mrequest.symbol = _Symbol;                                            // символ
         mrequest.volume = Lot;                                                // количество лотов для торговли
         mrequest.type= ORDER_TYPE_SELL;                                       // ордер на продажу
         mrequest.type_filling = ORDER_FILLING_RETURN;                            // тип исполнения ордера - все или ничего
         mrequest.deviation=100;                                               // проскальзывание от текущей цены
         //--- отсылаем ордер
     OrderSend(mrequest,mresult);
    }   
     return;
  }

What am I doing wrong?

I colored the code I added and changed

This is what it says in the log file

FD 0 10:57:05.453 Core 1 agent process started on 127.0.0.1:3000

CS 0 10:57:05.453 Core 1 connecting to 127.0.0.1:3000

JD 0 10:57:05.953 Core 1 connected

OD 0 10:57:05.975 Core 1 authorized (agent build 2650)

JL 0 10:57:05.980 Tester EURUSD,M1 (Alpari-MT5-Demo): testing of experts\GRAAL.ex5 from 2020.09.01 00:00 to 2020.09.10 00:00

ON 0 10:57:05.997 Core 1 common synchronization completed

CJ 0 10:57:06.223 Tester quality of analyzed history is 100%

LM 0 10:57:06.248 Core 1 MetaTester 5 started on 127.0.0.1:3000

EJ 0 10:57:06.248 Core 1 initialization finished

LS 0 10:57:06.248 Core 1 login (build 2650)

KO 0 10:57:06.248 Core 1 4372 bytes of account info loaded

LI 0 10:57:06.248 Core 1 1482 bytes of tester parameters loaded

FN 0 10:57:06.248 Core 1 1724 bytes of input parameters loaded

OK 0 10:57:06.248 Core 1 423 bytes of symbols list loaded (72 symbols)

HO 0 10:57:06.248 Core 1 expert file added: Experts\GRAAL.ex5 13680 bytes loaded

CP 0 10:57:06.248 Core 1 4077 Mb available, 50 blocks set for ticks generating

DI 0 10:57:06.248 Core 1 calculate profit in pips, initial deposit 10000, leverage 1:100

LP 0 10:57:06.248 Core 1 successfully initialized

RI 0 10:57:06.248 Core 1 15 Kb of total initialization data received

DN 0 10:57:06.248 Core 1 Intel Core i5-6400 @ 2.70GHz, 7883 MB

IG 0 10:57:06.248 Core 1 EURUSD: symbol to be synchronized

RS 0 10:57:06.248 Core 1 EURUSD: symbol synchronized, 3720 bytes of symbol info received

OL 0 10:57:06.248 Core 1 EURUSD: load 27 bytes of history data to synchronize in 0:00:00.003

EK 0 10:57:06.248 Core 1 EURUSD: history synchronized from 2019.01.02 to 2020.10.23

LK 0 10:57:06.248 Core 1 EURUSD,M1: history cache allocated for 628432 bars and contains 619175 bars from 2019.01.02 06:00 to 2020.08.31 23:59

LH 0 10:57:06.248 Core 1 EURUSD,M1: history begins from 2019.01.02 06:00

LN 0 10:57:06.248 Core 1 EURUSD,M1 (Alpari-MT5-Demo): OHLC bar states generating. OnTick execution on the bar begin only

JM 0 10:57:06.248 Core 1 EURUSD,M1: testing of experts\GRAAL.ex5 from 2020.09.01 00:00 to 2020.09.10 00:00 started with inputs:

LS 0 10:57:06.248 Core 1 StopLoss=30

PL 0 10:57:06.248 Core 1 TakeProfit=100

FJ 0 10:57:06.248 Core 1 Lot=0.1

DP 0 10:57:06.248 Core 1 final balance 10000.00 pips

EE 0 10:57:06.248 Core 1 EURUSD,M1: 39553 ticks, 10068 bars generated. Environment synchronized at 0:00:00.031. Test passed in 0:00:00.247 (including ticks preprocessing 0:00:00.016).

DE 0 10:57:06.248 Core 1 EURUSD,M1: total time from login to stop testing 0:00:00.278 (including 0:00:00.031 for history data synchronization)

NQ 0 10:57:06.248 Core 1 272 Mb memory used including 36 Mb of history data, 64 Mb of tick data

KE 0 10:57:06.248 Core 1 log file "C:\Users\a1960\AppData\Roaming\MetaQuotes\Tester\36A64B8C79A6163D85E6173B54096685\Agent-127.0.0.1-3000\logs\20201027.log" written

OS 0 10:57:06.260 Core 1 connection closed


 
Denis Diakonov:

Please advise!

Why isn't the server time updated when new ticks come in?

At the moment when EA starts, everything works as it should, but then the time goes, but new value of the current minute does not come into the variable.

I.e., the Expert Advisor works depending on the number obtained in the variable int M = TimeMinute(TimeCurrent());

Actually this code line is from the reference and it doesn't work.

For example, I start it at 12-the current time returned by the server corresponds to the time in the variable, but then the variable remains at 12, although it is already 15-20 minutes on the clock

The code is completely better, more precisely where you create the function and in which function (OnInit, OnTick, OnTime) get the value of minutes and call the print function. If in OnInit or outside the terminal function fields, that's how it should be. If in OnTick, it will print on every tick and update the value with a new minute.

 

Clear example of server time and variable value

Valeriy Yastremskiy:

The code is completely better, or rather where you create the function and in which function (OnInit, OnTick, OnTime) you get the value of minutes and call the print function. If in OnInit or outside the terminal function fields, that's how it should be. If in OnTick, it will print on every tick and update the value with a new minute.

int M = TimeMinute(TimeCurrent());
bool TimeServer()                                                  
{  
   Print(M, " - Tекущее время сервера");
   if((M > 55 || M == 55) && (M < 59 || M == 59))
   {
   return(true);
   }
   else
   {
   return(false);
   }
}

Well, here is the full code. In the void OnTick() function it is triggered at the very beginning by the first line to be executed.

It is triggered only at the moment of recompiling or appending to the schedule/deletion field/. For the rest of the time, the variable M holds the value of the minute obtained during the first run of the EA.

 
Denis Diakonov:

Well the code here is all there is to it. The void OnTick() is triggered at the very beginning by the first line to be executed.

It is triggered only at the moment of recompilation or joining to the graph/deletion field/ . For the rest of the time, the variable M holds the value of the minute obtained during the first run of the EA.

//--------------------------------------------------------------------
//
//--------------------------------------------------------------------
int m1,m2;
void OnTick() // Спец. функция start
  {
 // int M = TimeMinute(TimeCurrent());
//if(m1!=M)
 TimeServer();
//--------------------------------------------------------------------
  m1=m2;
   return;                            // Выход из start()
  }
//--------------------------------------------------------------------
bool TimeServer()                                                  
{  
int M = TimeMinute(TimeCurrent());
m2=M;
if(m1!=M)
   Alert (M, " - Tекущее время сервера");
   Print(M, " - Tекущее время сервера");
    if((M >= 55) && (M <= 59))
   {
   return(true);
   }
   else
   {
   return(false);
   }
}
 
Valeriy Yastremskiy:

Got it, thanks!

I should have

int M = TimeMinute(TimeCurrent());

put it in the body of the function, not in front of it by assigning the value M

 
Denis Diakonov:

Got it, thanks!

I should have

put it in the body of the function, instead of assigning the M value before it.

You can do it in different ways. Read global and local variables and their visibility.

 

Afternoon. Trying to get the angle of the trendline from the angle. Here is the code:

void DrawLine(string name,
              datetime time1,
              double price1,
              datetime time2,
              double price2,
              double &angle)
  {
   CChartObjectTrendByAngle *line=new CChartObjectTrendByAngle();
   if(!line.Create(ChartID(),name,0,time1,price1,time2,price2))
     {
      Print(__FUNCTION__+": object line create failed. Last error: ",GetLastError());
      delete line;
      return;
     }
   
   line.Color(InpColorZoneUp);
   line.Background(false);
   line.RayLeft(false);
   line.RayRight(false);
   angle=line.Angle();
   
   /*ObjectCreate(name,OBJ_TRENDBYANGLE,0,time1,price1,time2,price2);
   double W = ObjectGet(name,OBJPROP_ANGLE);
   angle=W;*/
   lines.Add(line);
  }

angle is always 0. Regardless of whether to use standard library methods or built-in functions. At the same time, the line is drawn. What is wrong? How to get the angle?

 
leonerd:

Afternoon. Trying to get the angle of the trendline from the angle. Here is the code:

angle is always 0. Regardless of whether to use standard library methods or built-in functions. At the same time, the line is drawn. What is wrong? How do I get the angle?

https://www.mql5.com/ru/forum/103591

I see, but how do you calculate the angle?

Вопрос: TRENDBYANGLE, а где ANGLE?
Вопрос: TRENDBYANGLE, а где ANGLE?
  • 2007.06.07
  • www.mql5.com
Добрый день...
 
leonerd:

https://www.mql5.com/ru/forum/103591

I see, but how do you calculate the angle?

You're a comedian.

Who am I kidding?

Forum on trading, automated trading systems and strategy testing

Any questions from newbies on MQL4 and MQL5, any help and discussion of algorithms and codes

Nikolai Semko, 2020.10.26 00:34

You should not be afraid of speed. It's just a conditionality for type conversion.
As a variant of the angle definition function:

struct PointPriceTime
  {
   double            price;
   datetime          time;
                     PointPriceTime(double p, datetime t) { price=p; time=t; };
   void              Set(double p, datetime t){ price=p; time=t;};
                     PointPriceTime(PointPriceTime &p){ price=p.price; time=p.time; };
                     PointPriceTime() { price=0.0; time=0; };
  };

double Angle(PointPriceTime &p1,PointPriceTime &p2) // возвращает угол в градусах в приведенной системе координат price-price, где по оси X 
  {                                                 // расстояние между x1 и  x2  = N*_Point, где N - количество минутных баров во временном промежутке отрезка. 
   static int tf[9]= {PERIOD_M1,PERIOD_M5,PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1,PERIOD_W1,PERIOD_MN1};
   int i=0;
   while(i<9 && SeriesInfoInteger(_Symbol,tf[i],SERIES_FIRSTDATE)>p1.time)
      i++;
   if(i==9)
     {
      Print("Время левой границы вне диапазона исторических данных");
      return DBL_MAX;
     }
   int bar1 = iBarShift(_Symbol,tf[i],p1.time);
   int bar2 = iBarShift(_Symbol,tf[i],p2.time);
   if(bar1==bar2)
      return 0.0;
   return atan((p2.price-p1.price)/((bar1-bar2)*PeriodSeconds(tf[i])*_Point/60))*180/M_PI;
  }

After MT5 the feeling of MT4 is just awful. The access to the history is somehow emasculated. I am not even speaking about the ticks.




 

Can you please tell me if this font selection is possible in the indicator?


Reason: