MqL4 Fractals

 

hi guys

i'm new to mql4 and trying to write a code for the current four Fractals where i want some form of identification for the previous fractals. Problem is i'm stuck at the array. Please any help with the code would be much appreciated

below is what i have been able to do.

 

***


Fractals - Bill Williams' Indicators - MetaTrader 5 Help
Fractals - Bill Williams' Indicators - MetaTrader 5 Help
  • www.metatrader5.com
All markets are characterized by the fact that on the most part the prices do not change too much, and only short periods of time (15–30 percent)...
 
double array[4];
int count = 0;

for(int i=0; i<Bars; i++) {
 double val = iFractals(NULL,0,MODE_UPPER,i);
 if(val!=0 || val!=EMPTY_VALUE) {
  array[count] = val;
  count++;
  If(count==4) break;
 }
}


Typed on the phone. Not compiled and tested.

 
Navdeep Singh:


Typed on the phone. Not compiled and tested.

Thank you very much. I will compile and see. God bless you
 
Philip Ninson :


1. Please insert the code correctly: when editing a message, press the button   Codeand paste your code into the pop-up window.

2. All questions about the old terminal should be discussed only in a dedicated section: MQL4 and MetaTrader 4 . I will move your topic to the specified section.

 
Navdeep Singh:
double array[4];
int count = 0;

for(int i=0; i<Bars; i++) {
 double val = iFractals(NULL,0,MODE_UPPER,i);
 if(val!=0 || val!=EMPTY_VALUE) {
  array[count] = val;
  count++;
  If(count==4) break;
 }
}

Typed on the phone. Not compiled and tested.

if(val!=0 || val!=EMPTY_VALUE)

This will always return true.

You probably mean to use && not ||

 
Keith Watford:

This will always return true.

You probably mean to use && not ||

Yes the && . thanks
 
Keith Watford:

This will always return true.

You probably mean to use && not ||

Please I have trouble still understanding arrays and how to quote them with a loop in a function. But I really want to learn and understand it . I'll be grateful if you could provide me with a document to read on it. Or some little explanation with examples will do it.

 
Philip Ninson:
Please I have trouble still understanding arrays and how to quote them with a loop in a function. But I really want to learn and understand it . I'll be grateful if you could provide me with a document to read on it. Or some little explanation with examples will do it.

You have used the array correctly in your code.

I don't think that there is a single document that fully explains using arrays.

When you encounter a problem, post your code and explain what you are trying to do. Someone will help.

 
Keith Watford:

You have used the array correctly in your code.

I don't think that there is a single document that fully explains using arrays.

When you encounter a problem, post your code and explain what you are trying to do. Someone will help.

double Fractal[5];
int count = 0;

for(int i=0; i<Bars; i++){ 
 double Fvalue = iFractals(_Symbol,_Period,MODE_UPPER,i);
 if(Fvalue!=0 && Fvalue!=EMPTY_VALUE)
  {
  Fractal[count] = Fvalue;
  count++;
  if(count==4) break;
  string signal="";
  if(Fractal[0]>Fractal[2] )
    {
     signal="bullish";
 if (signal=="bullish" )
      {
       Comment("signal is buy");
      }
    else
      {
       Comment("No signal");
      }
   

please image description below, but i have problem with the array in the code

Files:
Fractals.PNG  49 kb
 
Keith Watford:

This will always return true.

You probably mean to use && not ||

I forgot that fractals buffers have the empty value set to zero. Thanks for correcting 

 
Philip Ninson:

please image description below, but i have problem with the array in the code

Oh now I see what you are trying to achieve. Well in this case you could try

double arrUp[4],arrDn[4],val=0;
int count = 0;
int i = 0;
datetime foundUp = 0;
datetime foundDn = 0;

for(i=0; i<Bars; i++) {
 val = iFractals(NULL,0,MODE_UPPER,i);
 if(val!=0) {
  arrUp[count] = val; if(count==0) foundUp = Time[i];
  count++;
  if(count==4) break;
 }
}

count = 0;
for(i=0; i<Bars; i++) {
 val = iFractals(NULL,0,MODE_LOWER,i);
 if(val!=0) {
  arrDn[count] = val; if(count==0) foundDn = Time[i];
  count++;
  if(count==4) break;
 }
}

if(foundUp>foundDn) //Buy condition valid as per your logic
   if(arrUp[0]>arrUp[1]) //Buy

//Opposite for sell


But I still believe there may be smarter ways to do it. You should also consider that the current fractal repaints.

Again not compiled and tested

Reason: