Errors, bugs, questions - page 3032

 
Andrey Dik:

Thank you, Andrew. You are the only one who has fully understood the question.


Now everything is working as intended, the indicators have fully calculated only once during the first run and then only once each time on their new bar.


The final code of the second indicator will hopefully be useful to someone:

Here is the beginning of what you should have thought of

Forum on trading, automated trading systems and strategy testing

Bugs, bugs, questions

Alexey Viktorov, 2021.05.28 08:36

What is this check for?

//проверка готовности данных и индикатора на другом TF
if (SeriesInfoInteger (Symbol (), tf, SERIES_SYNCHRONIZED))
{
  if (iBars (Symbol (), tf) != BarsCalculated (handleFr)) return 0;
}
else return 0;

It would be easier to write return 0; without any conditions...

At every new bar the condition will be fulfilled and all the bars will be recalculated, regardless of synchronization. You have written an ill-considered code and pretend that it is a terminal bug...


And Igor Makanu said this even earlier...
 

I would like to remind you.

1. For each symbol, for which at least one chart is open, there is a separate thread for processing incoming ticks. Several charts for some symbol can be open, but there will still be only one thread.

2. The symbol thread handles timeseries, not charts. That is, the very same data arrays, which are submitted to the CopyRates request.

3. it is useless to ask your symbol in OnTick or OnCalculate, if it is synchronized. Of course it is!

4. All timeseries are handled in order, from lowest to highest. First of all, the tick is applied, and then the calculation of all indicators, created on this timeseries. If you ask data for the same H1 symbol from the indicator, working on M1, you will never get data with the applied tick. The data will always be one tick back, no matter what tricks you apply. Because one thread per symbol with consecutive timeframe processing.

5. The previous statement does not apply to EAs and scripts, because EAs and scripts each work in their own separate threads.

 
Slava:

I would like to remind you.

1. For each symbol, for which at least one chart is open, there is a separate thread for processing incoming ticks. Several charts for some symbol can be open, but there will still be only one thread.

2. The symbol thread does not process charts, but timeseries. That is, the very same data arrays, which are submitted to the CopyRates request.

3. it is useless to ask your symbol in OnTick or OnCalculate, if it is synchronized. Of course it is!

4. All timeseries are handled in order, from lowest to highest. First of all, the tick is applied, and then the calculation of all indicators, created on this timeseries. If you ask data for the same H1 symbol from the indicator, working on M1, you will never get data with the applied tick. The data will always be one tick back, no matter what tricks you apply. Because one thread per symbol with consecutive timeframe processing.

5. The previous statement doesn't concern Expert Advisors and scripts, because Expert Advisors and scripts work in their own separate threads.

Please send me more detailed reminders like this! Thank you!

 
Slava:

I would like to remind you.

4. All timeseries are processed in order, from the lowest to the highest. First the tick application, then the calculation of all indicators created on this timeseries. If you are asking for data for the same H1 symbol from an indicator, working on M1, you will never get data with an applied tick. The data will always be one tick back, no matter what tricks you apply. Because one thread per symbol with consecutive timeframe processing.

5. The previous statement does not apply to EAs and scripts, because EAs and scripts work each in its own separate thread.

Am I following correctly, if an EA working on M1 uses an indicator on M1 (or any other TF?) that takes data from the upper TF, then on the first tick of a new bar it will not be able to return the actual value in any case, because the queue for calculating the upper TF will reach it after n ticks?

I simply faced with such behaviour and was searching for a problem in the indicator, and now it turns out that it should be so. But if it is so, it strongly interferes with testing because I have to skip several ticks, which is critical when testing in OHLC mode.

 
Slava:

2. Symbol stream does not process graphs, but timeseries. That is, the very data arrays that are given to the CopyRates request

....

4. All timeseries are processed in order, from lowest to highest. First the application of the tick, then the calculation of all indicators, created on this time series. If you are asking for data for the same H1 symbol from an indicator, working on M1, you will never get data with an applied tick. The data will always be one tick back, no matter what tricks you apply. Because one thread per symbol with consecutive timeframe processing.

Why do I get black "Update" screens when I switch TFs?

