Something interesting, old thread - page 15

 

thanks for the lesson,

I have a lot of questions to make it but I will not bother you more than this...

About the main question I made in the last post, how is it possible have in one indicator rsi and sma working together with sma that take previous data of the rsi? I mean something like this in one indy:

Files:
rsi_sma.png  66 kb
 

...

Doc

You must have SMA as function for that

The problem is that you can not call an already built custom indicator that can be applied to other indicators (like the T3 from few posts ago) ant "tell" it to use your data for calculation. So the only solution is to have SMA as a function that will take rsi value as an argument for calculating average

PS: don't worry about the questions. It seems to be a serious lack of people willing to answer questions about metatrader 5 coding, so we might as well fill the gap at least a bit

dr.house7:
thanks for the lesson,

I have a lot of questions to make it but I will not bother you more than this...

About the main question I made in the last post, how is it possible have in one indicator rsi and sma working together with sma that take previous data of the rsi? I mean something like this in one indy:
 

so I need to handle both and than...sorry I don't know how proceed during the calculation, and seems other persons had this kind of problem (without solution)

Handle of a Buffer? - MQL5 forum

mladen:
Doc

You must have SMA as function for that

The problem is that you can not call an already built custom indicator that can be applied to other indicators (like the T3 from few posts ago) ant "tell" it to use your data for calculation. So the only solution is to have SMA as a function that will take rsi value as an argument for calculating average

PS: don't worry about the questions. It seems to be a serious lack of people willing to answer questions about metatrader 5 coding, so we might as well fill the gap at least a bit
 

Something like this (I assume you have a value of rsi in a buffer)

The function :

double workSma[][2];

double iSma(double price, int period, int r,int bars, int instanceNo=0)

{

if (ArrayRange(workSma,0)!= bars) ArrayResize(workSma,bars); instanceNo *= 2; int k;

//

//

//

//

//

workSma[r] = price;

if (r>=period)

workSma[r] = workSma[r-1]+(workSma[r]-workSma[r-period])/period;

else { workSma[r] = 0; for(k=0; k=0; k++) workSma[r] += workSma[r-k];

workSma[r] /= k; }

return(workSma[r]);

}

[/PHP]

and how would it be used :

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

rsi[shift] should contain current rsi value, i is the counter, rates_total is there instead of Bars() (it is faster to pass it like that then to call a built in function)

dr.house7:
so I need to handle both and than...sorry I don't know how proceed during the calculation, and seems other persons had this kind of problem (without solution) Handle of a Buffer? - MQL5 forum
 

Something more complicated no eh?

For example why you're not using an include MovingAverages.mqh?(just to call SimpleMA)

why workSma has number 2?

what's instanceNo? and why instanceNo= 0*2?

mladen:
Something like this (I assume you have a value of rsi in a buffer)

The function :

double workSma[][2];

double iSma(double price, int period, int r,int bars, int instanceNo=0)

{

if (ArrayRange(workSma,0)!= bars) ArrayResize(workSma,bars); instanceNo*= 2; int k;

//

//

//

//

//

workSma[r] = price;

if (r>=period)

workSma[r] = workSma[r-1]+(workSma[r]-workSma[r-period])/period;

else { workSma[r] = 0; for(k=0; k=0; k++) workSma[r] += workSma[r-k];

workSma[r] /= k; }

return(workSma[r]);

}

[/PHP]

and how would it be used :

[PHP]double averageRsi = iSma(rsi,AveragePeriod,i,rates_total);
rsi[shift] should contain current rsi value, i is the counter, rates_total is there instead of Bars() (it is faster to pass it like that then to call a built in function)
 

...

:):)

1. When metatrader 5 started I was burnt buy their onArray moving averages (it took me a some time to understand that it was not an error in my code but an error in the onArray averages) From then on I decided not to use their "custom" functions. Nothing personal, but this way I know what am I doing and if there is something to fix who is to blame instead of scratching my head while looking for errors in someone else code (remeber the iSmaOnArry problem you had?)

2. instanceNo is there for cases when you want to calculate more than one average. So first average (let say of rsi) would have an instance No 0 (first in the usual C like coding) average of let say momentum would have instance No 1 , ... and so on

3. workSma has number 2 since it is a 2 dimensional array of which second dimension is of size 2 (each instance of sma calculating needs 2 arrays in order to calculate sma using the optimal speed calculation - it is not looping except for the first "period" bars, after that there is no looping in calculation at all, so, as an example, avarage 2 and average 1000 take same time for calculation). All in all it is almost the same as if you would have array1, array2, array3, array4, and so on, but in simpler way and much easier to code for multiple instances

