Learning and writing together in MQL5 - page 9

 
gdtt:

the advisor uses

value from the 0th bar is taken, the values of indicator buffers for it are changed on every tick until the close of the candle.

That's right, I experimented, but in essence it does not solve the main problem.-- How to make an EA recalculate the indicator buffer not only on the requested bar, but also several bars backwards

Усреднение ценовых рядов без дополнительных буферов для промежуточных расчетов
Усреднение ценовых рядов без дополнительных буферов для промежуточных расчетов
  • 2010.10.25
  • Nikolay Kositsin
  • www.mql5.com
Статья о традиционных и не совсем традиционных алгоритмах усреднения, упакованных в максимально простые и достаточно однотипные классы. Они задумывались для универсального использования в практических разработках индикаторов. Надеюсь, что предложенные классы в определенных ситуациях могут оказаться достаточно актуальной альтернативой громоздким, в некотором смысле, вызовам пользовательских и технических индикаторов.
 

A solution may have been found! One of them is...

For this, however, you have to make a special version of the indicator.

 

Gentlemen,

I'm writing an indicator: ...
int handle;
double indicatorBuffer[];
...
int OnInit()
{
... handleMA = iMA(_Symbol, _Period, periodMA, shiftMA, MODE_SMA, AppPrice);
...
}

int OnCalculate (const int rates_total, // size of array price[]
const int prev_calculated, // processed bars at previous call
const int begin, // where significant data start
const double& price[]) // array for calculation
{
... doing something

Question is - how to let handleMA = iMA(_Symbol, _Period, periodMA, shiftMA, MODE_SMA, AppPrice) know what is AppPrice?
or how to extract Apply to: from the Parameters tab to use in the code?

Thanks in advance...

 
FlyAgaric:

Gentlemen,


The question is - how to let handleMA = iMA(_Symbol, _Period, periodMA, shiftMA, MODE_SMA, AppPrice) know what is AppPrice?
or how to extract Apply to: from the Parameters tab for use in the code?

Thank you in advance...

See OnCalculate():

Selection of a necessary time series or indicator as the price[] array is performed by a user when starting the indicator in the "Parameters" tab. To do this, you should specify the necessary item in the drop-down list of "Apply to" field.

For receiving values of a custom indicator from other mql5 programs, the iCustom() function is used, it returns the indicator handle for subsequent operations. You can also specify the appropriate price[] array or the handle of another indicator. This parameter should be passed last in the list of input variables of the custom indicator.
 
Rosh:

See OnCalculate():


Rosh thanks, but my question is exactly that. What should I specify in operator
handleMA = iMA(_Symbol, _Period, periodMA, shiftMA, MODE_SMA, AppPrice)
as AppPrice?

I'm reading the available help very carefully. Perhaps the heat has taken its toll, but ...

 
FlyAgaric:

Rosh thanks, but my question is exactly that. What should I specify in the statement
handleMA = iMA(_Symbol, _Period, periodMA, shiftMA, MODE_SMA, AppPrice)
as AppPrice?

I read the available help very carefully. Perhaps the heat has taken its toll, but ...

Specify an indicator handle, if you want to calculate on data of another indicator. Or the type of prices on which the indicator will be calculated.
 
FlyAgaric:

Rosh thanks, but my question is exactly that. What should I specify in the statement
handleMA = iMA(_Symbol, _Period, periodMA, shiftMA, MODE_SMA, AppPrice)
as AppPrice?

I read the available help very carefully. Perhaps the heat has taken its toll, but ...

Heat. You should specify ENUM_APPLIED_PRICE as AppPrice)
input ENUM_APPLIED_PRICE AppPrice=PRICE_CLOSE;
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы - Документация по MQL5
 
Swan:
Heat. You should specify ENUM_APPLIED_PRICE as AppPrice)

Swan, thank you for your attention. But if you use
input ENUM_APPLIED_PRICE AppPrice=PRICE_CLOSE; and the first form

int OnCalculate (const int rates_total, // size of array price[]
const int prev_calculated, // processed bars at previous call
const int begin, //where significant data begin
const double& price[]) // array for calculation
We get a warning message at compilation: Two OnCalculate functions are defined. Price data function will be used NameIndicator.mq5 (pg)
and price[] array remains untied to AppPrice in any way, unless it is the same as Apply to: in the third tab "Parameters".

The question, in fact, is whether the built-in single-buffer indicators like iMA() and the first intCalculate() form can be used, if price[] array is somehow
used in calculations.

 
Rosh:
Specify the indicator handle if you want to calculate on data of another indicator. Or type of prices on which the indicator will be calculated.

We (rather me) have some misunderstanding.

The question, in fact, is whether we can use built-in single-buffer indicators like iMA() and the first form of int OnCalculate(), if price[] array is somehow
used in calculations.

 
FlyAgaric:

We (rather me) have some misunderstanding.

The question, in fact, is whether one can use built-in one-buffer indicators of iMA() type and the first form int OnCalculate() if the price[] array is somehow
used in calculations.

YourAppPrice parameter has nothing to do with OnCalculate().

int OnInit()
{
... handleMA = iMA(_Symbol, _Period, periodMA, shiftMA, MODE_SMA, AppPrice);
...
}

You can either give it the value of one of the price constants (option 1) or the handle of some other indicator (option 2). And then you can:

1st variant.

In the OnCalculate() function of the second type

int OnCalculate (const int rates_total,      // размер входных таймсерий
                 const int prev_calculated,  // обработано баров на предыдущем вызове
                 const datetime& time[],     // Time
                 const double& open[],       // Open
                 const double& high[],       // High
                 const double& low[],        // Low
                 const double& close[],      // Close
                 const long& tick_volume[],  // Tick Volume
                 const long& volume[],       // Real Volume
                 const int& spread[]         // Spread
   );

call for all necessary data and perform the calculation

2nd variant.

Use OnCalculate() of any kind as required by the code and use CopyBuffer() to obtain indicator values.