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

 
Vladimir Baskakov:

Thank you, it works, only one condition is met:

And I need

It doesn't open a position for some reason.

int barfrup_1 = GetLastFractals(1,MODE_UPPER);
int barfrup_2 = GetLastFractals(barfrup_1+1,MODE_UPPER);
int barfrdn_1 = GetLastFractals(1,MODE_LOWER);
int barfrdn_2 = GetLastFractals(barfrdn_1+1,MODE_LOWER);

if(High[barfrup_1] < High[barfrup_2] && Low[barfrdn_1] < Low[barfrdn_2] )
if(High[barfrup_1] < High[barfrup_2] && Low[barfrdn_1] > Low[barfrdn_2] )
 
Igor Makanu:

It works, but it opens positions, not by condition, wherever it wants, all right

 
Vladimir Baskakov:

It works, but opens positions, not by condition, wherever it wants, ok

it cannot be so, my code is simple, like ZigZag, fractal has values only on the bars with arrows in the loop, look for indicator values before the arrow appears and exit the loop, return the fractal bar number

I have just made an Expert Advisor by fractals - the code is checked, and it turned out during the test that fractal on the bar number 1 may overdraw - turn on the visualization mode of the tester and add an indicator for fractal

 
Igor Makanu:

it cannot be, my code is simple, the fractal, like ZigZag, has values only on the bars with arrows, in the loop, go through the indicator values until the arrow appears and exit the loop, return the number of bar on which the fractal is

I have just made an Expert Advisor by fractals - the code is checked, and it turned out during the test that fractal on the bar number 1 may overdraw - turn on the visualization mode of the tester and add an indicator for fractal

Maybe the result should be checked at 0 or empty value
 
Aleksei Beliakov:
Maybe the result should be checked for 0 or empty value

there is 0 in empty values, well kinda not the best way to compare to _Point

it works, I don't want to prove it, but fractal indicator values should work with this part of the code

SZY: once again, for some reason I discuss my code.... the more the code works, I do not see the code of other participants, I do not understand who needs it in the end? ))))


PS:Checked, because I know that the question will not rest, everything works, the code is fast:

#property copyright "IgorM"
#property link      "https://www.mql5.com/ru/users/igorm"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "Label2"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrBlue
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- indicator buffers
double         Label1Buffer[];
double         Label2Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
   SetIndexBuffer(1,Label2Buffer);
   SetIndexArrow(0,SYMBOL_ARROWUP);
   SetIndexArrow(1,SYMBOL_ARROWDOWN);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//--
   static int limit=0;   
   if(limit>=10) return(rates_total);
   int b_up = 0, b_dn = 0;
   while(limit<=10)
     {
      b_up = GetLastFractals(b_up,MODE_UPPER);
      Label1Buffer[b_up] = high[b_up];
      b_up++;
      b_dn = GetLastFractals(b_dn,MODE_LOWER);
      Label2Buffer[b_dn] = low[b_dn];
      b_dn++;
      limit++;
      }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//_______________________________________________________________________
int GetLastFractals(int bar,int mode) // bar - с какого бара начинать поиск, mode = MODE_UPPER или MODE_LOWER , результат № бара где найден фрактал
  {
   int i=bar; 
   while(i<Bars && iFractals(NULL,0,mode,i)<_Point) i++;
   return(i);
  }
//_______________________________________________________________________

result


 
Artyom Trishkin:

ArraySetAsSeries(true) for indicator buffers.

Did. I did according to the handbook
 
Igor Makanu:

it cannot be, my code is simple, the fractal, like ZigZag, has values only on the bars with arrows, in the loop, go through the indicator values until the arrow appears and exit the loop, return the number of bar on which the fractal is

I have just made an Expert Advisor by fractals - the code is checked, and it turned out during the test that fractal on the bar number 1 may overdraw - switch on the visualization mode of the tester and add an indicator for fractal,

No, my position opens. As it should, on the third bar a fractal. But further it is worse. By my condition (fr1_up<fr_2 && fr1_down>fr2_down) it does not find. The essence is the compression of prices, which we find by two fractals
 

I think I did it !

999

Files:
IgorM.mq5  17 kb
 
Aleksandr Klapatyuk:

I think I did it !

What is it?
 
Vladimir Baskakov:
Which one?

object name move over iFractals

Reason: