Переделать Fractals.mq5

 

Хочу чтоб индикатор рисовался линией от фрактала к фракталу и в отдельном окне – прописал:

#property indicator_separate_window

#property indicator_type1   DRAW_COLOR_LINE

#property indicator_type2   DRAW_COLOR_LINE

#property indicator_width1  1

Но окно индикатора пусто. ЧЯДНТ? 

Файлы:
Fractals.mq5  4 kb
 
Roma:

Хочу чтоб индикатор рисовался линией от фрактала к фракталу и в отдельном окне – прописал:

#property indicator_separate_window

#property indicator_type1   DRAW_COLOR_LINE

#property indicator_type2   DRAW_COLOR_LINE

#property indicator_width1  1

Но окно индикатора пусто. ЧЯДНТ? 

Как то так, для начала...

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
#property indicator_type1   DRAW_COLOR_SECTION
#property indicator_type2   DRAW_COLOR_SECTION

 
Valeriy Medvedev, всё равно пусто.
 
Valeriy Medvedev:

Как то так, для начала...

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
#property indicator_type1   DRAW_COLOR_SECTION
#property indicator_type2   DRAW_COLOR_SECTION

Ну, если уж на то пошло, то на два типа DRAW_COLOR_SECTION нужно по два буфера на каждый = 4.
 
Roma:

Хочу чтоб индикатор рисовался линией от фрактала к фракталу и в отдельном окне – прописал:

#property indicator_separate_window

#property indicator_type1   DRAW_COLOR_LINE

#property indicator_type2   DRAW_COLOR_LINE

#property indicator_width1  1

Но окно индикатора пусто. ЧЯДНТ? 

Для наглядности, лучше вставляйте полный код прямо на форум (через кнопку SRC), а не файлом. 
 

вписал #property indicator_buffers 4 – всё равно пусто – похоже этого недостаточно. Вот весь код:

#property copyright "2009, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   2
#property indicator_type1   DRAW_COLOR_SECTION
#property indicator_type2   DRAW_COLOR_SECTION
#property indicator_width1  1
#property indicator_color1  Gray
#property indicator_color2  Gray
#property indicator_label1  "Fractal Up"
#property indicator_label2  "Fractal Down"
//---- indicator buffers
double ExtUpperBuffer[];
double ExtLowerBuffer[];
//--- 10 pixels upper from high price
int    ExtArrowShift=-10;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtLowerBuffer,INDICATOR_DATA);
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_ARROW,217);
   PlotIndexSetInteger(1,PLOT_ARROW,218);
//---- arrow shifts when drawing
   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,ExtArrowShift);
   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-ExtArrowShift);
//---- sets drawing line empty value--
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- initialization done
  }
//+------------------------------------------------------------------+
//|  Accelerator/Decelerator Oscillator                              |
//+------------------------------------------------------------------+
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[])
  {
   int i,limit;
//---
   if(rates_total<5)
      return(0);
//---
   if(prev_calculated<7)
     {
      limit=2;
      //--- clean up arrays
      ArrayInitialize(ExtUpperBuffer,EMPTY_VALUE);
      ArrayInitialize(ExtLowerBuffer,EMPTY_VALUE);
     }
   else limit=rates_total-5;

   for(i=limit;i<rates_total-3 && !IsStopped();i++)
     {
      //---- Upper Fractal
      if(high[i]>high[i+1] && high[i]>high[i+2] && high[i]>=high[i-1] && high[i]>=high[i-2])
         ExtUpperBuffer[i]=high[i];
      else ExtUpperBuffer[i]=EMPTY_VALUE;

      //---- Lower Fractal
      if(low[i]<low[i+1] && low[i]<low[i+2] && low[i]<=low[i-1] && low[i]<=low[i-2])
         ExtLowerBuffer[i]=low[i];
      else ExtLowerBuffer[i]=EMPTY_VALUE;
     }
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }

//+------------------------------------------------------------------+
 
Roma:

вписал #property indicator_buffers 4 – всё равно пусто – похоже этого недостаточно. Вот весь код:

//+------------------------------------------------------------------+
//|                                                     Fractals.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
#property indicator_type1   DRAW_SECTION
#property indicator_type2   DRAW_SECTION
#property indicator_width1  1
#property indicator_color1  clrGray
#property indicator_color2  clrGray
#property indicator_label1  "Fractal Up"
#property indicator_label2  "Fractal Down"
//---- indicator buffers
double ExtUpperBuffer[];
double ExtLowerBuffer[];
//--- 10 pixels upper from high price
int    ExtArrowShift=-10;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtLowerBuffer,INDICATOR_DATA);
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//---- initialization done
  }
//+------------------------------------------------------------------+
//|  Accelerator/Decelerator Oscillator                              |
//+------------------------------------------------------------------+
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[])
  {
   int i,limit;
//---
   if(rates_total<5)
      return(0);
//---
   if(prev_calculated<7)
     {
      limit=2;
      //--- clean up arrays
      ArrayInitialize(ExtUpperBuffer,EMPTY_VALUE);
      ArrayInitialize(ExtLowerBuffer,EMPTY_VALUE);
     }
   else limit=rates_total-5;

   for(i=limit;i<rates_total-3 && !IsStopped();i++)
     {
      //---- Upper Fractal
      if(high[i]>high[i+1] && high[i]>high[i+2] && high[i]>=high[i-1] && high[i]>=high[i-2])
         ExtUpperBuffer[i]=high[i];
      else ExtUpperBuffer[i]=EMPTY_VALUE;

      //---- Lower Fractal
      if(low[i]<low[i+1] && low[i]<low[i+2] && low[i]<=low[i-1] && low[i]<=low[i-2])
         ExtLowerBuffer[i]=low[i];
      else ExtLowerBuffer[i]=EMPTY_VALUE;
     }
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }

//+------------------------------------------------------------------+
Автоматический трейдинг и тестирование торговых стратегий
Автоматический трейдинг и тестирование торговых стратегий
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
 
Valeriy

линии появились, но почему-то отдельные для позитив. и негатив. фракталов.

нужен один буфер, чтоб по нему рисовалась одна линия. 

 
Roma:

линии появились, но почему-то отдельные для позитив. и негатив. фракталов.

нужен один буфер, чтоб по нему рисовалась одна линия. 

Тогда: https://www.mql5.com/ru/code/10022
ZIGZAG по фракталам, без перерисовки значений
ZIGZAG по фракталам, без перерисовки значений
  • голосов: 6
  • 2010.12.09
  • Vladimir Khlystov
  • www.mql5.com
Линии зигзага строятся по фракталам, но не по стандартным, а по определенным вами.
 

заменил в расчётах ExtLowerBuffer[i] на ExtUpperBuffer[i] – теперь одна линия, но почему-то последние 2 фрактала не показываются.

 

 
Valeriy, по ссылке mq4.
Причина обращения: