Questions from Beginners MQL5 MT5 MetaTrader 5 - page 850

 
Artyom Trishkin:
Correct the curve indicator. It may draw a line only at full recalculation, which is done by context menu command.
Alexey Viktorov:

There is one in mql4 as well.

Thank you.

 
Got it out with a crutch). I wanted the indicator to update after manually dragging the vertical line, from which it takes the time. I used the event function of dragging an object and put in it the function of change of TF with return to initial one. But for some reason the update is delayed, about several seconds. The function of TF switching works so slowly, I don't understand.
 
khorosh:
Worked it out with a crutch). I needed to update the indicator after manual dragging of a vertical line, from which it takes the time. I used the function of dragging an object and put in it the function of changing TF with a return to the initial one. But for some reason the update is delayed, about several seconds. The function of TF switching is too slow, I don't understand it.

This function is asynchronous. It only returns the result of the command in the event queue.

To update immediately, you need to execute the ChartRedraw() command after the chart switch command

This is, of course, a wrong approach. If you want to update the chart only after the completion of line shift, the loop of indicator recalculation should be called not from OnCalculate() but from ChartEvent() - the shift of the line is caught - the function of indicator recalculation is called, which will run the whole cycle of line recalculation with the new data (the line is needed for some data, isn't it?).

Or the indicator simply is not made correctly and does not update the zero bar on the current data, and you kicked it?

 
ilyav:

Can anyone help to fix EA code on MT5?

I've read the manuals, but I can't beat 2 varnings when compiling.

declaration of 'xxxx ' hides global declaration

и

possible loss of data due to type conversion

See attached tip.

I just stupidly fixed the global variable names and made the types match.

That's 10,000,000 you can charge - for overcoming your laziness.

Files:
 
Artyom Trishkin:

Just bluntly corrected the global variable names and brought the types in line.

You owe me 10 000 000 for overcoming your laziness.

Thank you very much.

I'm ashamed to show how I fixed it)

int CountTrades(long PositionID1)

 
Artyom Trishkin:

This function is asynchronous. It only returns the result of the command in the event queue.

To update immediately, you need to execute the ChartRedraw() command after the chart switch command

This is, of course, a wrong approach. If you need to update the chart only after the completion of line shift, the loop of indicator recalculation should be called not from OnCalculate() but from ChartEvent() - the shift of the line is caught - the function of indicator recalculation is called, which will perform the whole cycle of line recalculation with the new data (the line is needed for some data, isn't it?).

Or maybe the indicator was simply made incorrect and it does not update zero bar on current data and you fucked it up?

The indicator counts the last non-calculated bars. And after dragging the vertical, it should recalculate completely after reading the new vertical time. I wrote about it here and added screenshots of how it works.

Thanks, I will try to implement your idea. I am generally not very good with indicators, I have been dealing with Expert Advisors mostly.

 
Artyom Trishkin:

This function is asynchronous. It only returns the result of the command in the event queue.

To update immediately, you need to execute the ChartRedraw() command after the chart switching command

This is, of course, a wrong approach. If you want to update the chart only after the completion of line shift, the loop of indicator recalculation should be called not from OnCalculate() but from ChartEvent() - shift of the line - call indicator recalculation function, which will run the entire cycle of line recalculation with the new data (the line is needed for some data, right?).

Or maybe the indicator is just not made correctly and does not update the zero bar on the current data, and you kicked it?

Did as you advised. Everything worked perfectly. Now instantaneously after dragging the indicator is completely redrawn. Thanks again.

 
khorosh:

I did as you advised. Everything worked perfectly. Now instantly after dragging the indicator is completely redrawn. Thanks again.

You're welcome. But it should be drawn in OnCalculate(), or no?

When it is dragged on a chart, the indicator is not aware of any changes of the line, but it should draw the line.

 
Artyom Trishkin:

You're welcome. But it should draw in OnCalculate(), or not?

When you apply it to a chart, it is not aware of any movements of the line, but it should draw the line.

When the indicator is attached to the chart, a vertical line is created in init() and some time is initially set for it, for example Time[10]. I have duplicated the code inOnChartEvent() and OnCalculate(). Only in OnChartEvent I recalculated by all bars.

 
khorosh:

When installing the indicator on the chart in init() a vertical line is created and initially it is set to some time, for example Time[10]. I duplicated the code in OnChartEvent() and OnCalculate(). Only in OnChartEvent I recalculated by all bars.

Wouldn't it be better to simply create the Refresh() function, for example, with the required formal parameters, and call it when necessary?

And by the way, when getting the rates_total in the indicator beyond OnCalculate() using Bars() with a date range, you can catch a hang of the indicator:

Forum on trading, automated trading systems and trading strategy testing

Analog of iBarShift

Nikolai Semko, 2018.04.05 23:47

So far this variant, but I now want to add it to bypass this bug of Bars function hangups, about which I have already written to servicedesk.

The essence of this bug is that if in Bars function bothstart_time andstop_time are inside one bar or are in the future (to the right of zero bar), then this function hangs for more than 10 seconds.

Maybe I'll make a proper faster but more cumbersome version later.


Reason: