Something interesting, old thread - page 16

 

...

Doc

The answers to the last post :

10. I like the int form better. It does not take too much processing time more (OnInit() is called just once) and allows me to have some return code if necessary. So I use the int for of OnInit() always regardless of do I check for error on initialization or not

11. I do not use the reserve size since the array is going to be re sized only once per new bar (even on a 1 minute chart it is going to be a rare occasion when the array is re sized, and, if they made it as I would, than it just a simple malloc(), memcopy() and free() low level functions to do the work when the array is re sized) . The reserve size is in my opinion good only when you know the maximal size of an array that will be used, and working with chart you never know the final size.

dr.house7:
and also...

10. in your t3 indy you wrote:

int OnInit()

{

SetIndexBuffer(0,t3,INDICATOR_DATA);

SetIndexBuffer(1,colorBuffer,INDICATOR_COLOR_INDEX);

return(0);

}

but why not:

void OnInit()

{

SetIndexBuffer(0,t3,INDICATOR_DATA);

SetIndexBuffer(1,colorBuffer,INDICATOR_COLOR_INDEX);

}

11.

when you wrote:

ArrayResize(workSma,bars)

where is the third value? workSma is our array passed by reference, bars is new array size, and reserve size value (excess) where is?
 

...

and another doubt...

double averageRsi = iSma(rsi,AveragePeriod,i,rates_total);

why didn't use the buffer?

averageRsi = iSma(rsi,AveragePeriod,i,rates_total);

I thought was needed for the indicator's data

 

Doc

That was just an example You can assign the return value from a function to anything you wish : a buffer element, an array element, variable - anything

dr.house7:
and another doubt...

double averageRsi = iSma(rsi,AveragePeriod,i,rates_total);

why didn't use the buffer?

averageRsi = iSma(rsi,AveragePeriod,i,rates_total);

I thought was needed for the indicator's data
 

Mladen

I did talk referred to the creation of rsi sma indy...

mladen:
Doc That was just an example You can assign the return value from a function to anything you wish : a buffer element, an array element, variable - anything
 

...

Doc

In that case use the form you used in your example (this one :

averageRsi = iSma(rsi,AveragePeriod,i,rates_total);

It will work OK the way you wrote it too ...

dr.house7:
Mladen I did talk referred to the creation of rsi sma indy...
 

...

Mladen

Could you please reply me to those 3 questions:

1. about this part of code : iSma(rsi ...

it's like say: iSma(ExtRSIBuffer[]?

2. workSMA it's our sma buffer and you wrote:

double workSma[][2];

First square bracket is for x axis and the second for...I thought Y axis? you wrote "of which second dimension is of size 2" ...but why?

3. You wrote :

for(k=0; k=0; k++)

so for k=0, until k=0 than increase k of 1... but why r-k??? Is there any article for newbie where I can learn much better cycles?

 

...

Doc

1. Yes

2. Doc, it seems that you are thinking in space and I am thinking in abstract. I am usually bad at explaining things like these but, lets try :

let imagine we have 2 simple arrays : array 1 and array 2. Both arrays should have as much elements as there are bars on the chart. And then we would have (numbers are an index of an array)

array1 = { 0, 1, 2, 3 , ... , Bars-2, Bars-1 }

array2 = { 0, 1, 2, 3 , ... , Bars-2, Bars-1 }

So we have 2 same size arrays. Now, instead of creating array1,array2, ... arrayn, we can create an array that has the same amount of data as the above example only it is a single 2 dimensional array. And that is that 2 in the double workSma[][2] declaration : it specifies that there will be 2 same sized arrays that we shall use to our convenience

The simplicity of it is the main reason to use it. If we need more than 2 same sized arrays we simply replace the "2" with the desired number. And we access each "sub-array" with its second index : workSma[n][0] is the nth element of the first array, and workSma[n][1] would in that case be nth element of the second same sized arrays

3. the (r-k) is there since the array I use are not set as series but are the usual C/C++ like arrays (that is even the default for buffers in metatrader 5 now if you do not specify that a buffer should be "series like") What doe that mean? In an "regular" array first (oldest) element is having index 0 and the newest (current bar) would be (Bars-1). If it was set as series then the first (oldest would have the (Bars-1) and newest - current would be 0

I use that way for a number of reasons, but the main one is that metatrader (4 and 5) is very, but very slow when you re size an array that is set as series, so I decided to use the C/C++ natural way of using arrays (if they - metatrader - already claim that they are aiming towards C/C++ like language, then I decided to use C/C++ ways instead of metatrader ways)

dr.house7:
Mladen

Could you please reply me to those 3 questions:

1. about this part of code : iSma(rsi ...

it's like say: iSma(ExtRSIBuffer[]?

2. workSMA it's our sma buffer and you wrote:

double workSma[][2];

First square bracket is for x axis and the second for...I thought Y axis? you wrote "of which second dimension is of size 2" ...but why?

3. You wrote :

for(k=0; k=0; k++)

so for k=0, until k=0 than increase k of 1... but why r-k??? Is there any article for newbie where I can learn much better cycles?
 

...

PS: attaching an indicator that uses the arrays as explained in the previous post for both rsi and sma calculation and it calculates a smoothed rsi indicator. I hope that this way it will be much simpler to see what and how it is done and that, by making both the rsi and sma as function it allows us "perversions" of simply inverting the order of calculation a in a single line and we can have a completely different indicator. So if you set the Invert to true you are going to get rsi of a sma instead a smoothed rsi (here is a comparison of the 2 : upper is smoothed rsi, lower is an rsi of a sma)

Files:
 

...

thanks Mladen,

you are an excellent tutor

but why the cycle of this is incorrect?

Files:
try_2.mq5  4 kb
 

...

Doc

If you are referring to the "possible loss of data" warning it is because you declared SmAperiod as double and iSma expects the SmaPeriod to be integer. Change the type of SmaPeriod to int and there will be no warning

As of the rest - you are calculating 2 things : a simple moving average and an rsi. You are not calculating neither smoother rsi nor rsi of an average. If you want a sma of an rsi then the code should be like this :

rsi = iRsi(price,RsiPeriod,i,rates_total);

sma = iSma(rsi ,SmaPeriod,i,rates_total);

All this provided that I do understand what are you trying to achieve

dr.house7:
thanks Mladen, you are an excellent tutor but why the cycle of this is incorrect?
Reason: