Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 445

 
Artyom Trishkin:

So read iCustom() right by the first loop index.

Another question is that you need data from current bar to the left. That's why I say - read from zero to the found one, but no more than rates_total-1.

Read only when limit>1

Other time there is no new data, and index of the bar you need will not change.

It does not, but the bar numbers of the nearest arrows in the commentary are correct

//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   if(rates_total<1) return(0);
   int limit=rates_total-prev_calculated;
   if(limit>1) 
     {
      limit=rates_total-1;
      ArrayInitialize(BufferUP,EMPTY_VALUE);
      ArrayInitialize(BufferDN,EMPTY_VALUE);
     }
   for(int i=limit; i>=0; i--) 
     {
         if(NormalizeDouble(iCustom(NULL,0,"Arrow v.3",0,i),Digits)!=EMPTY_VALUE)
           {
            num_buy=i;

           }
//
      if(num_buy==10)
        {
         BufferUP[i+1]=low[i+1]-distance*MyPoint;
         
        }
         if(NormalizeDouble(iCustom(NULL,0,"Arrow v.3",1,i),Digits)!=EMPTY_VALUE
            )
           {
            num_sell=i;

           }
      if(num_sell==10)
        {
         BufferDN[i+1]=high[i+1]+distance*MyPoint;

        }
     
      Comment(num_buy,"num_sell",num_sell);
     }
//--- return value of prev_calculated for next call

   return(rates_total);
  }
 
mila.com:

He doesn't want to.

Do you read what I write?

The other question is that you want data from the current bar to the left. That's why I say - read from zero to the found one, but no more than rates_total-1.

Read only at limit>1

 
Artyom Trishkin:

Do you read what I write?

The other question is that you need data from the current bar to the left. That's why I say - read from zero to the found one, but no more than rates_total-1.

Read only at limit>1

Didn't I make it so?
if(limit>1)
{
limit=rates_total-1;

 
mila.com:

Isn't that what I did?
if(limit>1)
{
limit=rates_total-1;

This is what you did next:

for(int i=limit; i>=0; i--) 

What was I talking about?

 
Artyom Trishkin:

What you have done next is this:

What was I saying?

Read at limit>1

for(int i=limit; i>1; i--) 

I don't know how to do it right?

 
mila.com:

Read at limit>1

I don't know how to do it right?

That's why I say - read from zero to the found one, but no more than rates_total-1.
 
Artyom Trishkin:
That's why I say read from zero to find the right one, but no more than rates_total-1.

I'm telling you, I don't know how to do it. Show me, please.)

 
mila.com:

I told you, I don't know how to do it. Show me, please.)

if(limit>1)
  {
   for(int i=0; i<limit; i++) 
     { 
      // тут поиск до нужного вам бара. Нашли - запомнили бар или поставили точку куда нужно и break;
     }
  }

This cycle will only go to the bar you want (if found), or the whole story will go to the limit.

 
Artyom Trishkin:

This cycle will only be up to the bar you want (if found), or for the whole story, up to the limit.

me, quite bad, shows nothing.

//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   if(rates_total<1) return(0);
   int limit=rates_total-prev_calculated;
   if(limit>1) 
     {
      limit=rates_total-1;
      ArrayInitialize(BufferUP,EMPTY_VALUE);
      ArrayInitialize(BufferDN,EMPTY_VALUE);
     }
  if(limit>1)
  {
   for(int i=0; i<limit; i++) 
     { 
         if(NormalizeDouble(iCustom(NULL,0,"Arrow v.3",0,i),Digits)!=EMPTY_VALUE)
           {
            num_buy=i;

           }
//
      if(num_buy==10)
        {
         BufferUP[i+1]=low[i+1]-distance*MyPoint;
         
        }
         if(NormalizeDouble(iCustom(NULL,0,"Arrow v.3",1,i),Digits)!=EMPTY_VALUE
            )
           {
            num_sell=i;

           }
      if(num_sell==10)
        {
         BufferDN[i+1]=high[i+1]+distance*MyPoint;

        }
     
      Comment(num_buy,"num_sell",num_sell);
     }
     }
//--- return value of prev_calculated for next call

   return(rates_total);
  }
 
mila.com:

I'm really bad, it doesn't show anything.

I still don't get it: what do you want to find and display? Just in words - without code.

Here you are writing:

Hello, help me, please.

I want, at any time, to know the number of the bar where the indicator arrow is.

In the example, I tried to fill the buffer if the arrow is on the tenth bar.

Here is the question at once: why are you looking for it on the tenth bar? And in general, on which bar do you want? And which arrow? The very last one? Or the last two - the upper and the lower? Or know the bar of the desired arrow by its number from right to left?

This is not clear.

And attach the whole indicator, not OnCalculate()