opened the chart I was using before (H1 on EURUSD), left the indicator, did nothing for 2-3 minutes, then switch to a lower chart (M30...M1), black screen "Update" may appear for 10 seconds

and this black screen depends on the build - when the terminal is without a black screen, and when it really annoys me, because you know exactly what history is loaded, you just need to render a chart to the terminal, and why wait for this black screen


i.e. if the indicator is running on M5 and every 30 minutes calls the indicator on H1 - will CopyBuffer() always get the correct data from H1 ?

or not a fact, therefore "pull the indicator" on H1 every tick(breakage of the connection is not considered yet)

 

how to handle variables from one loop/function in another function?

can visibility be made more global?

 
Igor Makanu:

why do black "Update" screens appear when switching TFs?

I opened the chart I used before (H1 on EURUSD), threw the indicator, did nothing for 2-3 minutes, then I switch to a lower chart (M30...M1) and a black screen "refresh" may appear for 10 seconds

and this black screen depends on the build - when the terminal is without a black screen, and when it really annoys me, because you know exactly what history is loaded, you just need to render a chart to the terminal, and why wait for this black screen


i.e. if the indicator is running on M5 and every 30 minutes calls the indicator on H1 - will CopyBuffer() always get the correct data from H1 ?

or not a fact, therefore "pull the indicator" on H1 every tick(we don't consider the connection breakage variants yet)

I think, based on Slava's words, that it's not a fact.

Since all calculations are performed only on the tick, the chain of tied indicators may not be completed and we will have to wait for the next tick.

But there are some interesting problems, the answers to which I haven't found in the documentation.

What to do, when ticks don't occur (for example, at weekend)? If you place an indicator, that works in the current timeframe, it will be drawn without problems, and what is interesting - it doesn't need a tick to be received! But if the indicator requests data from another timeframe, it won't do anything until a new tick comes, and there is no tick coming - weekend!

If we call ChartRedraw (ChartID ()) in the timer, then for certain Comment (cnt); wherecnt is incremented by 1, we see that cnt is working properly on the screen, but the indicator is not drawn.

When I refresh the screen with Refresh button from the context menu, the indicator is redrawn from the beginning to the end.

But as soon as you refresh the screen with Update from the context menu, the indicator is happily drawn from the beginning to the end.


HH Your example of the second indicator works, but the Expert's code is faster.

 
Andrey Dik:

what to do when there are no ticks (weekend for example)? if you put an indicator working on the current TF, it will be drawn without problems, and what is interesting - the arrival of a tick is not required for this!

it is not necessary

when you draw the indicator on the chart, there is a strictly defined sequence of calls: OnInit() and immediately OnCalculated(). i.e. the first OnCalculated() is called before the tick receipt, that is why prev_calc needs to be compared with 0. At the tick receipt or connection with the server OnCalculated() will be called again andprev_calc will be equal to zero

Andrey Dik:

It turns out that ChartRedraw () and Update by button are not the same thing, even though I can think otherwise.

most likely you should use ChartSetSymbolPeriod() with parameters NULL and current period, should help

 
Igor Makanu:

Most likely you should use ChartSetSymbolPeriod() with parameters NULL and current period, should help

ChartSetSymbolPeriod

The ChartSetSymbolPeriod call with the same symbol and timeframe can be used to refresh the chart (similar to Refresh command in the terminal). Chart refresh, in its turn, triggers recalculation of indicators attached to it. Thus, you can recalculate the indicator on the chart even when there are no ticks (eg weekends).

it helped. also, as i remember now, ac Pushkin used to say:

Oh, how many wondrous discoveries
Prepareourenlightened spirit
And experience, the son of hard errors,
And genius, the friend of paradoxes,
And chance, God the inventor.

 
Andrey Dik:


What to do when ticks don't come (for example, weekends)? If the indicator works in the current timeframe, it will be drawn without problems, and what is interesting - it doesn't need a tick to come! But if the indicator requests data from another timeframe, it cannot do anything until a new tick comes, and it is not coming - weekends!


From the other timeframe the data will be obtained that is ready at the moment. So, in the output all data will be perfectly synchronized

Reason: