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

 

Greetings. MQL4. I want to add a snake game to my EA.

Can you please advise if it is possible to set the number of seconds which determines periodicity of OnTimer() events to be less than 1, for example 0.7?

Or in other ways to implement periodic execution of part of code, but so that it doesn't delay execution in OnTick() ?

 
Andrey Sokolov:

Greetings. MQL4. I want to add a snake game to my EA.

Can you please advise if it is possible to set the number of seconds which determines periodicity of OnTimer() events to be less than 1, for example 0.7?

Or in other ways to implement periodic execution of part of code, but so that it does not delay execution in OnTick() ?

https://docs.mql4.com/ru/eventfunctions/eventsetmillisecondtimer
EventSetMillisecondTimer - Работа с событиями - Справочник MQL4
EventSetMillisecondTimer - Работа с событиями - Справочник MQL4
  • docs.mql4.com
Указывает клиентскому терминалу, что для данного эксперта или индикатора необходимо генерировать события таймера с периодичностью менее одной секунды. нужно получать события таймера чаще, чем один раз в секунду. Если вам достаточно обычного таймера с периодом в несколько секунд, то используйте EventSetTimer(). Обычно эта функция должна...
 
Alexey Viktorov thank you
 

The code below outputs 牖漠摲牥⁳湩潦〉〮र〲थ⸰〰㠉┰〉〮र

It's supposed to output the text test

The files are in the Files\\\Test\\ folder.

Function says that handle is correct it's 1 and immediately GetLastError says error 5008 Wrong handle ....

What should I do?

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   core();
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

  }
//+------------------------------------------------------------------+
void core()
  {
   string value = "", name = "";

   name =  "Test" + "\\test.csv";
   Print(FileIsExist(name));

   ResetLastError();

   int m_hendle = -1;
   m_hendle = FileOpen(name, FILE_READ | FILE_WRITE | FILE_CSV);
   if(m_hendle != INVALID_HANDLE)
     {
      Print((string)m_hendle + "    " + name + " [" + (string)FileSize(m_hendle) + "]"+ (string)GetLastError());
       while(!FileIsEnding(m_hendle))
        {
         string sCurrent = FileReadString(m_hendle);
         Print("sCurrent = ", sCurrent);
        }
      FileClose(m_hendle);
     }
  }
//+------------------------------------------------------------------+
 
Vladimir Pastushak:

The code below outputs 牖漠摲牥⁳湩潦〉〮र〲थ⸰〰㠉┰〉〮र

Looks like "coronavirus"

 

Hello....help me convert an mt5 advisor to 4 please. I have no desire or need to learn myself, if it's complicated, I'll understand and forget it, I don't need much...

I already asked, but my feedback was about how to learn, or I asked for settings and " grail expert". While reading the forums, it seemed that people will help ... what's interesting, if people are asking to do something not expensive, for money ... help for free, and when I'm just asking for money, they probably think someone who wants to use strangers hands and ask for free ... had the money here and now, would have paid immediately and not bother, but they do not, and when you do will not need ... easier to score, but still ... hope dies last.


I can pay later, when I have it...

Files:
Lift.mq5  9 kb
 
eKpuBu4:

Hello....help me convert an mt5 advisor to 4 please. I do not want or need to learn it myself, if it is complicated, I will understand and forget it, I do not need much...

Where is the rest?

Expert.mqh>

SignalTRIX.mqh>


SignalStoch.mqh>

TrailingFixedPips.mqh>

MoneyFixedRisk.mqh>

 
Hello. I do not have a great knowledge of mql4 programming.
input double   Lots=0.01;     //Lots size
input int      Tprof=1000;     //TakeProfit
input int      TreilSt=100;    //Trailing Stop
input int      TrStKor=10;     //The size of the correction Trailing Stop
input int      Magik=1001012;  //Magic Number
extern int Bars_left = 5;
extern int Bars_right = 5;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   static double Upf,Lowf;
   double Tupf=0,Tlowf=0;
   int i,k;
   for(i=2; i<100; i++)
     {
      Tupf=iCustom(Symbol(),0,"takbir",Bars_left,Bars_right,0,i);
      if(Tupf>0)
         break;
     }
   for(k=2; k<100; k++)
     {
      Tlowf=iCustom(Symbol(),0,"takbir",Bars_left,Bars_right,1,k);
      if(Tlowf>0)
         break;
     }
