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

 
artmedia70:

This line can be removed, because iFractals() returns zero as no fractal, not "empty value" (EMPTY_VALUE).

My question is as follows: are you trying to make an indicator that will look for two consecutive fractals? Or are you searching in your EA for two consecutive fractals closest to the current bar? This question is not of idle curiosity because the search methods in the indicator and in the Expert Advisor are different - the indicator calculates from the end to the beginning - from past to present, and the Expert Advisor looks through the bars from present to past. Accordingly, the search directions are also different in the Expert Advisor and in the indicator.

And one last question: what should the output be?



Not interested (no need to know until now) in what iFractals() returns. If it's really 0 - yes, sorry I lied, EMPTY_VALUE doesn't need to be checked.

I came up with this formulation as a nice justification - we considered the general case of EMPTY_VALUE and not the local one with 0 return.

But I'm ashamed and am amused myself that I did not know such an elementary thing.

I understand the code was for an indicator - artmedia70 is right that the approach is different for Expert Advisors.

I have no time for it - I will do it at night when I get home, because we have not understood each other well ( after finding the condition of two fractals the event should be processed) but everything is OK.

//----
   БЛОК ПРОВЕРКИ НОВОГО БАРА;                //проверить наличие нового бара 

   int   a1=0,                               //преведущий фрактал (-1 ->нижний, 1 -> верхний)
         a2,                                 //нынешний фрактал  (-1 ->нижний, 1 -> верхний)
         a3,                                 //сума преведущий + нынешний
         kilkict,                            //была введена с мыслю уменьшить перерасчет после глобального расчета (идея просто еще не реализована)
         frac,                               //frac - флаг существования фракталов,
         frac1=0,                            //frac1- счетчик фракталов (+1 или 0 за цикл)сейчас просто выполняет роль фильтра, надо найти сперва 2 фрактала чтобы приступить к их сравнению.
         i;
     
   kilkict=Bars;                            

   for (i=3; i<kilkict;i++){                 // 3
      a2=0;
      frac=0;
      if(iFractals(NULL, 0, MODE_UPPER, i)>0) {            
         if (Bufer0!=EMPTY_VALUE) {          //не нужно для iFrctals()данной проверки условий
            a2+=1;                           //к числу фракталов добавляем 1
            frac=1;                          //флаг - фрактал есть
            frac1++;                         //счетчик увеличиваем на 1
         }
      }
      if(iFractals(NULL, 0, MODE_LOWER, i)>0) {            
         if (Bufer0!=EMPTY_VALUE) {          //не нужно для iFrctals() данной проверки условий
            if(a2==0){              
               frac1++;                      //счетчик увеличиваем на 1 
               frac=1;                       //флаг - фрактал есть
            }
            a2+=-1;                          //к числу фракталов добавляем -1(т. е. уменшаем)
         }
      } 
      if (frac==0){continue;}                // если флага нет (фрактал не найден)
      if (frac1==1){                         //если счетчик равен 1,
         a1=a2; 
         continue;
      }          
      a3=a1+a2;
      if(a3<0)           { a1=a2; БЛОК ОБРАБОТКИ УСЛОВИЯ ДВА ФРАКТАЛА НАЙДЕНО; continue;}//Два фрактала вниз  подряд найдено// 
      if(a3>0)           { a1=a2; БЛОК ОБРАБОТКИ УСЛОВИЯ ДВА ФРАКТАЛА НАЙДЕНО; continue;}//Два фрактала вверх подряд найдено //
      if(a3==0 && a1==0) { a1=a2; БЛОК ОБРАБОТКИ УСЛОВИЯ ДВА ФРАКТАЛА НАЙДЕНО; БЛОК ОБРАБОТКИ УСЛОВИЯ ДВА ФРАКТАЛА НАЙДЕНО; }// Два фрактала подряд вверх и два фрактала подряд вниз найдено //
   } 

 
gince:


...

I apologise for the mistakes. Don't be too hard on me.


Just wondering, it's a funny phenomenon.
 
Integer:

Just wondering, it's a funny phenomenon.

Thanks for the correction.
 
if(!SL==0)
   {
  dollarsPerPip = lot/SL;
   }

Who does that?

if(SL>0) dollarsPerPip = lot/SL;

Why bother with a lot of { }?? and slow down the process...

alternatively...

if(SL) dollarsPerPip = lot/SL;
 
gince:


While the indicator, and then we'll see. The search methods in the indicator and in the Expert Advisor are different - the indicator calculates from end to beginning - from past to present, and the Expert Advisor looks through the bars from present to past .

for (i=kilkict;i>0;i--)

Result - two high -> sell (arrow down), two low -> buy (arrow up). The signal will appear +2 bars to the right of the fractal. That is what I would like to see visually on the history at the beginning. And probably we will need a filter.

Then the question is: why do you want to make yourself tired of writing this indicator, if you just want to look at the history? You were given a link to the Articulus indicator. It does exactly what you want:

//+------------------------------------------------------------------+
//|                                                    iFractals.mq4 |
//|                             Copyright © 2010, EGEN Software LTD. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright   "Copyright © 2010, EGEN Software LTD."
#property link        "http://www.metaquotes.net"

#property indicator_chart_window

#property indicator_buffers   2
#property indicator_color1    Lime
#property indicator_color2    Red
#property indicator_width1    2
#property indicator_width2    2

datetime TIME; double F,F1,F2;

double WAVE.0[];
double WAVE.1[];

bool EQ(int value1, int value2)
{
   return(value1==value2);
}

bool ZERO(int value)
{
   return(EQ(value,0));
}

int MathSign(double value1, double value2)
{
   if(value1<0)
      if(value2<0) return(-1);
   if(value1>0)
      if(value2>0) return(1);
   return(0);
}

bool TOTAL(int index)
{
   return(index<Bars);
}

double FRACTALS(int mode, int shift)
{
  return(iFractals(NULL,0,mode,shift));
}

double UPPER(int shift)
{
   return(FRACTALS(MODE_UPPER,shift));
}

double LOWER(int shift)
{
   return(FRACTALS(MODE_LOWER,shift));   
}

int PEAK(int shift)
{
   int peak=0;
   double F1=UPPER(shift); 
   if(F1>0) peak++;
   double F2=LOWER(shift); 
   if(F2>0) peak--;
   F=F1+F2; 
   return(peak);
}

void init()
{
   IndicatorBuffers(2);
   SetIndexBuffer(0,WAVE.0);
   SetIndexStyle(0,DRAW_ARROW,EMPTY);  
   SetIndexArrow(0,236);    
   SetIndexBuffer(1,WAVE.1);
   SetIndexStyle(1,DRAW_ARROW,EMPTY);      
   SetIndexArrow(1,238);
   IndicatorDigits(Digits);
   IndicatorShortName("iFractals");  
}

bool F1(int shift)
{
   int peak=PEAK(shift);
   if(ZERO(peak)) return(false); 
   F1=F*peak;
   return(true);
}

int WAVE.1(int shift)
{   
   for(int i=shift; TOTAL(i); i++) 
      if(F1(i)) break; 
   return(i);
}

bool F2(int shift)
{
   int peak=PEAK(shift);
   if(ZERO(peak)) return(false); 
   F2=F*peak;
   return(true);
}

int WAVE.2(int shift)
{   
   for(int i=shift; TOTAL(i); i++) 
      if(F2(i)) break; 
   return(i);
}

void WAVE(int shift)
{
   WAVE.0[shift]=EMPTY_VALUE;
   WAVE.1[shift]=EMPTY_VALUE;
   shift=WAVE.1(shift); 
   int index=shift; shift++;
   shift=WAVE.2(shift);
   int wave=MathSign(F1,F2);
   F1=MathAbs(F1);
   F2=MathAbs(F2);
   if(wave<0) 
      if(F1<F2) WAVE.1[index]=F1; else WAVE.0[index]=F1;                  
   if(wave>0) 
      if(F1>F2) WAVE.0[index]=F1; else WAVE.1[index]=F1;       
}   

void CheckWave()
{
   for(int i=3; TOTAL(i); i++) WAVE(i);
}   

void start()
{
   CheckWave();
}

Compile and look at the stories. Then draw conclusions.

Or is "standing in a hammock" more comfortable?

 
artmedia70:

Then the question is: why are you torturing yourself by writing this indicator if you just want to look at the stories? You were given a link to the Articulus indicator. It does exactly what you want it to do:

Compile it and look at the history. And then draw conclusions.

Or is "standing in a hammock" more comfortable?



and you trace the logic of the turkey ))

You don't need 20 functions to figure it out, do you?

 
VOLDEMAR:

Who does that?

Why bother with a lot of { }?? and slow down the process...

alternatively...


Funny, I didn't know that, I'll have to check it out.
 
ALXIMIKS:


and you trace the logic of the turkey ))

you don't get bored with 20 functions???

Every function there returns a result which is understandable at a glance. I don't get bogged down at a glance. It's as clear as day. Besides, what does he need? He needs to look at stories, not code.
 
VOLDEMAR:

Who does that?

Why bother with a lot of { }?? and slow down the process...

that's one way to do it.

Thanks for the correction.

I have this stupid habit

when writing a conditional statement

to put parentheses right away.

 

Can you tell me how to determine the price for a text marker so that it is always at the top of the chart?

We draw a vertical line at a given time and we want its name at the top.

Reason: