[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 181

 
Activict:

Good afternoon. I have such a question.

I have redesigned this indicator for my own needs with great difficulty from pieces of code of other Expert Advisors and Inductors. It is not a big code and it works the way I want it to.

The matter is that it performs some calculations internally and shows up or down arrows on the chart.

Please advise how to make an Expert Advisor to open an order in the right direction when arrow appears on the chart

More precisely, I just need to know which arrow is active now, I think I can do the rest

Here is a piece of code to make it clearer, it's an initialization in the indicator

   SetIndexBuffer(1, Vverh);

   SetIndexStyle(1,DRAW_ARROW);

   SetIndexArrow(1,233);

   

   SetIndexBuffer(2,Vniz);

   SetIndexStyle(2,DRAW_ARROW);

   SetIndexArrow(2,234); 

Thanks in advance, everyone

Use the built-in iCustom function to receive the values of the custom indicator you need in the Expert Advisor.



double iCustom( string symbol, int timeframe, string name, ..., int mode, int shift)

For example, you need to know if there is an up or down arrow on the last fully formed bar:


double Up=iCustom(NULL, 0, name/* название индикатора */, /* настраиваемые параметры индикатора через запятую */, 1, 1); // стрелка вверх
double Dw=iCustom(NULL, 0, name/* название индикатора */, /* настраиваемые параметры индикатора через запятую */, 2, 1); // стрелка вниз
 

Thanks for the reply! Yes the arrows sometimes go missing. Will this method read "0" if the arrow disappears?

And the arrow is drawn only on the emerging bar, the previous bars it does not re-draw, at the moment of occurrence it is necessary to open a deal and respectively if the arrow disappears then close

 
Is there any way to make the EA send requests to the server more often than usual using program code? So that instead of one request there are two, or for that you can just repeat the program shell ... If three requests instead of one, then repeat it twice ...? ?
 
Activict:

Yes the arrows sometimes go missing. Will this method through customisation read '0' if the arrow goes missing?

Yes, it will.

Activict:

And the arrow is drawn only on the forming bar, the previous bars it does not re-draw, at the moment of occurrence it is necessary to open the position and respectively if the arrow disappears then close

Consequently, if the arrow is on one of the fully formed bars, it will no longer disappear. The arrow can appear and disappear several times on the current bar.
 
Activict:

спасибо за ответ! Да стрелки иногда пропадают. Этот способ через кастом будет считывать "0" если стрелка пропадет?

The value that is specified as "empty" in the code of the indicator is considered with iCustom. As a rule, it can be 0 or EMPTY_VALUE.

EMPTY_VALUE is default in indicators, but if you put SetIndexEmptyValue in init(), it will be different.

 
yellownight:
Is there any way to make the EA send requests to the server more often than usual using program code? So that instead of one request there are two, or for that you can just repeat the program shell ... If three requests instead of one, then repeat twice ...? ?
This will not do you any good. Bombard the server with requests and your account may be disabled altogether. I know this happens to people who "overdo the requests" and "bombard" the server with too many of them.
 

I have written a simple indicator. Here is the code:

//+------------------------------------------------------------------+
//|                                            AngleByLineFromMA.mq4 |
//|                                                              hoz |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "hoz"
#property link      ""

extern string  h1 = "основные параметры машки";
extern int     maTF = 0;
extern int     maPeriod = 50;
extern int     maShiftByPrice = 0;
extern int     maMethod = 0;
extern int     maPrice = 0;
extern int     shiftBarsBack1 = 2;                       // Первое значение shift
extern int     shiftBarsBack2 = 7;                       // Второе значение shift
extern string  h2 = "===============================";

string         h3 = "Другие переменные";
double         pointOfMaFirst,                           // Первая тока (начало отрисовки отрезка)
               pointOfMaLast,                            // Вторая тока отрезка (конец отрисовки отрезка)
               varsAngle[1000];                              // Буфер для хранения значение возвращаемых машкой

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//#property indicator_minimum -45
//#property indicator_maximum 45
//+------------------------------------------------------------------+
//|               Функция инициализации индикатора                   |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   SetIndexBuffer(0,varsAngle);                          // Связываем массив значений угла с буфером
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2); 
   
// -------------- блок инициализации закончен ----------------------
   return(0);
  }
//+------------------------------------------------------------------+
//|              Функция деинициализации индикатора                  |
//+------------------------------------------------------------------+
int deinit()
  {
    ObjectsDeleteAll();                                  // Очистим график от всего
    
// -------------- блок инициализации закончен ----------------------
   return(0);
  }
//+------------------------------------------------------------------+
//|                  Функция итерации эксперта                       |
//+------------------------------------------------------------------+
int start()
  {
    int i, countedBars = IndicatorCounted();
    int limit = Bars - countedBars;
    if (limit > 400) limit = 400;
        
    for(i = limit;i > 1;i--)
    {
      pointOfMaFirst = iMA(Symbol(),maTF,maPeriod,maShiftByPrice,maMethod,maPrice,shiftBarsBack1+i);   // Начальная точка прямой
      pointOfMaLast = iMA(Symbol(),maTF,maPeriod,maShiftByPrice,maMethod,maPrice,shiftBarsBack2+i);     // Крайняя точка прямой
    
      varsAngle[i] = pointOfMaFirst - pointOfMaLast;
      Print("varsAngle[i] = ", varsAngle[i]);
    }

    return(0);
  }
There is only one buffer in it. The indicator values are of type double.

In Expert Advisor, I decided to get the value of the indicator and apply it to the trade as a filter.

Here I wrote a simple function call of this indicator buffer on the last formed bar:

//+-------------------------------------------------------------------------------------+
//| Получаем направление фильтрующей МА                                                 |
//+-------------------------------------------------------------------------------------+
double GetSlopeOfMa()
{
   double slope = iCustom(NULL, i_TF, "AngleByLineFromMA simplest", 0, 1);
   Print ("slope = ", slope);
   
   return(slope);
}
The slope value is not correct in the tester:
2013.02.26 16:57:26     2009.10.26 00:23  D_Aleks_first_pattern EURUSD,H1: slope = 2147483647
2013.02.26 16:57:26     2009.10.26 00:23  D_Aleks_first_pattern EURUSD,H1: slope = 2147483647
2013.02.26 16:57:26     2009.10.26 00:23  D_Aleks_first_pattern EURUSD,H1: slope = 2147483647
2013.02.26 16:57:26     2009.10.26 00:23  D_Aleks_first_pattern EURUSD,H1: slope = 2147483647
2013.02.26 16:57:26     2009.10.26 00:23  D_Aleks_first_pattern EURUSD,H1: slope = 2147483647
2013.02.26 16:57:26     2009.10.26 00:23  D_Aleks_first_pattern EURUSD,H1: slope = 2147483647

Why? The type is correct. The call is also correct. The indicator works properly at all. Here is the log from the tester, but from a real current market:

2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.0009
2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.0009
2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.0009
2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.0009
2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.0009
2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.0009
2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.001
2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.001
2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.0011
2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.0011
2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.0011
2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.0011
2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.001
2013.02.26 16:57:05     AngleByLineFromMA simplest EURUSD,H1: varsAngle[i] = 0.001

Why is some number 2147483647 returned all the time instead of the required number ?

 
hoz:

I have written a simple indicator. Here is the code:

It has only one buffer. The indicator values are of double type.

In Expert Advisor, I decided to get the value of the indicator and apply it to the trade as a filter.

Here I wrote a simple function call of this indicator buffer on the last formed bar:

The slope value returned in the tester is not correct:

Why? The type is correct. The call is also correct. The indicator works properly at all. Here is the log log on the tester, and from the real current market:

Why is some number2147483647 returnedall the time instead of the required number ?

In the tester at the beginning of work not enough bars in the history for the correct calculation of the indicator.

//+-------------------------------------------------------------------------------------+
//| Получаем направление фильтрующей МА                                                 |
//+-------------------------------------------------------------------------------------+
double GetSlopeOfMa()
{
   if(iBars(NULL, i_TF)<maPeriod) { Print("Недостаточно баров в истории для корректного расчёта значений индикатора!"); return(-1.0); }
   double slope = iCustom(NULL, i_TF, "AngleByLineFromMA simplest", 0, 1);
   Print ("slope = ", slope);
   
   return(slope);
}
 
//+-------------------------------------------------------------------------------------+
//| Получаем направление фильтрующей МА                                                 |
//+-------------------------------------------------------------------------------------+
double GetSlopeOfMa()
{
   if(iBars(NULL, i_TF) < maPeriod)
   {
      Print("Недостаточно баров в истории для корректного расчёта значений индикатора!");
      return(0);
   }
   double slope = iCustom(NULL, i_TF, "AngleByLineFromMA simplest", 0, 1);
   Print ("slope = ", slope);
   Print ("iBars(NULL, i_TF) = ", iBars(NULL, i_TF));
   
   return(slope);
}

I have downloaded a story from Dukascopy since 2007... there's no way there are not enough bars. MA period is only 50.

I pasted your line, but I corrected return(0) ... and added the output of the number of bars on the chart:

Here in the log:

2013.02.26 17:53:26	2009.10.26 00:22  D_Aleks_first_pattern EURUSD,H1: iBars(NULL, i_TF) = 15895
2013.02.26 17:53:26	2009.10.26 00:22  D_Aleks_first_pattern EURUSD,H1: slope = 2147483647
2013.02.26 17:53:26	2009.10.26 00:22  D_Aleks_first_pattern EURUSD,H1: iBars(NULL, i_TF) = 15895
2013.02.26 17:53:26	2009.10.26 00:22  D_Aleks_first_pattern EURUSD,H1: slope = 2147483647
2013.02.26 17:53:26	2009.10.26 00:22  D_Aleks_first_pattern EURUSD,H1: iBars(NULL, i_TF) = 15895
2013.02.26 17:53:26	2009.10.26 00:22  D_Aleks_first_pattern EURUSD,H1: slope = 2147483647
2013.02.26 17:53:26	2009.10.26 00:22  D_Aleks_first_pattern EURUSD,H1: iBars(NULL, i_TF) = 15895
2013.02.26 17:53:26	2009.10.26 00:22  D_Aleks_first_pattern EURUSD,H1: slope = 2147483647


 
hoz:

I have downloaded a story from Dukascopy since 2007... there's no way there are not enough bars. MA period is only 50.

Here's your line, but I corrected it with return(0) ...

Here it is in the log:


The problem seems to be in the indicator

 if (limit > 400) limit = 400;