[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 83

 

Can you tell me how should the code look like with the following conditions: if the colour of the indicator changes from red to blue, put a pending order buystop, if on the contrary, the colour of the indicator changed from blue to red, then sellstop?

 
If you put an order in every time you change colour, wouldn't that be a lot?
 
Notter:

Is it acceptable to use complex compound conditions



Very permissible
 
MikeM:
If we set a pending order every time we change colours, will we have too many pending orders?

The indicator is a trend indicator, it does not change colour every bar. I am interested in the condition of checking the colour change of bars and set a pending order based on it. For example, if a new bar is opened and the previous one is blue and the previous one was red, it means that the colours have changed and we should place a pending order.

 
What is the correct way to attach one indicator to another via iCustom()?
I have one indicator in which all 8 indicator arrays are occupied. How to create the second one correctly, so that it draws the curve from the first indicator in 1 indicator array?
Both indicators #property indicator_chart_window.
The most obvious explanation is the analogue in the form of the code of the two linked indicators.

Thank you in advance!

//+------------------------------------------------------------------+
//|                                                   __proba_MA.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 LightSeaGreen
//---- buffers
double MovingBuffer[];
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,MovingBuffer);
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();
//----
   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++;
   for(i=0; i<limit; i++)
      MovingBuffer[i]=iCustom(NULL,0,"moving averages", 0, i); 
   return(0);
  }
This works.
 

This is not working.

//+------------------------------------------------------------------+
//|                                                      ___ORSE.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window       // Индикатор рисуется в основном окне
#property indicator_buffers 8          // Количество буферов
#property indicator_color1 Black       // Цвет линии 0 буфера опорной    МАO
#property indicator_color2 Black       // Цвет линии 1 буфера опорной    МАO сглаженной
#property indicator_color3 Blue        // Цвет линии 2 буфера расчётной  МАR
#property indicator_color4 Blue        // Цвет линии 3 буфера расчётной  МАR  сглаженной
#property indicator_color5 LimeGreen   // Цвет линии 4 буфера скоростной МАS
#property indicator_color6 LimeGreen   // Цвет линии 5 буфера скоростной МАS  сглаженной
#property indicator_color7 Red         // Цвет линии 6 буфера импульсной МАE
#property indicator_color8 Red         // Цвет линии 7 буфера импульсной МАE  сглаженной


 double TF             =   1;    // Тайм Фрэйм
//-----------------
 int    Period_O       =  13;    // Период опорной O
 int    Aver_Bars_O    =   5;    // Колич. баров для сглаживания опорной O

 int    Period_R       =  21;    // Период расчётной R
 int    Aver_Bars_R    =   5;    // Колич. баров для сглаживания расчётной R

 int    Bars_V_S       =   5;    // Колич.баров для расчёта скоростной S
 double K_V_S          = 2.1;    // Коэффициент усиления разности значений скоростной S
 int    Aver_Bars_S    =   5;    // Колич. баров для сглаживания скоростной S

 int    Bars_V_E       =   5;    // Колич.баров для расчёта импульсной E
 double K_V_E          = 2.1;    // Коэффициент усиления разности значений импульсной E
 int    Aver_Bars_E    =   5;    // Колич. баров для сглаживания импульсной E
//-----------------
int     Ma_method      =   3;    // MODE_LWMA       3  Линейно-взвешенное скользящее среднее  
int     Applied_price  =   5;    // PRICE_TYPICAL   5  Типичная цена (High+Low+Close)/3

//--------------------------------------------------------------------
                   // Расчитываемые величины
double Line_0[];                       // Инидикаторн. массив опорной    O            Black
double Line_1[];                       // Инидикаторн. массив опорной    O сглаженный Black
double Line_2[];                       // Инидикаторн. массив расчётной  R            Blue
double Line_3[];                       // Инидикаторн. массив расчётной  R сглаженный Blue
double Line_4[];                       // Инидикаторн. массив скоростной S            Green
double Line_5[];                       // Инидикаторн. массив скоростной S сглаженный Green
double Line_6[];                       // Инидикаторн. массив импульсной E            Red
double Line_7[];                       // Инидикаторн. массив импульсной E сглаженный Red

