Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 504

 

Need to find the maximum value of the indicator over 15 periods. Searching in bars is not a problem, but in an indicator?

I will assume that for this you need to make a check loop, declare an array and find this value in it. The loop is done, but I don't know how to declare the array.

And then use the ArrayMaximum function to find the value? Can you tell me how to accomplish this task?

for(int i=0;i<=15;i++)
{
double indicator[];
ArrayInitialize(indicator,0);
double MA_2_t=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE,i); 
}
 
niktron:

Hello!

Can you tell me how to make a condition -

if there is enough free margin to open a position?

(So that error 131 doesn't pop up)...Thanks!


https://docs.mql4.com/ru/account/accountfreemargincheck
 
Forexman77:

Need to find the maximum value of the indicator over 15 periods. Searching in bars is not a problem, but in an indicator?

I will assume that for this you need to make a check loop, declare an array and find this value in it. The loop is done, but I don't know how to declare the array.

And then, I will use the ArrayMaximum function to find the value. Please, advise how to complete this task.

You need not just an array, but an indicator buffer. In the main loop, fill the buffer with indicator values and use ArrayMaximum() to this buffer.
 
Integer:
You don't just need an array, but an indicator buffer. In the main loop, fill the buffer with indicator values and use ArrayMaximum() to this buffer.

The search is needed for the Expert Advisor. Will an indicator buffer work with it?
 
Forexman77:
The search is necessary for the Expert Advisor. Will an indicator buffer work with it?


There is no indicator buffer in the EA.

If in the EA, then there are two options:

1. Do everything in the indicator, the EA calls the indicator and gets a ready value.

2. Make a loop in the Expert Advisor. But in this case, the array is not needed at all.

val=0;

for(i=1;i<=15;i++) {

    ind=iMA(...,i);

   if(ind>val) val=ind;

}
 
Integer:


The Expert Advisor has no indicator buffer.

If in the EA, then there are two options:

1. Do everything in the indicator, the EA calls the indicator and gets a ready value.

2. Make a loop in the Expert Advisor. But in this case, the array is not needed at all.

An array will be needed. To find the minimum. The minimum will not be found in this way.
 
Forexman77:
An array will be needed. To find the minimum. The minimum will not be found in this way.



So you know exactly and are absolutely sure? There is no need to refute your opinion? Would you prefer to stick with it?

 
niktron:

Hello!

Can you tell me how to make a condition -

if there is enough free margin to open a position?

(So that error 131 doesn't pop up)...Thanks!

maybe the lot is wrong if 131?
 
Integer:



So you know for sure and are absolutely certain? There is no need to refute your opinion? Would you prefer to stick to it?

Of course I do! Well, how do you apply this construct to finding the minimum? I can't get my brain around it)
And I want to learn how to declare an array. I tried it this way:

double massiv[];
int start()
  {
//----
for(int i=0;i<=33;i++)
{
double ind=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE,i); 
massiv[33]=ind;
double minValueidx=ArrayMinimum(massiv,33,0);
Alert("minValueidx=",minValueidx);
}
//----
   return(0);
  }
It comes out -1.
 
Forexman77:
You need it, of course! Well, how to apply this construction to search for the minimum? I can't do it with my brain)

To find the maximum, the variable val is assigned a value of 0 (obviously less than any of the indictor values).

This means that to find the minimum, we must add a deliberately higher value. The EMPTY_VALUE constant can be used or the indicator value directly on some bar among which the minimum is searched.

val=EMPTY_VALUE;

for(i=1;i<=15;i++) {

    ind=iMA(...,i);

   if(ind< val) val=ind;

}

Or like this:

val=MA(...,1);


for(i=2;i<=15;i++) {

    ind=iMA(...,i);

   if(ind< val) val=ind;

}