Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 134
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
There is a problem with the Expert Advisor in the tester. I am testing on 1-minute data. I calculate the stochastic for the higher TF by myself using the minute data.
The history of minutes has been downloaded since 2001. In the "Charts" tab set the maximum number of bars in the history, and displayed.
The whole history on the chart is scrolled.
The problem is that, as it turned out with the debug print, no matter from what date I start the tester, the maximum number of bars
in the Bars variable on the first bar of the test (at the start) is always 1001 or 1002. The value of Bars increases by 1 with every next bar.
Therefore, it is impossible to count the higher TFs at the start.
There is one solution. We should add a ban on trading before Bars reaches the desired value.
Can we solve this problem in another way? Does this start value of Bars in the tester increase somehow?
There is a problem with the Expert Advisor in the tester. I am testing on 1-minute data. I calculate the stochastic for the higher TF by myself using the minute data.
The history of minutes has been downloaded since 2001. In the "Charts" tab set the maximum number of bars in the history, and displayed.
The whole history on the chart is scrolled.
The problem is that, as it turned out with the debug print, no matter from what date I start the tester, the maximum number of bars
in the Bars variable on the first bar of the test (at the start) is always 1001 or 1002. The value of Bars increases by 1 with every next bar.
Therefore, it is impossible to count the higher TFs at the start.
There is one solution. We should add a ban on trading before Bars reaches the desired value.
Can we solve this problem in another way? Does this start value of Bars in the tester increase somehow?
P.S. I pressed the compile button.
I really need to understand the algorithm for calculating the smoothed moving average. There are several reasons why the iMA function is not suitable.
As I understood the information from https://www.metatrader5.com/ru/terminal/help/indicators/trend_indicators/ma#smma
The first element is calculated as the sum of closing prices divided by the period.
The following ones are calculated according to the formula SMMA (i) = (SMMA (i - 1) * (N - 1) + CLOSE (i)) / N.
Let's take a period of 5 and the closing prices of EUR/USD H1 for the period from 24.02.2017 19:00 to 24.02.2017 23.00 (GMT+2) i.e. last 5 candles
The closing prices are 1.05681; 1.05702; 1.05639; 1.05612; 1.05592.
Correspondingly, 1st element - 1.056452; 2nd element - 1.056852 3rd element - 1.05676 4th element - 1.056632 5th element - 1.056489
But on the SMMA 5 chart, close is 1.05706, i.e. the difference is already in the 3rd digit
What am I counting wrong?
And how shall I calculate correctly in order to get 1.05706?
I really need to understand the algorithm for calculating the smoothed moving average. There are several reasons why the iMA function is not suitable.
As I understood the information from https://www.metatrader5.com/ru/terminal/help/indicators/trend_indicators/ma#smma
The first element is calculated as the sum of closing prices divided by the period.
The following ones are calculated according to the formula SMMA (i) = (SMMA (i - 1) * (N - 1) + CLOSE (i)) / N.
Let's take a period of 5 and the closing prices of EUR/USD H1 for the period from 24.02.2017 19:00 to 24.02.2017 23.00 (GMT+2) i.e. last 5 candles
The closing prices are 1.05681; 1.05702; 1.05639; 1.05612; 1.05592.
Correspondingly, 1st element - 1.056452; 2nd element - 1.056852 3rd element - 1.05676 4th element - 1.056632 5th element - 1.056489
But on the SMMA 5 chart, close is 1.05706, i.e. the difference is already in the 3rd digit
What am I counting wrong?
And how shall I calculate correctly in order to get 1.05706?
Gentlemen Developers! Good day to all. I am interested in the question of creating a template for an Expert Advisor (script) when creating it. Can it be edited somewhere and how is it done?
Look at the indicator itself, it will make more sense.
double SMMA(int period)
{
//fill array with closing prices
int k=period;
for(int i=1; i<=period; i++)
{
H1_Close[i]=Close[k];
// Print("H1_Close [",i,"] ",H1_Close[i]," Close [",k,"] ",Close[k]);
k--;
}
//calculate the first element as the average closing price
double Summ=0;
for (int i=1; i<=period;i++)
Summ=Summ+H1_Close[i]; //SUM1 = SUM(CLOSE, N)
double TmpSMMA=Summ/period; //SMMA1 = SUM1/N
//calculate the i-th element as SMMA (i) = (SMMA (i - 1) * (N - 1) + CLOSE (i)) / N
for(int i=2;i<=period;i++)
TmpSMMA=(TmpSMMA*(period-1)+H1_Close[i])/period;
}
The result is still much different from the indicator data in the terminal. WHY ?
I really need to understand the algorithm for calculating the smoothed moving average. There are several reasons why the iMA function is not suitable.
As I understood the information from https://www.metatrader5.com/ru/terminal/help/indicators/trend_indicators/ma#smma
The first element is calculated as the sum of closing prices divided by the period.
The following ones are calculated according to the formula SMMA (i) = (SMMA (i - 1) * (N - 1) + CLOSE (i)) / N.
Let's take a period of 5 and the closing prices of EUR/USD H1 for the period from 24.02.2017 19:00 to 24.02.2017 23.00 (GMT+2) i.e. last 5 candles
The closing prices are 1.05681; 1.05702; 1.05639; 1.05612; 1.05592.
Correspondingly, 1st element - 1.056452; 2nd element - 1.056852 3rd element - 1.05676 4th element - 1.056632 5th element - 1.056489
But on the SMMA 5 chart, close is 1.05706, i.e. the difference is already in the 3rd digit
What am I counting wrong?
And how shall I calculate correctly in order to get 1.05706?
There is a calculation algorithm in the inluder.
I wrote the code of the function in Vitaly Muzichenko's answer, but I can't figure out what the error is
So I seem to be doing everything as in the calculations, but the result does not come out. I'm sitting here for the 4th day and can't figure it out.
I wrote the code of the function in Vitaly Muzichenko's answer, but I can't figure out what the error is