int    Calc_Period_O;                  // Расчитываемый период опорной   O
int    Calc_Period_R;                  // Расчитываемый период расчётной R
double Bars_S;                         // Вычисленное количество баров (период) для измерения скорости  S
double Bars_E;                         // Вычисленное количество баров (период) для измерения импульса Е

//--------------------------------------------------------------------
int init()
   {
    SetIndexBuffer(0,Line_0);          // Назначение массива буферу опорной    O            Black
    SetIndexBuffer(1,Line_1);          // Назначение массива буферу опорной    O сглаженный Black 
    SetIndexBuffer(2,Line_2);          // Назначение массива буферу расчётной  R            Blue
    SetIndexBuffer(3,Line_3);          // Назначение массива буферу расчётной  R сглаженный Blue
    SetIndexBuffer(4,Line_4);          // Назначение массива буферу скоростной S            Green
    SetIndexBuffer(5,Line_5);          // Назначение массива буферу скоростной S сглаженный Green
    SetIndexBuffer(6,Line_6);          // Назначение массива буферу импульсной E            Red
    SetIndexBuffer(7,Line_7);          // Назначение массива буферу импульсной E сглаженный Red

    SetIndexStyle (0,DRAW_NONE,STYLE_SOLID,1);   // Стиль линии, толщина опорной    O            Black
    SetIndexStyle (1,DRAW_LINE,STYLE_SOLID,2);   // Стиль линии, толщина опорной    O сглаженный Black
    SetIndexStyle (2,DRAW_NONE,STYLE_SOLID,1);   // Стиль линии, толщина расчётной  R            Blue
    SetIndexStyle (3,DRAW_LINE,STYLE_SOLID,2);   // Стиль линии, толщина расчётной  R сглаженный Blue
    SetIndexStyle (4,DRAW_NONE,STYLE_SOLID,1);   // Стиль линии, толщина скоростной S            Green
    SetIndexStyle (5,DRAW_LINE,STYLE_SOLID,2);   // Стиль линии, толщина скоростной S сглаженный Green
    SetIndexStyle (6,DRAW_NONE,STYLE_SOLID,1);   // Стиль линии, толщина импульсной E            Red
    SetIndexStyle (7,DRAW_LINE,STYLE_SOLID,2);   // Стиль линии, толщина импульсной E сглаженный Red

    Calc_Period_O = TF * Period_O;     // Вычисленный период O
    Calc_Period_R = TF * Period_R;     // Вычисленный период R для S и Е

    Bars_S        = TF * Bars_V_S;     // Вычисленное количество баров (период) для измерения скорости S
    Bars_E        = TF * Bars_V_E;     // Вычисленное количество баров (период) для измерения импульса Е

    return;
   }
//--------------------------------------------------------------------
int deinit()
   {
    return(0);
   }
