Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 16
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello, can you please help me find the price of the larger fractal, from the first - near top four fractals.
Hello, can you please help me find the price of the larger fractal, from the first - near top four fractals.
{
Comment("Min = ",MaxMinFractal(MODE_LOWER, 4),"; Max = ",MaxMinFractal(MODE_UPPER, 4));
}
//===============================================================================================
//--------------------------------- Возвращает Max/Min фрактала --------------------------------+
//===============================================================================================
double MaxMinFractal(int mode=MODE_UPPER, int nf=4) {
string symb=Symbol();
double f=0,min=9999999,max=0;
int kf=0;
for(int i=3; i<iBars(symb, 0); i++) {
if(mode==MODE_LOWER){
f=iFractals(symb, 0, MODE_LOWER, i);
if(f!=0) {
kf++;
if(min>iLow(symb,0,i)) min=iLow(symb,0,i);
if(kf>=nf) return(min);
}}
if(mode==MODE_UPPER){
f=iFractals(symb, 0, MODE_UPPER, i);
if(f!=0) {
kf++;
if(max<iHigh(symb,0,i)) max=iHigh(symb,0,i);
if(kf>=nf) return(max);
}}}
return(-1);
}
Hello, can you please help me find the price of the larger fractal, from the first - near top four fractals.
void OnStart()
{
int i=1,cnt=1;
double lastupfr=0;
while(cnt<5)
{
double upfr=iFractals(_Symbol,0,1,i);
if(upfr!=0)
{
if(upfr>lastupfr) lastupfr=upfr;
cnt++;
}
i++;
}
Comment("Biggest UpFractal = ",lastupfr);
}
Even shorter ) Thank you.
And how, of these, customisable, fractals, do you choose the maximum one?
//| nr - количество баров справа |
//+----------------------------------------------------------------------------+
double GetNearestUpFractal(string sy="0", int tf=0, int nl=2, int nr=2) {
bool f;
int fb, i, nb=-1;
if (sy=="" || sy=="0") sy=Symbol();
if (nl<1) nl=1;
if (nr<1) nr=1;
fb=nr;
while (nb<0) {
fb++;
f=True;
for (i=fb; i>fb-nr; i--) {
if (iHigh(sy, tf, i)<iHigh(sy, tf, i-1)) { f=False; break; }
}
if (f) {
for (i=fb; i<fb+nl; i++) {
if (iHigh(sy, tf, i)<iHigh(sy, tf, i+1)) { f=False; break; }
}
if (f) { nb=fb; break; }
}
}
return(iHigh(sy, tf, nb));
}
Even shorter ) Thank you.
And how, of these, customisable, fractals, do you choose the maximum one?
//| nr - количество баров справа |
//+----------------------------------------------------------------------------+
double GetNearestUpFractal(string sy="0", int tf=0, int nl=2, int nr=2) {
bool f;
int fb, i, nb=-1;
if (sy=="" || sy=="0") sy=Symbol();
if (nl<1) nl=1;
if (nr<1) nr=1;
fb=nr;
while (nb<0) {
fb++;
f=True;
for (i=fb; i>fb-nr; i--) {
if (iHigh(sy, tf, i)<iHigh(sy, tf, i-1)) { f=False; break; }
}
if (f) {
for (i=fb; i<fb+nl; i++) {
if (iHigh(sy, tf, i)<iHigh(sy, tf, i+1)) { f=False; break; }
}
if (f) { nb=fb; break; }
}
}
return(iHigh(sy, tf, nb));
}
void OnStart()
{
int i=1,cnt=1;
double lastupfr=0;
while(cnt<5)
{
double upfr=GetNearestUpFractal(_Symbol,0,2,2);
if(upfr!=0)
{
if(upfr>lastupfr) lastupfr=upfr;
cnt++;
}
i++;
}
Comment("Biggest UpFractal = ",lastupfr);
}
//-----------
//| nl - количество баров слева |
//| nr - количество баров справа |
//+----------------------------------------------------------------------------+
double GetNearestUpFractal(string sy="0", int tf=0, int nl=2, int nr=2) {
bool f;
int fb, i, nb=-1;
if (sy=="" || sy=="0") sy=Symbol();
if (nl<1) nl=1;
if (nr<1) nr=1;
fb=nr;
while (nb<0) {
fb++;
f=True;
for (i=fb; i>fb-nr; i--) {
if (iHigh(sy, tf, i)<iHigh(sy, tf, i-1)) { f=False; break; }
}
if (f) {
for (i=fb; i<fb+nl; i++) {
if (iHigh(sy, tf, i)<iHigh(sy, tf, i+1)) { f=False; break; }
}
if (f) { nb=fb; break; }
}
}
return(iHigh(sy, tf, nb));
}
So returns the price of the nearest fractal.
How do I find the maximum of the four configurable fractals?
So returns the price of the near fractal.
How do I find the maximum of the four configurable fractals?
Um... You need to select the 4 fractals set up for selection, and by blowing away the worthless inferior fractals, leave one Maximka:)
How do you do it?