Withthese ChartTimePriceToXY and ChartXYToTimePricefunctions you can arrange anywhere
Not enough brains to figure out how to do it. Here I have done it the old-fashioned way, crooked, but it works. And no one can show you how to make it look nice using ChartTimePriceToXY and ChartXYToTimePricefunctions or provide you with a link to a working example of code.
Leo59: I don't have the brains to figure out how to do it. Here I did it the old-fashioned way, crooked and slanted, but it works. No one can show you how to make it look nice using ChartTimePriceToXY and ChartXYToTimePricefunctions or provide you with a link to a working example.
#property indicator_chart_windowexternint History = 35; // Сколько баров мы имеем ввидуexternint Multiple = 5; // Кратность отображаемой разметкиcolor Color=0;
color Color_multiple=Moccasin; // Цвет индексов кратных "Multiple"color Color_between=MintCream; // Цвет индексов промежуточных string name="", name2="";
string Text="";
int Font_size=0;
int Font_size_multiple=14; // Размер шрифта индексов кратных "Multiple"int Font_size_between=8; // Размер шрифта индексов промежуточныхbool Back=true; //--- отобразим на переднем (false) или заднем (true) плане. Если (true), то подсветки дат не выводитсяstring Font="Arial"; // Шрифтdouble Angle=0.0; // Угол наклона в градусахint Style=STYLE_DOT; // Для всех - стиль пунктирint Width=1; // Толщина линииint x,y=10,y2;
double _price;
datetime dt;
int window;
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+//жжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжж//+------------------------------------------------------------------+//| Custom indicator initialization function F 1 | int init()//+------------------------------------------------------------------+int init()
{
// IndicatorShortName(IN + " (" + ")"); // Короткое имя индикатораreturn(INIT_SUCCEEDED); // Успешная инициализация приложения
}
//жжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжж//+------------------------------------------------------------------+//| expert deinitialization function F 2 | int deinit()//+------------------------------------------------------------------+int deinit() // Время исполнения специальной функции deinit() ограничено периодом 2,5 секунды.
{
ObjectsDeleteAll(0,"label",0); // Идентификатор графика, префикс имени объекта, индекс окнаObjectsDeleteAll(0,"text",0);
return(0); // Выход из deinit()
}
//жжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжж//+------------------------------------------------------------------+//| Custom indicator iteration function F 3 | int start()//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
int i=0;
int limit=Bars-IndicatorCounted()-1;
if(limit>1) limit=MathMin(Bars,History+(History==0)*Bars)-1;
for(i=0; i<History; i++)
{
name="label "+i;
name2= "text "+i;
Text = DoubleToStr(i,0);
if(MathMod(i,Multiple)==0) // MathMod() Возвращает вещественный остаток от деления двух чисел (i/Multiple).
{
Color=Color_multiple;
Font_size=Font_size_multiple;
if(ObjectFind(0,name)==-1) // Если объект "name" не найден
{
ObjectCreate(0,name,OBJ_VLINE,0,Time[i],0); // Создаем объект..ObjectSetInteger(0,name,OBJPROP_STYLE,Style); //--- установим стиль отображения линииObjectSetInteger(0,name,OBJPROP_WIDTH,Width); //--- установим толщину линииObjectSetInteger(0,name,OBJPROP_COLOR,Color); //--- установим цветif(ChartTimePriceToXY(0,0,time[i],close[i],x,y2))
{
if(x<0) continue;
}
elsePrint(__FUNCTION__," return error code: ",GetLastError());
if(ChartXYToTimePrice(0,x,y,window,dt,_price))
{
if(!ObjectCreate(0,name2,OBJ_TEXT,0,time[i],_price))
{
Print(__FUNCTION__,
": не удалось создать текстовую метку! Код ошибки = ",GetLastError());
}
//--- установим угол графика, относительно которого будут определяться координаты точки ObjectSetInteger(0,name2,OBJPROP_CORNER,CORNER_LEFT_UPPER);
//--- установим текст ObjectSetString(0,name2,OBJPROP_TEXT,IntegerToString(i));
//--- установим шрифт текста ObjectSetString(0,name2,OBJPROP_FONT,"Arial");
//--- установим размер шрифта ObjectSetInteger(0,name2,OBJPROP_FONTSIZE,12);
//--- установим угол наклона текста ObjectSetDouble(0,name2,OBJPROP_ANGLE,0);
//--- установим способ привязки ObjectSetInteger(0,name2,OBJPROP_ANCHOR,ANCHOR_LEFT_UPPER);
//--- установим цвет ObjectSetInteger(0,name2,OBJPROP_COLOR,clrBlue);
//--- отобразим на переднем (false) или заднем (true) плане ObjectSetInteger(0,name2,OBJPROP_BACK,false);
//--- включим (true) или отключим (false) режим перемещения метки мышью ObjectSetInteger(0,name2,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,name2,OBJPROP_SELECTED,false);
//--- скроем (true) или отобразим (false) имя графического объекта в списке объектов ObjectSetInteger(0,name2,OBJPROP_HIDDEN,true);
//--- установим приоритет на получение события нажатия мыши на графике ObjectSetInteger(0,name2,OBJPROP_ZORDER,0);
}
elsePrint(__FUNCTION__," return error code: ",GetLastError());
}
else// Если объект "name" найден
{
ObjectMove(0,name,0,Time[i],0); // Сообщение новых координат.
}
}
/* else
{
Color = Color_between;
Font_size = Font_size_between;
if(ObjectFind(0, name)==-1) // Если объект "name" не найден
{
ObjectCreate(0,name,OBJ_VLINE,0,Time[i],0); // Создаем объект..
ObjectSetInteger(0,name,OBJPROP_STYLE,Style); //--- установим стиль отображения линии
ObjectSetInteger(0,name,OBJPROP_WIDTH,Width); //--- установим толщину линии
ObjectSetInteger(0,name,OBJPROP_COLOR,Color); //--- установим цвет
ObjectSetString(0,name,OBJPROP_TEXT,Text); //--- установим текст
ObjectSetString(0,name,OBJPROP_FONT,Font); //--- установим шрифт текста
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,Font_size); //--- установим размер шрифта
ObjectSetDouble(0,name,OBJPROP_ANGLE,Angle); //--- установим угол наклона текста
// Для отображения текстового описания объекта необходимо включить галочку опции "Показывать описания объектов" в окне Графики->Свойства финансового инструмента (F8) > Общие.
ObjectSetInteger(0,name,OBJPROP_BACK, Back); //--- отобразим на переднем (false) или заднем (true) плане
}
else // Если объект "name" найден
{
ObjectMove(0,name, 0, Time[i], 0); // Сообщение новых координат.
}
}*/
}
return(rates_total);
}
I didn't rewrite your code, just added a snippet on how to use the functions
didn't rewrite your code, just added a snippet on the use of functions
Ooh, Rafil, ..... this is so unexpected, and most importantly, so nice, I'm even confused... THANK YOU SO MUCH!!!!! SUPER!!!! Probably just what I needed!!!! It's deep into the night now, and in the morning, I'll try to make sense of it))
I didn't rewrite your code, just added a fragment on using functions
Alas, but in your version, Rafil, the digits are not redrawn on every new bar and are not scaled at the upper (in your version) boundary of the window.
Alas, but in your version, Rafil, the figures are not redrawn on each new bar and are not scaled at the upper (in your version) boundary of the window.
From the animation in your picture you can see that the bar numbers are positioned at the top edge of the window. What happens when a new bar is formed? Maybe the duration of the clip should have been slightly longer, before a new bar is formed, to illustrate this?
Leo59: Your animation shows that the bar numbers are positioned near the upper border of the window. What happens when a new bar is formed? Maybe the duration of the animation should have been slightly longer before a new bar is formed to illustrate this?
Sorry, I didn't catch the moment when the new bar appeared, look carefully, the picture below...
and the code itself, y_pos - number of pixels from the top border, if you want the bottom, useCHART_HEIGHT_IN_PIXELS orCHART_WINDOW_YDISTANCE
//| indexBars.mq5 |//| Copyright 2017, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property indicator_chart_window#property indicator_buffers0#property indicator_plots0int y_pos=10, //--- координата по Y для текстовой метки
x_pos, //--- координата по Х для текстовой метки
y2, bars,
visibleBars=0,//--- количество баров в видимой части графика
indexBars=0; //--- индекс левого крайнего бара в видимой части графикаdouble price;
string names="text";
datetime times[];
//+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ intOnInit()
{
EventSetMillisecondTimer(100);
MqlTick last_tick;
if(SymbolInfoTick(Symbol(),last_tick)) price=last_tick.last;
elsePrint("SymbolInfoTick() failed, error = ",GetLastError());
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
EventKillTimer();
ObjectsDeleteAll(0,names);
}
//+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
return(rates_total);
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnTimer()
{
bars=Bars(_Symbol, _Period);
if(bars<=0) return;
if(CopyTime(_Symbol, _Period, 0, bars, times)<=0) return;
//--- перевернем доступ к массиву times[] - сделаем как в таймсерии ArraySetAsSeries(times,true);
//--- если изменился номер крайнего индекса или кол-во видимых баров на графике, то отрисуем if(indexBars!=ChartFirstVisibleBar() || visibleBars!=ChartVisibleBars())
{
indexBars=ChartFirstVisibleBar(); //запомним новое значение
visibleBars=ChartVisibleBars();
int a=indexBars-visibleBars;
ObjectsDeleteAll(0,names);
for(int i=indexBars; i>a; i--)
{
if(ChartTimePriceToXY(0,0,times[i],price,x_pos,y2))
{
string nname=names+IntegerToString(i);
if(!LabelCreate(0,nname,0,x_pos,y_pos,0,IntegerToString(i,0)))
Print(__FUNCTION__,": не удалось создать текстовую метку! Код ошибки = ",GetLastError());
}
elsePrint(__FUNCTION__," return error code: ",GetLastError());
}
}
ChartRedraw();
}
//+------------------------------------------------------------------+ //| Создает текстовую метку | //+------------------------------------------------------------------+ bool LabelCreate(constlong chart_ID=0, // ID графика conststring name="Label", // имя метки constint sub_window=0, // номер подокна constint x=0, // координата по оси X constint y=0, // координата по оси Y constENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // угол графика для привязки conststring text="Label", // текст conststring font="Arial", // шрифт constint font_size=10, // размер шрифта constcolor clr=clrRed, // цвет constdouble angle=0.0, // наклон текста constENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // способ привязки constbool back=false, // на заднем плане constbool selection=false, // выделить для перемещений constbool hidden=true, // скрыт в списке объектов constlong z_order=0) // приоритет на нажатие мышью
{
//--- сбросим значение ошибки ResetLastError();
//--- создадим текстовую метку if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0))
{
Print(__FUNCTION__,
": не удалось создать текстовую метку! Код ошибки = ",GetLastError());
return(false);
}
//--- установим координаты метки ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- установим угол графика, относительно которого будут определяться координаты точки ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- установим текст ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- установим шрифт текста ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- установим размер шрифта ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- установим угол наклона текста ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
//--- установим способ привязки ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- установим цвет ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- отобразим на переднем (false) или заднем (true) плане ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- включим (true) или отключим (false) режим перемещения метки мышью ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- скроем (true) или отобразим (false) имя графического объекта в списке объектов ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- установим приоритет на получение события нажатия мыши на графике ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- успешное выполнение return(true);
}
//+------------------------------------------------------------------+ //| Функция получает номер первого видимого бара на графике. | //| Индексация как в таймсерии, последние бары имеют меньшие индексы.| //+------------------------------------------------------------------+ int ChartFirstVisibleBar(constlong chart_ID=0)
{
//--- подготовим переменную для получения значения свойства long result=-1;
//--- сбросим значение ошибки ResetLastError();
//--- получим значение свойства if(!ChartGetInteger(chart_ID,CHART_FIRST_VISIBLE_BAR,0,result))
{
//--- выведем сообщение об ошибке в журнал "Эксперты" Print(__FUNCTION__+", Error Code = ",GetLastError());
}
//--- вернем значение свойства графика return((int)result);
}
//+------------------------------------------------------------------+ //| Функция получает количество баров, которые отображаются (видимы )| //| в окне графика. | //+------------------------------------------------------------------+ int ChartVisibleBars(constlong chart_ID=0)
{
//--- подготовим переменную для получения значения свойства long result=-1;
//--- сбросим значение ошибки ResetLastError();
//--- получим значение свойства if(!ChartGetInteger(chart_ID,CHART_VISIBLE_BARS,0,result))
{
//--- выведем сообщение об ошибке в журнал "Эксперты" Print(__FUNCTION__+", Error Code = ",GetLastError());
}
//--- вернем значение свойства графика return((int)result);
}
//+------------------------------------------------------------------+
Sorry, I didn't catch the moment when the new bar appeared, look carefully, the picture below...
and the code, y_pos - number of pixels from the top border. If you want the bottom, useCHART_HEIGHT_IN_PIXELS orCHART_WINDOW_YDISTANCE
Rafil, you have nothing to apologize for. What you have done deserves respect and emulation. I am very much pleased! And the point isn't even in the fact that you did WHAT I needed, but in your attitude to people who need attention, support and help. You, Rafil, are one of the few who know and can. Can do more than just give advice to press the "F1" key. INFINITE THANKS TO YOU !!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
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.
Greetings!
Can you tell me how to make an array of instu
I'm trying to do it like this:
input double Df_1 = 0.8;
input double Df_2 = 0.1;
input double Df_3 = 0.3;
const double Df[3] = {Df_1 ,Df_2 ,Df_3 };
but it generates an error :
'Df_1' - constant expression required
'Df_2' - constant expression required
'Df_3' - constant expression required
A variant:
(Insert the code correctly in the forum)
Withthese ChartTimePriceToXY and ChartXYToTimePricefunctions you can arrange anywhere
I don't have the brains to figure out how to do it. Here I did it the old-fashioned way, crooked and slanted, but it works. No one can show you how to make it look nice using ChartTimePriceToXY and ChartXYToTimePrice functions or provide you with a link to a working example.
I didn't rewrite your code, just added a snippet on how to use the functions
didn't rewrite your code, just added a snippet on the use of functions
Ooh, Rafil, ..... this is so unexpected, and most importantly, so nice, I'm even confused... THANK YOU SO MUCH!!!!! SUPER!!!! Probably just what I needed!!!! It's deep into the night now, and in the morning, I'll try to make sense of it))
I didn't rewrite your code, just added a fragment on using functions
Alas, but in your version, Rafil, the digits are not redrawn on every new bar and are not scaled at the upper (in your version) boundary of the window.
My variant:
Your, Rafil, variant:
Alas, but in your version, Rafil, the figures are not redrawn on each new bar and are not scaled at the upper (in your version) boundary of the window.
My variant:
Your, Rafil's, option:
I assume you need it?
I assume you need this? click on the picture
If I want to pass an indicator parameter of ENUM_TIMEFRAMES type via MqlParam structure, what type should I indicate for this parameter?
InENUM_DATATYPE there is no type ENUM_TIMEFRAMES and other enumerations.
Your animation shows that the bar numbers are positioned near the upper border of the window. What happens when a new bar is formed? Maybe the duration of the animation should have been slightly longer before a new bar is formed to illustrate this?
Sorry, I didn't catch the moment when the new bar appeared, look carefully, the picture below...
and the code itself, y_pos - number of pixels from the top border, if you want the bottom, useCHART_HEIGHT_IN_PIXELS orCHART_WINDOW_YDISTANCE
Sorry, I didn't catch the moment when the new bar appeared, look carefully, the picture below...
and the code, y_pos - number of pixels from the top border. If you want the bottom, useCHART_HEIGHT_IN_PIXELS orCHART_WINDOW_YDISTANCE
With deep respect, Leonid Belsky.