Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 473

 
Vladon:

fixed the errors... But during the test it says "Custom indicators cannot be tested".

I first doubted the specified indicator buffer, but having specified both in turn, the error still hasn't disappeared. Did I screw up somewhere again?

Files:
expert_2.mq4  9 kb
 
Programming Guru help). I was testing an EA and I guess I finally got it) as soon as I turn on the EA tester and my bot starts working the tester freezes and stays in place for a very long time, what can be in the code that slows down the tester?
 
miha91:
Programming Guru help). I was testing an EA and I guess I made it through) as soon as I turn on the tester and my bot starts working the tester freezes and stays in place for a very long time, what can be in the code that slows down the tester?
I also have something under the bathtub rustling! What could it be?
 
int OnInit()
  {
//--- indicator buffers mapping
 SetIndexBuffer(0,buf1);
SetIndexStyle(0,DRAW_LINE,0,1,Red);



 SetIndexBuffer(1,buf2);
SetIndexStyle(1,DRAW_LINE,0,1,Aqua);


 SetIndexBuffer(2,buf3);
SetIndexStyle(2,DRAW_LINE,0,1,Green);



 SetIndexBuffer(3,buf4);
SetIndexStyle(3,DRAW_LINE,0,1,Yellow);



//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---



   
   buf1[pos]=iOpen(Symbol(),0,pos);
   buf2[pos]=iHigh(Symbol(),0,pos);
   buf3[pos]=iClose(Symbol(),0,pos);
   buf4[pos]=iLow(Symbol(),0,pos);
   
  
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
it should draw 4 lines, but it only draws the first buffer if the others are missing
 

I am trying to determine a point on the line after its modification, it works fine at all periods, but at 1 and 4 o'clock there is periodically an error of 100-200 points, how to deal with it?

marriage

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   SetTLine(Red,"LineAlert",Time[15],High[15],0,High[0]+15*Point,0,0,1);
//---
   return(INIT_SUCCEEDED);
  }
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//|  Описание : Уравнение прямой.                                              |
//|             Вычисляет значение Y для X в точке пересечения с прямой.       |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    x1,y1 - координаты первой точки,                                        |
//|    x2,y2 - координаты второй точки,                                        |
//|    x     - значение, для которого вычислить Y                              |
//+----------------------------------------------------------------------------+
double EquationDirect(double x1,double y1,double x2,double y2,double x)
  {
   double tk;
   if(x2==x1) return(y1);
   tk=(y2-y1)/(x2-x1)*(x-x1)+y1;

   return(NormalizeDouble(tk,Digits));
  }
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//|  Описание : Установка объекта OBJ_TREND трендовая линия                    |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    cl - цвет линии                                                         |
//|    nm - наименование               (  ""  - время открытия текущего бара)  |
//|    t1 - время открытия бара        (  0   - Time[10]                       |
//|    p1 - ценовой уровень            (  0   - Low[10])                       |
//|    t2 - время открытия бара        (  0   - текущий бар)                   |
//|    p2 - ценовой уровень            (  0   - Bid)                           |
//|    ry - луч                        (False - по умолчанию)                  |
//|    st - стиль линии                (  0   - простая линия)                 |
//|    wd - ширина линии               (  1   - по умолчанию)                  |
//+----------------------------------------------------------------------------+
void SetTLine(color cl,string nm="",
              datetime t1=0,double p1=0,datetime t2=0,double p2=0,
              bool ry=False,int st=0,int wd=1)
  {
   if(nm=="") nm=DoubleToStr(Time[0],0);
   if(t1<=0) t1=Time[10];
   if(p1<=0) p1=Low[10];
   if(t2<=0) t2=Time[0];
   if(p2<=0) p2=Bid;
   if(ObjectFind(nm)<0) ObjectCreate(nm,OBJ_TREND,0,0,0,0,0);
   ObjectSet(nm,OBJPROP_TIME1,t1);
   ObjectSet(nm,OBJPROP_PRICE1,p1);
   ObjectSet(nm,OBJPROP_TIME2,t2);
   ObjectSet(nm,OBJPROP_PRICE2,p2);
   ObjectSet(nm,OBJPROP_COLOR,cl);
   ObjectSet(nm,OBJPROP_RAY,ry);
   ObjectSet(nm,OBJPROP_STYLE,st);
   ObjectSet(nm,OBJPROP_WIDTH,wd);
  }
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    cd - код значка                                                         |
//|    cl - цвет значка                                                        |
//|    nm - наименование               ("" - время открытия текущего бара)     |
//|    t1 - время открытия бара        (0  - текущий бар)                      |
//|    p1 - ценовой уровень            (0  - Bid)                              |
//|    sz - размер значка              (0  - по умолчанию)                     |
//+----------------------------------------------------------------------------+
void SetArrow(int cd,color cl,
              string nm="",datetime t1=0,double p1=0,int sz=0)
  {
   if(nm=="") nm=DoubleToStr(Time[0],0);
   if(t1<=0) t1=Time[0];
   if(p1<=0) p1=Bid;
   if(ObjectFind(nm)<0) ObjectCreate(nm,OBJ_ARROW,0,0,0);
   ObjectSet(nm,OBJPROP_TIME1,t1);
   ObjectSet(nm,OBJPROP_PRICE1,p1);
   ObjectSet(nm,OBJPROP_ARROWCODE,cd);
   ObjectSet(nm,OBJPROP_COLOR,cl);
   ObjectSet(nm,OBJPROP_WIDTH,sz);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int d=0;
   int    X_1,X_2,X3d;
   double Y_1,Y_2,Y3d;
   static int _time_waiting=0;
   static int i;
//---
   X_1=   ObjectGet("LineAlert",OBJPROP_TIME1);
   X_2 = ObjectGet("LineAlert", OBJPROP_TIME2);
   Y_1 = ObjectGet("LineAlert", OBJPROP_PRICE1);
   Y_2 = ObjectGet("LineAlert", OBJPROP_PRICE2);
   SetArrow(6,Orange,"X1",X_1,Y_1,3);
   SetArrow(6,Orange,"X2",X_2,Y_2,3);
   X3d=Time[0];Y3d=EquationDirect(X_1,Y_1,X_2,Y_2,X3d);
   SetArrow(6,Orange,"X",X3d,Y3d,3);
  }