4. With instanceNo *= 2; it makes sure that the correct arrays are referenced in calculation. The only "bad thing" about this way of using arrays is that you have to know up front how many instances are you going to have. Some "dynamic" solution is not possible since even in metatrader 5 only the first dimension of array can be dynamic, all the other dimensions must be fixed

dr.house7:
Something more complicated no eh?

For example why you're not using an include MovingAverages.mqh?(just to call SimpleMA)

why workSma has number 2?

what's instanceNo? and why instanceNo= 0*2?
 

:)

1. ok

2. instanceNo = averageNo?

3. when I must specify this dimensional array no.? How could I know the right number? Is it possible only 1 and 2 (2 is x,y axis) Am I right?

4. How calculate instances? How could I calculate the size of each array???

about this line:

double iSma(double price, int period, int r,int bars, int instanceNo=0)

Is there a guide to write this or you simply decide position of each argument(price, period etc.)

and another question...k is always =0 at begin, am I right?

mladen:
:):):)

1. When metatrader 5 started I was burnt buy their onArray moving averages (it took me a some time to understand that it was not an error in my code but an error in the onArray averages) From then on I decided not to use their "custom" functions. Nothing personal, but this way I know what am I doing and if there is something to fix who is to blame instead of scratching my head while looking for errors in someone else code (remeber the iSmaOnArry problem you had?)

2. instanceNo is there for cases when you want to calculate more than one average. So first average (let say of rsi) would have an instance No 0 (first in the usual C like coding) average of let say momentum would have instance No 1 , ... and so on

3. workSma has number 2 since it is a 2 dimensional array of which second dimension is of size 2 (each instance of sma calculating needs 2 arrays in order to calculate sma using the optimal speed calculation - it is not looping except for the first "period" bars, after that there is no looping in calculation at all, so, as an example, avarage 2 and average 1000 take same time for calculation). All in all it is almost the same as if you would have array1, array2, array3, array4, and so on, but in simpler way and much easier to code for multiple instances

4. With instanceNo *= 2; it makes sure that the correct arrays are referenced in calculation. The only "bad thing" about this way of using arrays is that you have to know up front how many instances are you going to have. Some "dynamic" solution is not possible since even in metatrader 5 only the first dimension of array can be dynamic, all the other dimensions must be fixed
 

2. yes

3. at design time : you must know how many different averages are you going to use. It is not possible to have just 1 and 2 since each instance has to have 2 arrays just for itself. So the number 2 should be replaced with planedInstances * 2 for sma

4. you do not have to calculate the size of each array nor do you have to know it. All you have to know is a total number of arrays. The rest is dne by ArrayResize() when the array size is different than the number of bars on chart

Abot k : yes, it is a standard loop

dr.house7:
:)

1. ok

2. instanceNo = averageNo?

3. when I must specify this dimensional array no.? How could I know the right number? Is it possible only 1 and 2 (2 is x,y axis) Am I right?

4. How calculate instances? How could I calculate the size of each array???

about this line:

double iSma(double price, int period, int r,int bars, int instanceNo=0)

Is there a guide to write this or you simply decide position of each argument(price, period etc.)

and another question...k is always =0 at begin, am I right?
 

...

Good morning Mladen,

let's start again

1. why sometime "SetIndexBuffer" has only the name of the buffer and sometime has INDICATOR_DATA?

I don't understand why for ex. the bb.mq5 indicator has for SetIndexBuffer the ExtMLBuffer without INDICATOR_DATA...

in this line...

iSma(rsi,AveragePeriod,i,rates_total);

2. why there's no instanceNo after rates_total? Is it possible omit part of this:

iSma(double price, int period, int r,int bars, int instanceNo=0)

3. AveragePeriod= rsi period?

4. why "i" and not again "r"? Because we need another cycle or we can't use an already used const int?

5. about this part of code : iSma(rsi ...it's like say: iSma(ExtRSIBuffer[]?

workSMA it's our sma buffer and you wrote:

double workSma[][2];

6. 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?

7. You wrote :

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

so for k=0, until k=0 than increase k of 1... but why r-k???

8. when you use internal call like iMA, you need to follow all parameter, instead of here yuo wrote your own? is it right?

double iSma(double price, int period, int r,int bars, int instanceNo=0)

9. where are our inputs for the sma?

mladen:
2. yes

3. at design time : you must know how many different averages are you going to use. It is not possible to have just 1 and 2 since each instance has to have 2 arrays just for itself. So the number 2 should be replaced with planedInstances * 2 for sma

4. you do not have to calculate the size of each array nor do you have to know it. All you have to know is a total number of arrays. The rest is dne by ArrayResize() when the array size is different than the number of bars on chart

Abot k : yes, it is a standard loop
 

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?