This is for M15. Every N minutes is a variable, for M15 there are 96. I would like a nice code instead of this mess.
Use arrays and for loop. If the question is to programmatically create a new variable every e.g. Every 5 minutes, for example, to programmatically create a new variable, then there is no such possibility.
001: That's why I'm asking, because I'm racking my brain on how to do it.
int MASS_LOW []; // объявляем массивint quantity=96; // количество_лоу, можно изменять в программе и делать заново ресайз массиваArrayResize(MASS_LOW,quantity); // размер масиива = количество_лоуArrayFill(MASS_LOW,0,quantity,0); // обнуление массива при необходмостиfor(cnt=0; cnt<quantity; cnt++) // перебираем количество_лоу (от 0 до 95)
{
int c=(cnt+1)*15; // 15 30 45 60 ....if (time_low == c) MASS_LOW [cnt]=MASS_LOW [cnt]++; // сравниваем время_лоу и увеличиваем при необходимости ячейку массива
}
or immediately without comparing and overriding, just enlarging the desired cell:
Dear gurus, please, help me to understand my newbie's confusion!
I am trying to understand how indicators written in MT4 work. I expect that indicators are calculated based on bars, i.e. if I set Period (=) 13 in Custom Moving Average indicator parameters, it is about averaging over 13 bars of the appropriate chart.
But I don't see any event handler like OnBar, only OnTick. It means that (my) indicator should automatically "form" bars from ticks by grouping them, say, by minutes (for servicing the chart M1)?
I look in the code of a ready-made indicator Custom Moving Average - it doesn't have OnTick ... The appropriate Calculate event in the manual says:"The Calculateevent is generated only for indicators [...] and at any change of price data". In other words, OnCalculate responds to each tick?
Dear gurus, please, help me to understand my newcomer's confusion!
I am trying to understand how indicators written in MT4 work. I expect that indicators are calculated based on bars, i.e. if I set Period (=) 13 in Custom Moving Average indicator parameters, it is about averaging over 13 bars of the appropriate chart.
But I don't see any event handler like OnBar, only OnTick. It means that (my) indicator should automatically "form" bars from ticks by grouping them, say, by minutes (for servicing the chart M1)?
I look in the code of a ready-made indicator Custom Moving Average - it doesn't have OnTick ... The appropriate Calculate event in the manual says:"The Calculateevent is generated only for indicators [...] and at any change of price data". In other words, OnCalculate responds to each tick?
To every tick if you use Close[0]. You can use Close[1] or Open[0], then you will see the changes only when the bar changes.
fxseminar: -- sorry, theCustom Moving Average indicatorCANNOT average over ticks. How would it work (look) then on a daily timeframe, for example - can you imagine?
It's OK, only the zero (unfinished) bar is recalculated. But it is the bars, the prices of the bars, that are being averaged. If you set appled_price -- PRICE_CLOSE, it will read the close prices of the bars, but not all ticks.
Generally speaking, on an unfinished bar, the close price is equal to the Bid price and, if this price changes, the indicator will summarize 13 price values and divide them by 13. Not long at all...
double iMA( stringsymbol, // имя символа int timeframe, // таймфрейм int ma_period, // период intma_shift, // сдвиг средней intma_method, // метод усреднения intapplied_price, // тип цены intshift// сдвиг
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.
You can use arrays and functions
That's why I'm asking you, I'm racking my brain on how to do it.
So far, only generalities have been talked about.
You can't do it without specifics.
Bring me the code that has racked my brain
So far we've only talked about the general.
It won't work without specifics.
Give me the code that broke my head
This is for the M15. Every N minutes is a variable, for M15 there are 96 of them. I would like to get a beautiful code instead of this disgrace.
This is for M15. Every N minutes is a variable, for M15 there are 96. I would like to get a nice code instead of this mess.
To make the right decision, you need to understand what you want to get
This is for M15. Every N minutes is a variable, for M15 there are 96. I would like a nice code instead of this mess.
That's why I'm asking, because I'm racking my brain on how to do it.
or immediately without comparing and overriding, just enlarging the desired cell:
Dear gurus, please, help me to understand my newbie's confusion!
I am trying to understand how indicators written in MT4 work. I expect that indicators are calculated based on bars, i.e. if I set Period (=) 13 in Custom Moving Average indicator parameters, it is about averaging over 13 bars of the appropriate chart.
But I don't see any event handler like OnBar, only OnTick. It means that (my) indicator should automatically "form" bars from ticks by grouping them, say, by minutes (for servicing the chart M1)?
I look in the code of a ready-made indicator Custom Moving Average - it doesn't have OnTick ... The appropriate Calculate event in the manual says:"The Calculateevent is generated only for indicators [...] and at any change of price data". In other words, OnCalculate responds to each tick?
Dear gurus, please, help me to understand my newcomer's confusion!
I am trying to understand how indicators written in MT4 work. I expect that indicators are calculated based on bars, i.e. if I set Period (=) 13 in Custom Moving Average indicator parameters, it is about averaging over 13 bars of the appropriate chart.
But I don't see any event handler like OnBar, only OnTick. It means that (my) indicator should automatically "form" bars from ticks by grouping them, say, by minutes (for servicing the chart M1)?
I look in the code of a ready-made indicator Custom Moving Average - it doesn't have OnTick ... The appropriate Calculate event in the manual says:"The Calculateevent is generated only for indicators [...] and at any change of price data". In other words, OnCalculate responds to each tick?
For each tick, if you use Close[0]. You can use Close[1] or Open[0], then you will see the change only when you change the bar.
-- sorry, theCustom Moving Average indicatorCANNOT average over ticks. How would it work (look) then on a daily timeframe, for example - can you imagine?
It's OK, only the zero (unfinished) bar is recalculated. But it is the bars, the prices of the bars, that are being averaged. If you set appled_price -- PRICE_CLOSE, it will read the close prices of the bars, but not all ticks.
Generally speaking, on an unfinished bar, the close price is equal to the Bid price and, if this price changes, the indicator will summarize 13 price values and divide them by 13. Not long at all...
double iMA(
string symbol, // имя символа
int timeframe, // таймфрейм
int ma_period, // период
int ma_shift, // сдвиг средней
int ma_method, // метод усреднения
int applied_price, // тип цены
int shift // сдвиг
);