//+------------------------------------------------------------------+
 
beginner:

I am trying to determine a point on the line after its modification, at all periods normally works, but at 1 and 4 o'clock periodically there is an error of 100-200 points, how to deal with it?


I have not tried it.

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   SetTLine(Red,"LineAlert",Time[15],High[15],0,High[0]+15*Point,0,0,1);
//---
   return(INIT_SUCCEEDED);
  }
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//|  Описание : Уравнение прямой.                                              |
//|             Вычисляет значение Y для X в точке пересечения с прямой.       |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    x1,y1 - координаты первой точки,                                        |
//|    x2,y2 - координаты второй точки,                                        |
//|    x     - значение, для которого вычислить Y                              |
//+----------------------------------------------------------------------------+
double EquationDirect(double x1,double y1,double x2,double y2,double x)
  {
   double tk;
   if(x2==x1) return(y1);
   tk=(y2-y1)/(x2-x1)*(x-x1)+y1;

   return(NormalizeDouble(tk,Digits));
  }
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//|  Описание : Установка объекта OBJ_TREND трендовая линия                    |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    cl - цвет линии                                                         |
//|    nm - наименование               (  ""  - время открытия текущего бара)  |
//|    t1 - время открытия бара        (  0   - Time[10]                       |
//|    p1 - ценовой уровень            (  0   - Low[10])                       |
//|    t2 - время открытия бара        (  0   - текущий бар)                   |
//|    p2 - ценовой уровень            (  0   - Bid)                           |
//|    ry - луч                        (False - по умолчанию)                  |
//|    st - стиль линии                (  0   - простая линия)                 |
//|    wd - ширина линии               (  1   - по умолчанию)                  |
//+----------------------------------------------------------------------------+
void SetTLine(color cl,string nm="",
              datetime t1=0,double p1=0,datetime t2=0,double p2=0,
              bool ry=False,int st=0,int wd=1)
  {
   if(nm=="") nm=DoubleToStr(Time[0],0);
   if(t1<=0) t1=Time[10];
   if(p1<=0) p1=Low[10];
   if(t2<=0) t2=Time[0];
   if(p2<=0) p2=Bid;
   if(ObjectFind(nm)<0) ObjectCreate(nm,OBJ_TREND,0,0,0,0,0);
   ObjectSet(nm,OBJPROP_TIME1,t1);
   ObjectSet(nm,OBJPROP_PRICE1,p1);
   ObjectSet(nm,OBJPROP_TIME2,t2);
   ObjectSet(nm,OBJPROP_PRICE2,p2);
   ObjectSet(nm,OBJPROP_COLOR,cl);
   ObjectSet(nm,OBJPROP_RAY,ry);
   ObjectSet(nm,OBJPROP_STYLE,st);
   ObjectSet(nm,OBJPROP_WIDTH,wd);
  }
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    cd - код значка                                                         |
//|    cl - цвет значка                                                        |
//|    nm - наименование               ("" - время открытия текущего бара)     |
//|    t1 - время открытия бара        (0  - текущий бар)                      |
//|    p1 - ценовой уровень            (0  - Bid)                              |
//|    sz - размер значка              (0  - по умолчанию)                     |
//+----------------------------------------------------------------------------+
void SetArrow(int cd,color cl,
              string nm="",datetime t1=0,double p1=0,int sz=0)
  {
   if(nm=="") nm=DoubleToStr(Time[0],0);
   if(t1<=0) t1=Time[0];
   if(p1<=0) p1=Bid;
   if(ObjectFind(nm)<0) ObjectCreate(nm,OBJ_ARROW,0,0,0);
   ObjectSet(nm,OBJPROP_TIME1,t1);
   ObjectSet(nm,OBJPROP_PRICE1,p1);
   ObjectSet(nm,OBJPROP_ARROWCODE,cd);
   ObjectSet(nm,OBJPROP_COLOR,cl);
   ObjectSet(nm,OBJPROP_WIDTH,sz);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int d=0;
   int    X_1,X_2,X3d;
   double Y_1,Y_2,Y3d;
   static int _time_waiting=0;
   static int i;
//---
   X_1=   ObjectGet("LineAlert",OBJPROP_TIME1);
   X_2 = ObjectGet("LineAlert", OBJPROP_TIME2);
   Y_1 = ObjectGet("LineAlert", OBJPROP_PRICE1);
   Y_2 = ObjectGet("LineAlert", OBJPROP_PRICE2);
   SetArrow(6,Orange,"X1",X_1,Y_1,3);
   SetArrow(6,Orange,"X2",X_2,Y_2,3);
   X3d=Time[0];Y3d=ObjectGetValueByShift("LineAlert", 0);
   SetArrow(6,Orange,"X",X3d,Y3d,3);
  }
//+------------------------------------------------------------------+

Try, I have not tried.

 

Alternatively, you could go like this

Y3d = ObjectGetValueByTime("LineAlert",Time[0],2);
  

In modern terms

 
r772ra:

Alternatively, you could go like this

In modern parlance.


Seems to be working, I'll keep watching.

Thank you!

 
Question to knowledgeable people-problem arose recently: on the UPU signal to the mail has ceased to come, before everything was normal, now in the log of the terminal writes during the test:has been sant, but the mail does not come anything. I restarted the UPU, the terminal, too, no result.
 

Help with advice. On the old version of the terminal my last tick price array worked, but on the new build 609 it no longer does.

The question is how to store the last, say, 20 ticks of price into the array?

Reason: