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

 
Андрей #:

Good night!

Dear forum users, I need some help. I wrote a script in MQL4 that draws a line by a formula from three given points on a chart. It takes 130 lines, including indents and spaces. I have recently decided to port it to MQL5 and realized that my poor knowledge of programming will not help me as I need to learn again.

There is an error in the zero divide code, fix it first

a1=(y3-(x3*(y2-y1)+x2*y1-x1*y2)/(x2-x1))/(x3*(x3-x1-x2)+x1*x2);

Here division by "0" because x1 and x2 equals "1", which results in "0".

Do a check before the matrix operation

 
Manter84 #:

You're a joker. But the problem is real, and there are topics about that the command Print prints twice in the tab Experts and Allert also comes twice, only there is no answer alas how to fix it. And for the future, if you do not know, you can just keep silent and pass by, but to gain rating themselves unprofessional answers is stupid. Yes, by the way, your answers are really very weak.

Whatever the question, whatever the answer.
 
Андрей #:

Good night!

Dear forum users, I need some help. I wrote a script in MQL4 that draws a line by a formula from three given points on a chart. It takes 130 lines, including indents and spaces. I have recently decided to port it to MQL5 and realized that my poor knowledge in programming will not help me, I need to study again.

I will be grateful if someone is ready to port the script to MQL5. I would be very thankful if somebody would like to convert the script to MQL5.

If you wrote the script, why do you need it in your code?

 //+------------------------------------------------------------------+
 //| Custom indicator initialization function                         |
 //+------------------------------------------------------------------+
 int init()
   {SetIndexBuffer(0,Buffer1);
   SetIndexStyle(0,DRAW_LINE);
 //---- indicators
 //----
    return(0);
   }
 
#property indicator_chart_window
int            FR_handle;
int OnInit()
  {

    FR_handle = iFractals(NULL,PERIOD_CURRENT);
   return(INIT_SUCCEEDED);

  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
    Print("Проверка 111 "); 
    return(rates_total);
  }
Alexey Viktorov #
:
As the question is, so is the answer.

Well, you could have just written that more details are needed. I wrote the code of the simplest indicator (it couldn't be simpler), but it generates two messages at the Print command too. And if you omit getting Handle, it gives one message.

***

Files:
111.png  15 kb
 
Alexey Viktorov #:

If you wrote the script, why in the code is it

Since my programming skills are at the level of a schoolboy, I took some working piece of code and made rules from it. What did not interfere, did not touch)
 
Manter84 #:

Well, you could have just written that more details are needed. I wrote the code of the simplest indicator (it couldn't be simpler), but it generates two messages at the Print command too. And if you don't get Handle, you get one.

Oh, dear... I've got only foul words in my vocabulary. That's why I'd better keep silent.

 
Андрей #:
Since my programming skills are on the level of a schoolboy, I took some working piece of code and rules from it. What did not interfere, did not touch)

Got it.

Andrew #:
If anyone helps, I owe you a whisky anyway!)

I think whisky from ......... is not cheaper than $30. Therefore, it's easier to create an application on a freelance site and there will be willing, about 20 people... And this is your message you provoke people to break the rules. Who needs it? Well, do it for free, and then what? After all, a bottle you have not passed, so it's a job for the money bypassing freelancing.

 
Андрей #:

#property strict
//+------------------------------------------------------------------+
#property indicator_chart_window
 #property indicator_buffers 1
 #property  indicator_color1 clrBlue
 #property  indicator_width1 2
 #property  indicator_style1 0
 
#property indicator_label1  "3T" 
#property indicator_type1   DRAW_LINE 

#property indicator_style1  STYLE_SOLID 


#define Point _Point
#define Period()  _Period
#define Symbol  _Symbol
#define  TimeToStr TimeToStruct



// Позволяет, как в MT4, работать с таймсериями: Open[Pos], High[Pos], Low[Pos], Close[Pos], Time[Pos], Volume[Pos].
// А так же задает привычные MT4-функции: iOpen, iHigh, iLow, iClose, iTime, iVolume.


