How to use FOR with iCustom code

 

I want to scan indicator buffer (from current bar to old bar )with using iCustom code.

 for (int J = 0; J < 1000; J++) { 

 double up = iCustom(Fx_Symbol,TIME_FRAME,"indicator file",0,J)!=EMPTY_VALUE;
 double dn = iCustom(Fx_Symbol,TIME_FRAME,"indicator file",1,J)!=EMPTY_VALUE;
 if (up){string FLAG="UP SIGNAL";break;
 if (dn){       FLAG="DN SIGNAL";break;
}

What I want is

When scan buffer from current bar to 1000 bars back, I want to know that the 1st signal is up or dn.

I don't know which signal comes first, I used for (int --- code to find the buffers.

For example, the 50 bars back , there is a up buffer signal (which comes earlier than DN SIGNAL), then I want to know it is UP SIGNAL.

How can  I code it?


How about this?

  for (int J = 0; J < 1000; J++) { 
       double up=iCustom(Fx_Symbol,TIME_FRAME,"AAAA",0,J)!=EMPTY_VALUE;
       double dn=iCustom(Fx_Symbol,TIME_FRAME,"AAAA",1,J)!=EMPTY_VALUE;
       if(up||dn)break;
       
       }
       if(up) string signal ="UP SIGNAL";
       if(dn)        signal ="DN SIGNAL";

/// if find the 1st up or dn buffer, just break and escape from the roop.

Thank you for your advise.

Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
  • www.mql5.com
Some technical indicators have several buffers drawn in the chart. Numbering of indicator buffers starts with 0. When copying indicator values using the CopyBuffer() function into an array of the double type, for some indicators one may indicate the identifier of a copied buffer instead of its number.
 

simple!

when your for circle hit a up arrow, the veriable "up" won't be EMPTY_VALUE; so you know it's a up arrow.

further more, your codes make me confused. if i were you, i will write your codes like this.

for(int j=0;j<1000;j++)
{
    double up = iCustom(Fx_Symbol,TIME_FRAME,"AAAA",0,j);
    double dn = iCustom(Fx_Symbol,TIME_FRAME,"AAAA",1,j);
    if(up!=EMPTY_VALUE) printf("up signal");
    if(dn!=EMPTY_VALUE) printf("dn signal");
}

that's it!

 
Cromo:

I want to scan

What I want is … I want to know that the 1st signal is up or dn.

I don't know which signal comes first, …

… I want to know …

How can  I code it?

  1. Saying it once is enough.
  2. Yes we know. Twice is too much.
  3. Please post only in English on this forum. "dn is not a word.
              Please don't write ur - it's "you are" or "your" - MQL4 programming forum 2014.03.04

  4. Yes we know the first time STOP repeating the same thing over and over. You are being obnoxious.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

  5. You already coded it. Either test in the loop or move those two variable definitions before, and test after. You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21

 
lissp:

simple!

when your for circle hit a up arrow, the veriable "up" won't be EMPTY_VALUE; so you know it's a up arrow.

further more, your codes make me confused. if i were you, i will write your codes like this.

that's it!

Thank you very much.

But when I tried this code, it is showing up signal and dn signal repeatedly.

I just want to show the one time alert.

Which comes first up signal or dn signal.

 
add break as soon as either signal is detected.
 
Soewono Effendi:
add break as soon as either signal is detected.
for(int j=0;j<1000;j++)
{
    double up = iCustom(Fx_Symbol,TIME_FRAME,"AAAA",0,j);
    double dn = iCustom(Fx_Symbol,TIME_FRAME,"AAAA",1,j);
    if(up!=EMPTY_VALUE) printf("up signal");break;
    if(dn!=EMPTY_VALUE) printf("dn signal");break;
}

Like this?

 
Cromo:

Like this?

for(int j=0;j<1000;j++)
{
    double up = iCustom(Fx_Symbol,TIME_FRAME,"AAAA",0,j);
    double dn = iCustom(Fx_Symbol,TIME_FRAME,"AAAA",1,j);
    if(up!=EMPTY_VALUE) printf("up signal");break;
    if(dn!=EMPTY_VALUE) printf("dn signal");break;
}

Think about what you are doing.

The breaks in your code are independent of any condition and will exit the loop on the first iteration.

 
Keith Watford:

Think about what you are doing.

The breaks in your code are independent of any condition and will exit the loop on the first iteration.


Hi, Keith

Yes, what I want is to know the latest signal is up or down.

So either signal received fist, escape from the loop.That is fine.

 
Cromo:

Hi, Keith

Yes, what I want is to know the latest signal is up or down.

So either signal received fist, escape from the loop.That is fine.

Keith Watford:

Think about what you are doing.

for(int j=0;j<1000;j++)
{
    double up = iCustom(Fx_Symbol,TIME_FRAME,"AAAA",0,j);
    double dn = iCustom(Fx_Symbol,TIME_FRAME,"AAAA",1,j);
    if(up!=EMPTY_VALUE) printf("up signal");break;
    if(dn!=EMPTY_VALUE) printf("dn signal");break;
}

The breaks in your code are independent of any condition and will exit the loop on the first iteration.

That is not fine

 
  if(up!=EMPTY_VALUE) { printf("up signal");break; }
   
if(dn!=EMPTY_VALUE) { printf("dn signal");break; }

 
Soewono Effendi:

Oh, I need   {  } ?

I thought below is the same..

if(A==1){string flag="OK";}


if(A==1)string flag="OK";
Reason: