Questions from Beginners MQL5 MT5 MetaTrader 5 - page 481

 
Hello!

Does anyone have a code example that draws some icons, e.g. arrows on the indicator chart, when the lines cross, if there are two, or when the "0" line is crossed, or any other criteria? Preferably at the top and bottom of the self-scaling indicator window.
 
Sergei Vladimirov:
Press "Load". Only the last 2048 bars are automatically loaded, the rest have to be kicked.
This is how it came out after "Load" ...
 
Mike:
That's how it came out after "Load" ...
Forcibly erase the history archive folder and run the terminal - then load all the quotes.
 
Leo59:
Hello!

Maybe someone has an example code that draws some icons, such as arrows on the indicator chart, when crossing the lines, if there are two, or when crossing "0" line, or any other criteria? Preferably at the top and bottom of the self-scaling indicator window.

Here's one from my turkey, maybe it'll help. The code is for MT4, just as it is. It also works with logs.

void PlotArrowUP(int i)
{
    string sup = "\xE9"; //233
    datetime dt = iTime(NULL, 0, i); 
    double dprice = (WindowPriceMax()-WindowPriceMin())/(100.0/ArrowOffsetInPercentOfScreen); //настроить масштаб под свои нужды
    ObjectCreate("arr1"+ArrowIdx, OBJ_TEXT, 0, dt, FastBuffer[i]-dprice);   
    ObjectSetText("arr1"+ArrowIdx, sup, ArrowFontSize, "Wingdings", ColorArrowUp);
    ArrowIdx++;
    if(EnableLogFile)
    {
        string dts = TimeToStr(TimeCurrent(), TIME_DATE | TIME_MINUTES | TIME_SECONDS);
        FileWrite(LogFile1, dts, "  call PlotArrowUp(i) i=", i, "  FastBuffer[i]=", FastBuffer[i]);
    }
}

void PlotArrowDown(int i)
{
    string sup = "\xEA"; //234
    datetime dt = iTime(NULL, 0, i); 
    double dprice = (WindowPriceMax()-WindowPriceMin())/(100.0/ArrowOffsetInPercentOfScreen);
    dprice*= 2.0;
    ObjectCreate("arr0"+ArrowIdx, OBJ_TEXT, 0, dt, FastBuffer[i]+dprice);   
    ObjectSetText("arr0"+ArrowIdx, sup, ArrowFontSize, "Wingdings", ColorArrowDown);
    ArrowIdx++;
    if(EnableLogFile)
    {
        string dts = TimeToStr(TimeCurrent(), TIME_DATE | TIME_MINUTES | TIME_SECONDS);
        FileWrite(LogFile1, dts, "  call PlotArrowDown(i) i=", i, "  FastBuffer[i]=", FastBuffer[i]);
    }
}
 
Alexey Volchanskiy:

Вот из моего индюка, может, поможет. Код для МТ4, выкладываю, как есть. Там еще работа с логами.

Thank you Alexey for your feedback!

In your example it's through objects. I wonder if it's possible to do it through arrays, so that when I change scale, they are always at the top and bottom boundaries of the window?
 
Leo59:
Alexey Volchanskiy:
Thank you Alexey for your feedback!

In your example, it is through objects. I wonder if it is possible to do it through arrays, so that when I change scale, they are always at the top and bottom of the window?

I don't understand about the arrays. See the comments, I added

ObjectCreate("arr0"+ArrowIdx, OBJ_TEXT, 0, dt, FastBuffer[i]+dprice);
// "arr0"+ArrowIdx - формируем уникальное имя стрелки
// FastBuffer[i]+dprice - тут формируется цена, на которой будет рисоваться стрелка
   
ObjectSetText("arr0"+ArrowIdx, sup, ArrowFontSize, "Wingdings", ColorArrowDown);
ArrowIdx++; // для каждой стрелки нужно уникальное имя

Further, if you need to draw on the upper border, do the following

ObjectCreate("arr0"+ArrowIdx, OBJ_TEXT, 0, dt, ChartGetDouble(0,CHART_PRICE_MAX,0); 

And you should read the editor's help; it is described here in details with examples

MQL4 Reference / Standard constants, enumerations and structures / Chart constants / Examples of working with charts

 
Alexey Volchanskiy:

I don't understand about the arrays. See the comments, I added

Further, if you need to draw on the upper border, do the following

And you should read the editor's help; it is described here in details with examples

MQL4 Reference / Standard constants, enumerations and structures / Chart constants / Examples of working with charts

Changing

WindowPriceMax() и WindowPriceMin()

Objects should be forcedly redrawn at a given distance from the window borders

 
Leo59:

With the change

objects will have to be forced to be redrawn at a given distance from the window borders

The old objects will remain in their places - at the old prices. If you need to move them to the boundaries, you will have to redraw them manually. I don't know your problem completely.

You can use OnChartEvent to track window changes.

 
Alexey Volchanskiy:

The old objects will remain in their places - at the old prices. If you need to move them to the boundaries, you have to redraw them by hand. I just don't know your task completely.

You can use OnChartEvent to track window changes.

At first glance, it seems like a simple task. BUT! ....
There is a line of any oscillator in the indicator window, which is moving relatively "0" with different amplitude.
The actual problem is:
- At "0" crossing from bottom to top, draw an arrow at the bottom border of the indicator window,
- At "0" crossing from the top downwards, to draw an arrow near the upper border of the indicator window,
- at self-scaling of the oscillator chart in the indicator window, the arrows should automatically remain at their borders of the indicator window.
I.e., scrolling the chart backwards and forwards through the history or changing its horizontal scale, the arrows always remain at the boundaries of the indicator window.
 
Leo59:
At first glance, the task seems as simple as three kopecks. BUT! ....
There is a line of any oscillator in the indicator window, which rotates relatively "0" with different amplitude.
The actual problem is:
- At "0" crossing from bottom to top, draw an arrow at the bottom border of the indicator window,
- At "0" crossing from the top downwards, to draw an arrow near the upper border of the indicator window,
- at self-scaling of the oscillator chart in the indicator window, the arrows should automatically remain at their borders of the indicator window.
I.e., scrolling the chart backwards and forwards through the history or changing its horizontal scale, the arrows always remain at the boundaries of the indicator window.

The task is and is quite simple.

When the window is changed or scrolled,OnChartEvent is called, it passes an event without parameters:

CHARTEVENT_CHART_CHANGEchart change event

If this event occurs, we determine the left and right visible bar and within these limits find all arrows in the indicator window. If it is found, we move it to the desired boundary. When creating arrows, give them names such as UpArrow***** and DownArrow***** to avoid troubles related to the analysis. Then just in case, call ChartRedraw.

Reason: