Download MetaTrader 5

How to use iMAOnArray() with Stochastic?

To add comments, please log in or register
Sign up for MQL5.community to leave your comments!
Arav007
412
Arav007 2014.02.27 19:08 

Hello,

I want to use MA within the Stochastic indicator window. When the 'Signal' line crosses with that MA, Buy/Sell will trigger.

To do this, how can I define the iMAOnArray()?

double Signal_Sto= iStochastic(NULL,0,70,5,5,MODE_EMA,0,MODE_SIGNAL,0); // The Signal Line

double MA_Sto= iMAOnArray( double array[], int total, int ma_period, int ma_shift, int ma_method, int shift);

Now to define iMAOnArray() function would I have to make 'Signal_Sto' an array i.e. Signal_Sto[i] and call it at iMAOnArray() like this:

double MA_Sto= iMAOnArray( Signal_Sto, 0,14,0,MODE_SMA,i);

OR

if I just call Signal_Sto like this without using Array:

double MA_Sto = iMA( Signal_Sto,0,14,0,MODE_SMA,PRICE_CLOSE,0);

will the function work?

And if I have to use the Array then will be the code like this:

for(int i=0; i<100000; i++) // set the checking limit to 100000 bars

double Signal_Sto[i]= iStochastic(NULL,0,70,5,5,MODE_EMA,0,MODE_SIGNAL,0);

for(int i=0; i<100000; i++)

double MA_Sto= iMAOnArray( Signal_Sto, 0,14,0,MODE_SMA,i);

My principle is comparing Signal_Sto and MA_Sto.

Regards

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.02.27 19:34  
Arav007:

Hello,

I want to use MA within the Stochastic indicator window. When the 'Signal' line crosses with that MA, Buy/Sell will trigger.

To do this, how can I define the iMAOnArray()?

Now to define iMAOnArray() function would I have to make 'Signal_Sto' an array i.e. Signal_Sto[i] and call it at iMAOnArray() like this:

OR

if I just call Signal_Sto like this without using Array:

will the function work?

And if I have to use the Array then will be the code like this:

My principle is comparing Signal_Sto and MA_Sto.

Regards

Red the documentation and search the forum, iMAOnArray() has been discussed plenty.

Your last block of code you are overwriting MA_Sto 10000 times . . . why ? don't you want to use a buffer/array there ?
Arav007
412
Arav007 2014.02.27 19:53  
RaptorUK:
Red the documentation and search the forum, iMAOnArray() has been discussed plenty.

Your last block of code you are overwriting MA_Sto 10000 times . . . why ? don't you want to use a buffer/array there ?


Hello

Thanks for the reply.

I have posted this after searching Internet+This Forum.

Yes there are plenty of examples on iMAOnArray() but I haven't found the one I need yet. [With Stochastic].

From there I got the idea what I have presented here but now I need someone to correct me please.

And yes, it's a mistake.

It should be like this, right?

for(int i=0; i<100000; i++) // set the checking limit to 100000 bars

double Signal_Sto[i]= iStochastic(NULL,0,70,5,5,MODE_EMA,0,MODE_SIGNAL,0);

for(int i=0; i<100000; i++)//----------------------------------------------> if I don't use this Array, any problem?

double MA_Sto= iMAOnArray( Signal_Sto, 0,14,0,MODE_SMA,0);// for current buffer
Keith Watford
Moderator
9627
Keith Watford 2014.02.27 22:51  

for(int i=0; i<100000; i++) // set the checking limit to 100000 bars
//---Check that i<Bars

double Signal_Sto[i]= iStochastic(NULL,0,70,5,5,MODE_EMA,0,MODE_SIGNAL,0);  //Do you want this to be 0?

for(int i=0; i<100000; i++)//----------------------------------------------> if I don't use this Array, any problem?

double MA_Sto= iMAOnArray( Signal_Sto, 0,14,0,MODE_SMA,0);// for current buffer
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.02.27 22:53  
Arav007:


Hello

Thanks for the reply.

I have posted this after searching Internet+This Forum.

Yes there are plenty of examples on iMAOnArray() but I haven't found the one I need yet. [With Stochastic].

From there I got the idea what I have presented here but now I need someone to correct me please.

And yes, it's a mistake.

It should be like this, right?

It depends on what you are trying to achieve . . . it might be right, it's more likely wrong. Why not use a buffer/array ?
Arav007
412
Arav007 2014.02.28 04:50  
GumRai:



ohh, I did it wrong. If I put '0' there instead of 'i', then the Signal_Sto[i]will always be giving the value of current bar even though 'i' keeps increasing, right?

So I have to check the 'i' times to get all the previous value?

for(int i=0; i<Bars; i++) // set the checking limit to 100000 bars

double Signal_Sto[i]= iStochastic(NULL,0,70,5,5,MODE_EMA,0,MODE_SIGNAL,i); 

I need to compare Signal_Sto and MA_Sto on current bar's every tick. For it if I just simply put this, will it work?

double Signal_Sto= iStochastic(NULL,0,70,5,5,MODE_EMA,0,MODE_SIGNAL,0);

double MA_Sto= iMAOnArray( Signal_Sto, 0,14,0,MODE_SMA,0);

Thanks

Arav007
412
Arav007 2014.02.28 05:07  
RaptorUK:
It depends on what you are trying to achieve . . . it might be right, it's more likely wrong. Why not use a buffer/array ?

I probably got your point. Please correct me if I am wrong.

At the attached screenshot's 'Red Vertical Line', the values of Stochastic and MA are:

Sto

Stoch=86.5602 [buffer 0]

Signal=76.0463 [buffer 1]

MA(14)=70.0273 [buffer 2]

Now I have to compare buffer 1 and buffer 2.

if(buffer 1>buffer 2) or if(buffer 1< buffer 2)

But how can I define the MA part, buffer 2 ?

Say if Y1 gets the value of buffer 1 and Y2 gets the value of buffer 2,

then

Y1 =iStochastic(NULL,0,70,5,5,MODE_EMA,0,MODE_SIGNAL,0);

But what for Y2= ?

qjol
3243
qjol 2014.02.28 05:42  
Arav007:

I want to use MA within the Stochastic indicator window. When the 'Signal' line crosses with that MA, Buy/Sell will trigger.

i don't get it it's n indiicator or a EA
Arav007
412
Arav007 2014.02.28 06:03  
qjol:
i don't get it it's n indiicator or a EA


It'd be an EA.

I don't have problem with buying/selling part. Just need to fix the 'Indicator' calling part.

Thanks

qjol
3243
qjol 2014.02.28 06:16  
still don't understand u gonna make n indicator & then use it with iCustom() or the all calculation is gonna be writen in the EA
Arav007
412
Arav007 2014.02.28 06:26  
qjol:
still don't understand u gonna make n indicator & then use it with iCustom() or the all calculation is gonna be writen in the EA


Calculations gonna be written in the EA.

The theory is having a 'Stochastic' indicator with a MA into it. That is the MA is in the Stochastic indicator's Data window.

But practically this idea is going to be implemented into the EA. That's it.

Here I am encountering the problem of defining the 'MA' function regarding the above scenario.

123
To add comments, please log in or register