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?
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.
//+------------------------------------------------------------------+//| ___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; // Период опорной Oint Aver_Bars_O = 5; // Колич. баров для сглаживания опорной Oint Period_R = 21; // Период расчётной Rint Aver_Bars_R = 5; // Колич. баров для сглаживания расчётной Rint Bars_V_S = 5; // Колич.баров для расчёта скоростной Sdouble K_V_S = 2.1; // Коэффициент усиления разности значений скоростной Sint Aver_Bars_S = 5; // Колич. баров для сглаживания скоростной Sint Bars_V_E = 5; // Колич.баров для расчёта импульсной Edouble K_V_E = 2.1; // Коэффициент усиления разности значений импульсной Eint 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 Blackdouble Line_1[]; // Инидикаторн. массив опорной O сглаженный Blackdouble Line_2[]; // Инидикаторн. массив расчётной R Bluedouble Line_3[]; // Инидикаторн. массив расчётной R сглаженный Bluedouble Line_4[]; // Инидикаторн. массив скоростной S Greendouble Line_5[]; // Инидикаторн. массив скоростной S сглаженный Greendouble Line_6[]; // Инидикаторн. массив импульсной E Reddouble Line_7[]; // Инидикаторн. массив импульсной E сглаженный Redint Calc_Period_O; // Расчитываемый период опорной Oint Calc_Period_R; // Расчитываемый период расчётной Rdouble Bars_S; // Вычисленное количество баров (период) для измерения скорости Sdouble Bars_E; // Вычисленное количество баров (период) для измерения импульса Е//--------------------------------------------------------------------int init()
{
SetIndexBuffer(0,Line_0); // Назначение массива буферу опорной O BlackSetIndexBuffer(1,Line_1); // Назначение массива буферу опорной O сглаженный Black SetIndexBuffer(2,Line_2); // Назначение массива буферу расчётной R BlueSetIndexBuffer(3,Line_3); // Назначение массива буферу расчётной R сглаженный BlueSetIndexBuffer(4,Line_4); // Назначение массива буферу скоростной S GreenSetIndexBuffer(5,Line_5); // Назначение массива буферу скоростной S сглаженный GreenSetIndexBuffer(6,Line_6); // Назначение массива буферу импульсной E RedSetIndexBuffer(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;
}
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!
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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?
Is it acceptable to use complex compound conditions
Very permissible
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.
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!
This works.This is not working.
//+------------------------------------------------------------------+ //| __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.
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.
TimeCurrent() % 86400
????