//--------------------------------------------------------------------
int start()
   {
    //----------------------------------------------------------------
    int i,n,s,e,Counted_bars;
    double MAO,MAR,MAR_c,MAR_p,MAS,MAS_c,MAS_p,MAE,Sum;
    //----------------------------------------------------------------
    Counted_bars=IndicatorCounted();   // Количество просчитанных баров 
    i=Bars-Counted_bars-1;             // Индекс первого непосчитанного
    //----------------------------------------------------------------
    while(i>=0)
        {
         //--------------------------------------------------------------
                             // ОПОРНАЯ
         MAO=iMA(NULL, 0, Calc_Period_O, 0, Ma_method, Applied_price, i);      // Значение опорной МАO
         Line_0[i]=MAO;                                                        // Индик. массив опорной O
         //--------------------------------------------------------------
         if (Aver_Bars_O<0)                      // Если неверно задано сглаживание
              Aver_Bars_O=0;                     // .. то не меньше нуля
         Sum=0;                                  // Технический приём
         for(n=i; n<=i+Aver_Bars_O; n++)         // Суммироваение последних значен.
              Sum=Sum + Line_0[n];               // Накопление суммы последн. знач.
         Line_1[i]= Sum/(Aver_Bars_O+1);         // Индик. массив сглаженной линии Black

         //--------------------------------------------------------------
                             // РАСЧЁТНАЯ
         MAR=iMA(NULL, 0, Calc_Period_R, 0, Ma_method, Applied_price, i);      // Значение расчётной МАR
         Line_2[i]=MAR;                                                        // Индик. массив расчётной R
         //--------------------------------------------------------------
         if (Aver_Bars_R<0)                      // Если неверно задано сглаживание
              Aver_Bars_R=0;                     // .. то не меньше нуля
         Sum=0;                                  // Технический приём
         for(n=i; n<=i+Aver_Bars_R; n++)         // Суммироваение последних значен.
              Sum=Sum + Line_2[n];               // Накопление суммы последн. знач.
         Line_3[i]= Sum/(Aver_Bars_R+1);         // Индик. массив сглаженной линии Blue

         //--------------------------------------------------------------
                             // СКОРОСТНАЯ
         MAR_c=Line_2[i];
         s=i+Bars_S;
         MAR_p=Line_2[s];
         MAS= MAO+K_V_S*(MAR_c-MAR_p);                                         // Значение скоростной MAS
         Line_4[i]= MAS;                                                       // Индик. массив скоростной S
         //--------------------------------------------------------------
         if (Aver_Bars_S<0)                      // Если неверно задано сглаживание
              Aver_Bars_S=0;                     // .. то не меньше нуля
         Sum=0;                                  // Технический приём
         for(n=i; n<=i+Aver_Bars_S; n++)         // Суммироваение последних значен.
              Sum=Sum + Line_4[n];               // Накопление суммы последн. знач.
         Line_5[i]= Sum/(Aver_Bars_S+1);         // Индик. массив сглаженной линии LimeGreen

         //--------------------------------------------------------------
                             // ИМПУЛЬСНАЯ
         MAS_c=Line_5[i];
         e=i+Bars_E;
         MAS_p=Line_5[e];
         MAE= MAO+0.001*K_V_E*(MAS_c-MAS_p)*Volume[i];                         // Значение импульсной MAE
         Line_6[i]= MAE;                                                       // Индик. массив импульсной Е
         //--------------------------------------------------------------
         if (Aver_Bars_E<0)                      // Если неверно задано сглаживание
              Aver_Bars_E=0;                     // .. то не меньше нуля
         Sum=0;                                  // Технический приём
         for(n=i; n<=i+Aver_Bars_E; n++)         // Суммироваение последних значен.
              Sum=Sum + Line_6[n];               // Накопление суммы последн. знач.
         Line_7[i]= Sum/(Aver_Bars_E+1);         // Индик. массив сглаженной линии Red
         i--;                                    // Расчёт индекса следующего бара
     }
   return;
  }
//+------------------------------------------------------------------+
//|                                                 __proba_ORSE.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 LightSeaGreen
//---- buffers
double MovingBuffer[];
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,MovingBuffer);
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();
//----
   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++;
   for(i=0; i<limit; i++)
      MovingBuffer[i]=iCustom(NULL,0,"___ORSE", 0, i); 
   return(0);
  }

The terminal hangs. Why, I don't understand.

 
ZahvatkiN:

The indicator is a trend indicator, it does not change colour every bar. I am interested in the condition itself to check if the colour of the bars is changing and to set a pending order based on that.

The computer does not distinguish the colour, but only the numbers 0 and 1. Therefore, we should specify the reason for colour changes in the indicator. For example, change of price direction and how significant this change is!
 
Guys, does anyone have a function to determine how much time (seconds) has elapsed since the start of the day?
 
TimeCurrent() % 86400
 
MikeM:
TimeCurrent() % 86400

????