//----Open position
//if(i>0) Print("i = ", i, " k = ",k);
   int total=OrdersTotal();
/*if(total<1)
      {*/
    
   if(Ask>Tupf+15*_Point && Tupf!=Upf)
     {
      double StL=NormalizeDouble(Tlowf,_Digits);
      int ticket=OrderSend(NULL,OP_BUY,Lots,Ask,30,StL,Bid+Tprof*_Point,NULL,Magik,0,clrBlue);
      if(ticket<0)
        {
         Print("OrderSend error #",GetLastError());
        }
      else {Print("Ask=",Ask,"Upf=",Upf," StL=",StL); Upf=Tupf;}
     }
   if(Bid<Tlowf-15*_Point && Tlowf!=Lowf)
     {
      double StL=NormalizeDouble(Tupf,_Digits);
      int ticket=OrderSend(NULL,OP_SELL,Lots,Bid,30,StL,Ask-Tprof*_Point,NULL,Magik,0,clrRed);
      if(ticket<0)
        {
         Print("OrderSend error #",GetLastError());
        }
      else {Print("Bid=",Bid,"Lowf=",Lowf," StL=",StL);   Lowf=Tlowf;}
     }
// }
//----Trailing Stop operation
   for(int cni=0;cni<total;cni++)
     {
      if(!OrderSelect(cni,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderMagicNumber()==Magik && TreilSt>0)
        {
         if(OrderType()==OP_BUY)
           {
            if(Bid-OrderOpenPrice()>_Point*TreilSt)
              {
               if(OrderStopLoss()<Bid-_Point*TreilSt-TrStKor*_Point)
                 {
                  //--- modify order and exit
                  if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-_Point*TreilSt,OrderTakeProfit(),0,clrBlue))
                     Print("OrderModify error ",GetLastError());
                  return;
                 }
              }
           }
         if(OrderType()==OP_SELL)
           {
            if((OrderOpenPrice()-Ask)>_Point*TreilSt)
              {
               if(OrderStopLoss()>Ask+_Point*TreilSt+_Point*TrStKor)
                 {
                  //--- modify order and exit
                  if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TreilSt,OrderTakeProfit(),0,clrRed))
                     Print("OrderModify error ",GetLastError());
                  return;
                 }
              }
           }
        }
     }
  }

But I can't figure out how to fix the following:

double StL=NormalizeDouble(Tupf,_Digits);

Stop loss is set at the previous "top fractal"

It should be:

If the last lower fractal is broken - stop loss is set atthe maximum price between the lower fractal and the breakdown

If the last upper fractal is broken through - stop loss is set at the minimum price between the upper fractal and the breakout

I try to set the time of fractal formation using itime and define the index, but I do not know how to reach the current time and search from the current time to the fractal, going through the bars every time, until the order is opened.

Maybe we should look for it during the order opening? And through the modification of the order to change the stop and ndp, but how, I can not understand.

I do not know how to do this. Dear Professionals, can you spare 5 minutes of your time?

Документация по MQL5: Константы, перечисления и структуры / Константы индикаторов / Ценовые константы
Документация по MQL5: Константы, перечисления и структуры / Константы индикаторов / Ценовые константы
  • www.mql5.com
Технические индикаторы требуют для своих расчетов указания значений цен и/или значений объемов, на которых они будут считаться. Существуют 7 предопределенных идентификаторов перечисления ENUM_APPLIED_PRICE, для указания нужной ценовой базы расчетов. Если технический индикатор для своих расчетов использует ценовые данные, тип которых задается...
 
v0van1990:
Please help. Respected pros, take five minutes of your time.

You need to fix it here

     {
      Tupf=iCustom(Symbol(),0,"takbir",Bars_left,Bars_right,0,i);
      if(Tupf>0)
         break;
     }
 
MakarFX:

You need to correct here.

This function gives me information about non-standard last formed fractals, and I change those non-standard fractals at the beginning of the EA.

Or, should I add another function to the indicator - information about high or low before the last fractal is penetrated or when a new fractal is formed?

Do I understand it correctly?