#define  DEFINE_TIMESERIE(NAME,FUNC,T)                                                                         \
  class CLASS##NAME                                                                                           \
  {                                                                                                           \
  public:                                                                                                     \
    static T Get(const string Symb,const int TimeFrame,const int iShift) \
    {                                                                                                         \
      T tValue[];                                                                                             \
      return((Copy##FUNC((Symb == NULL) ? _Symbol : Symb, _Period, iShift, 1, tValue) > 0) ? tValue[0] : -1); \
    }                                                                                                         \
    T operator[](const int iPos) const                                                                     \
    {                                                                                                         \
      return(CLASS##NAME::Get(_Symbol, _Period, iPos));                                                       \
    }                                                                                                         \
  };                                                                                                          \
  CLASS##NAME  NAME;                                                                                           \
  T i##NAME(const string Symb,const int TimeFrame,const int iShift) \
  {                                                                                                           \
    return(CLASS##NAME::Get(Symb,  TimeFrame, iShift));                                                        \
  }
//+------------------------------------------------------------------+
DEFINE_TIMESERIE(Volume, TickVolume, long)
DEFINE_TIMESERIE(Time, Time, datetime)
DEFINE_TIMESERIE(Open, Open, double)
DEFINE_TIMESERIE(High, High, double)
DEFINE_TIMESERIE(Low, Low, double)
DEFINE_TIMESERIE(Close, Close, double)
//+------------------------------------------------------------------+





 double     Buffer1[];
 //+------------------------------------------------------------------+
 //| Объявляем внешние переменные                                     |
 //+------------------------------------------------------------------+
 datetime point_1;
 datetime point_2;
 datetime point_3;
 datetime LastBarTime;
 string line_name[10];
 int gg=1;
 int x1;
 int x2;
 int x3;
 int xx1; // В эту переменную сохраняется значение номера бара вершины перед прогоном при появлении нового бара.
 int xx2; // Если линии стоят, значит при поялвении нового бара номер бара вершины должен увеличиться на 1.
 int xx3; // Если этого не произошло и xx1=x1 после прогона, значит увеличиваем вручную.
 int max;
 int maxx;
 double y1;
 double y2;
 double y3;
 double y11;
 double y22;
 double y33;
 double x11;
 double x22;
 double x33;
 double y;
 double a1;
 double a2;
 double a3;

bool Deinit = true;
 //+------------------------------------------------------------------+
 //| Custom indicator initialization function                         |
 //+------------------------------------------------------------------+
 

MqlDateTime str;
//--------------------------------------------------------------------
int OnInit()                             // Специальная функция init()
  {
   {SetIndexBuffer(0,Buffer1);
   
 //---- indicators
 //----
    return(0);
   }
  
   return(INIT_SUCCEEDED);                             // Выход из спец. ф-ии init()
  }
//--------------------------------------------------------------------
//int start()                            // Специальная функция start()
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])

  {
   // Пересчитываем инликатор только при появлении нового бара
   if(LastBarTime == iTime(Symbol, 0, 0))
      return(0);
    LastBarTime = iTime(Symbol, 0, 0);
   
   
 // Присваиваем значения переменных времени


 int obj_total=ObjectsTotal(0,0,-1);

   for(int ii=0;ii<100;ii++)
     {string name = ObjectName(0,0,ii,OBJ_VLINE);
       if(ObjectGetInteger(0, name,OBJPROP_TYPE)!=OBJ_VLINE)
       continue;
       line_name[gg] = ObjectName(0,0,ii,OBJ_VLINE);
       gg=gg+1;
     
     }
    
   
    point_1=ObjectGetTimeByValue(0,line_name[1],0, OBJPROP_TIME);
    point_2=ObjectGetTimeByValue(0,line_name[2],0, OBJPROP_TIME);
    point_3=ObjectGetTimeByValue(0,line_name[3],0, OBJPROP_TIME);
   
 // Запоминаем текущий номер бара вершины

 xx1=x1; 
    
 //Определяем номера баров ключевых точек
   for (int j=0;j<500; j++)
   { if (Time[j]==point_1) x1=j;}
  
  
   // Если после прогона сдвиг по вершине не произошел, значит линий нет, добавляем +1 вручную.
 if (x1==xx1) x1=x1+1;
  
  
 xx2=x2;
  
   for (int k=0;k<500; k++)
   {if (Time[k]==point_2) x2=k;  }
  
 if (x2==xx2) x2=x2+1;
  
 xx3=x3;

   for (int l=0;l<500; l++)
   {if (Time[l]==point_3) x3=l; }
  
 if (x3==xx3) x3=x3+1;

 // Comment ("n1=", j," n2=", k, " n3=", l);
 //Находим "высоту" вершин
   {
   y1=High[x1];
   y2=High[x2];
   y3=High[x3];
   //Comment ("y1=", y1," x1=", x1, " y2=", y2, "x2=", x2," y3=", y3, " x3=", x3);
   //Принимаем первую из них за начало координат
  
 a1=(y3-(x3*(y2-y1)+x2*y1-x1*y2)/(x2-x1))/(x3*(x3-x1-x2)+x1*x2);
 a2=((y2-y1)/(x2-x1))-a1*(x1+x2);
 a3=((x2*y1-x1*y2)/(x2-x1))+a1*x1*x2;

 max=MathMax(x1,x2);
 maxx=MathMax(max,x3);
  
  
   for (int i=maxx; i>=0; i--)
  
   { y=a1*i*i+a2*i+a3;
   Buffer1[i]=y;}
  

    return(0);
   }


//--------------------------------------------------------------------
   return(rates_total);                           // Выход из спец. ф-ии start()
  }
//--------------------------------------------------------------------
void OnDeinit(const int reason)
  {

   if( Deinit == true)                         // Стираем  с графика, если включена функция очистки графика
     {
      int obj_total=ObjectsTotal(0,0,-1);
      PrintFormat("Всего %d объектов",obj_total);
      for(int i=obj_total-1; i>=0; i--)
        {
         string name=ObjectName(0,i,-1,-1);
         //         PrintFormat("Объект %d: %s",i,name);
         ObjectDelete(0,name);
        }
     }
     Comment("");
//--- destroy timer
   EventKillTimer();

  }


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

There are no errors, but the timing function is not correct, there was not enough time)

And it is better to verify division by zero in 5, before the division operation If the divisor is zero, then....

 
Manter84 #:

Yes, by the way, your answers are really very weak.

Manter84 #:

Here's the code of the simplest inductor (it couldn't be simpler)

There are five mistakes in a six-letter word...

and I'm too weak to correct you.

 
Alexey Viktorov #:

Bummer... The only words I have left in my vocabulary are foul words. So I'd rather not say anything.

What did I ever do to you? Or are you all so aggressive?

Reason: