← К каталогу
Исходный код · ID 5156

hma atr channel button.mq5

Похожие материалы по тегам

elliot-waves-oscillator.mq5MQL5 / MetaTrader 5 · 1 общих теговslope-direction-line-alert-indicator.mq5MQL5 / MetaTrader 5 · 1 общих тегов2 ma crosses (arrows or lines mtf + alerts).mq5MQL5 / MetaTrader 5 · 1 общих теговswing arrows.mq5MQL5 / MetaTrader 5 · 1 общих тегов2ma.mq5MQL5 / MetaTrader 5 · 1 общих теговanchorfx.mq4MQL4 / MetaTrader 4 · 1 общих тегов
Вы автор или правообладатель?

Сообщите нам, если считаете, что материал размещён без разрешения.

Краткий обзор

О программе

Индикатор рассчитывает Hull Moving Average (HMA) с каналами на основе ATR (Average True Range). Основная линия HMA отображается цветом в зависимости от направления тренда: зелёный — восходящий, красный — нисходящий, оранжевый — основной HMA. Построено 7 пар верхних и нижних границ каналов с различными множителями ATR.

На графике размещена кнопка, позволяющая включать и отключать отображение всех линий индикатора. Состояние кнопки сохраняется в глобальной переменной терминала. Индикатор работает на текущем таймфрейме и поддерживает различные типы цен и методы усреднения.

Индикатор использует 17 буферов для отрисовки: основная линия HMA, её компоненты и 7 пар линий каналов. Также рассчитывается буфер ATR для формирования границ каналов. Параметры периода, скорости, множителей и визуального оформления кнопки настраиваются пользователем.

Настройки программы

НастройкаОписание
BandsPeriod Период расчёта полос индикатора
BandsPrice Тип цены для расчёта индикатора
BandsMethod Тип скользящей средней для расчёта HMA
BandsSpeed Скорость расчёта HMA
BandsShift Сдвиг индикатора в барах
ATRMultiplier1 Множитель ATR для первой пары каналов
ATRMultiplier2 Множитель ATR для второй пары каналов
ATRMultiplier3 Множитель ATR для третьей пары каналов
ATRMultiplier4 Множитель ATR для четвёртой пары каналов
ATRMultiplier5 Множитель ATR для пятой пары каналов
ATRMultiplier6 Множитель ATR для шестой пары каналов
ATRMultiplier7 Множитель ATR для седьмой пары каналов
button_note1 Текстовое примечание кнопки 1
btn_corner Угол графика для привязки кнопки
btn_text Текст, отображаемый на кнопке
btn_Font Шрифт текста на кнопке
btn_FontSize Размер шрифта текста на кнопке
btn_text_ON_color Цвет текста кнопки при включённом отображении
btn_text_OFF_color Цвет текста кнопки при отключённом отображении
btn_background_color Цвет фона кнопки
btn_border_color Цвет рамки кнопки
button_x Горизонтальное положение кнопки от угла графика
button_y Вертикальное положение кнопки от угла графика
btn_Width Ширина кнопки в пикселях
btn_Height Высота кнопки в пикселях
button_note2 Текстовое примечание кнопки 2

Поиск по коду файла

#property indicator_chart_window
#property indicator_buffers 17

#property indicator_color1  clrLawnGreen // main HMA in uptrend
#property indicator_color2  clrRed    // HMA in downtrend
#property indicator_color3  clrOrange

#property indicator_color4  clrSpringGreen //upperbuffer1
#property indicator_color5  clrHotPink     //lowerbuffer1
#property indicator_color6  clrSpringGreen
#property indicator_color7  clrHotPink
#property indicator_color8  clrSpringGreen
#property indicator_color9  clrHotPink
#property indicator_color10 clrSpringGreen
#property indicator_color11 clrHotPink
#property indicator_color12 clrSpringGreen
#property indicator_color13 clrHotPink
#property indicator_color14 clrSpringGreen
#property indicator_color15 clrHotPink
#property indicator_color16 clrSpringGreen //upperbuffer7
#property indicator_color17 clrHotPink     //lowerbuffer7

#property indicator_style4  STYLE_DOT
#property indicator_style5  STYLE_DOT
#property indicator_style6  STYLE_DOT
#property indicator_style7  STYLE_DOT
#property indicator_style8  STYLE_DOT
#property indicator_style9  STYLE_DOT
#property indicator_style10 STYLE_DOT
#property indicator_style11 STYLE_DOT
#property indicator_style12 STYLE_DOT
#property indicator_style13 STYLE_DOT
#property indicator_style14 STYLE_SOLID
#property indicator_style15 STYLE_SOLID
#property indicator_style16 STYLE_SOLID
#property indicator_style17 STYLE_SOLID

#property  indicator_width1  3
#property  indicator_width2  3
#property  indicator_width3  3
#property  indicator_width4  1
#property  indicator_width5  1
#property  indicator_width6  1
#property  indicator_width7  1
#property  indicator_width8  1
#property  indicator_width9  1
#property  indicator_width10 1
#property  indicator_width11 1
#property  indicator_width12 1
#property  indicator_width13 1
#property  indicator_width14 1
#property  indicator_width15 1
#property  indicator_width16 2
#property  indicator_width17 2

enum enPrices
{
   pr_close,      // Close
   pr_open,       // Open
   pr_high,       // High
   pr_low,        // Low
   pr_median,     // Median
   pr_typical,    // Typical
   pr_weighted,   // Weighted
   pr_average,    // Average (high+low+open+close)/4
   pr_medianb,    // Average median body (open+close)/2
   pr_tbiased,    // Trend biased price
   pr_tbiased2,   // Trend biased (extreme) price
   pr_haclose,    // Heiken ashi close
   pr_haopen ,    // Heiken ashi open
   pr_hahigh,     // Heiken ashi high
   pr_halow,      // Heiken ashi low
   pr_hamedian,   // Heiken ashi median
   pr_hatypical,  // Heiken ashi typical
   pr_haweighted, // Heiken ashi weighted
   pr_haaverage,  // Heiken ashi average
   pr_hamedianb,  // Heiken ashi median body
   pr_hatbiased,  // Heiken ashi trend biased price
   pr_hatbiased2, // Heiken ashi trend biased (extreme) price
   pr_habclose,   // Heiken ashi (better formula) close
   pr_habopen ,   // Heiken ashi (better formula) open
   pr_habhigh,    // Heiken ashi (better formula) high
   pr_hablow,     // Heiken ashi (better formula) low
   pr_habmedian,  // Heiken ashi (better formula) median
   pr_habtypical, // Heiken ashi (better formula) typical
   pr_habweighted,// Heiken ashi (better formula) weighted
   pr_habaverage, // Heiken ashi (better formula) average
   pr_habmedianb, // Heiken ashi (better formula) median body
   pr_habtbiased, // Heiken ashi (better formula) trend biased price
   pr_habtbiased2 // Heiken ashi (better formula) trend biased (extreme) price
};
enum enMaTypes
{
   ma_sma,     // Simple moving average
   ma_ema,     // Exponential moving average
   ma_smma,    // Smoothed MA
   ma_lwma,    // Linear weighted MA
   ma_slwma,   // Smoothed LWMA
   ma_dsema,   // Double Smoothed Exponential average
   ma_tema,    // Triple exponential moving average - TEMA
   ma_lsma     // Linear regression value (lsma)
};

extern int        BandsPeriod     = 34;
extern enPrices   BandsPrice      = pr_close;       // Price to use
extern enMaTypes  BandsMethod     = ma_lwma;        // Hma average type
extern double     BandsSpeed      = 1.0;            // Hma Speed
extern int        BandsShift      = 0;
extern double     ATRMultiplier1  = 1.618; //was 2.1
extern double     ATRMultiplier2  = 2.0;   //was 4.2
extern double     ATRMultiplier3  = 2.236; //was 6.3
extern double     ATRMultiplier4  = 2.5;
extern double     ATRMultiplier5  = 2.618;
extern double     ATRMultiplier6  = 3.0;
extern double     ATRMultiplier7  = 3.236;

extern string              button_note1          = "------------------------------";
extern ENUM_BASE_CORNER    btn_corner            = CORNER_LEFT_UPPER; // chart btn_corner for anchoring
extern string              btn_text              = "HMA34";
extern string              btn_Font              = "Arial";
extern int                 btn_FontSize          = 10;                             //btn__font size
extern color               btn_text_ON_color     = clrWhite;
extern color               btn_text_OFF_color    = clrRed;
extern color               btn_background_color  = clrDimGray;
extern color               btn_border_color      = clrBlack;
extern int                 button_x              = 20;                                     //btn__x
extern int                 button_y              = 13;                                     //btn__y
extern int                 btn_Width             = 60;                                 //btn__width
extern int                 btn_Height            = 20;                                //btn__height
extern string              button_note2          = "------------------------------";
bool                       show_data             = true;
string IndicatorName, IndicatorObjPrefix;

double MovingBuffer[];
double hmaDa[];
double hmaDb[];

double UpperBuffer1[];
double LowerBuffer1[],ATR_Buffer[];
double UpperBuffer2[];
double LowerBuffer2[];
double UpperBuffer3[];
double LowerBuffer3[];
double UpperBuffer4[];
double LowerBuffer4[];
double UpperBuffer5[];
double LowerBuffer5[];

double UpperBuffer6[];
double LowerBuffer6[];
double UpperBuffer7[];
double LowerBuffer7[];
double tem[];
int    HalfPeriod,HullPeriod;
double trend[];
bool   returnBars;
int   TimeFrame       = PERIOD_CURRENT; // Time frame to use

string GenerateIndicatorName(const string target) //don't change anything here
{
   string name = target;
   int try = 2;
   while (WindowFind(name) != -1)
   {
      name = target + " #" + IntegerToString(try++);
   }
   return name;
}

string buttonId;

int OnInit()
{
      // код доступен только после оплаты
   }

void createButton(string buttonID,string buttonText,int width,int height,string font,int fontSize,color bgColor,color borderColor,color txtColor)
{
      ObjectDelete    (ChartID(),buttonID);
      ObjectCreate    (ChartID(),buttonID,OBJ_BUTTON,0,0,0);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_COLOR,txtColor);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_BGCOLOR,bgColor);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_BORDER_COLOR,borderColor);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_XSIZE,width);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_YSIZE,height);
      ObjectSetString (ChartID(),buttonID,OBJPROP_FONT,font);
      ObjectSetString (ChartID(),buttonID,OBJPROP_TEXT,buttonText);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_FONTSIZE,fontSize);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_SELECTABLE,0);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_CORNER,btn_corner);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_HIDDEN,1);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_XDISTANCE,9999);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_YDISTANCE,9999);
}

int deinit()
{
   ObjectsDeleteAll(ChartID(), IndicatorObjPrefix);

	return(0);
}

bool recalc = true;

void handleButtonClicks()
{
   if (ObjectGetInteger(ChartID(), buttonId, OBJPROP_STATE))
   {
      ObjectSetInteger(ChartID(), buttonId, OBJPROP_STATE, false);
      show_data = !show_data;
      GlobalVariableSet(IndicatorName + "_visibility", show_data ? 1.0 : 0.0);
      recalc = true;
      start();
   }
}

void OnChartEvent(const int id, //don't change anything here in this function
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   handleButtonClicks();
}

int init2()
  {
   IndicatorBuffers(20);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,MovingBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,hmaDa);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,hmaDb);

   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,UpperBuffer1);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,LowerBuffer1);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,UpperBuffer2);
   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6,LowerBuffer2);
   SetIndexStyle(7,DRAW_LINE);
   SetIndexBuffer(7,UpperBuffer3);
   SetIndexStyle(8,DRAW_LINE);
   SetIndexBuffer(8,LowerBuffer3);
   SetIndexStyle(9,DRAW_LINE);
   SetIndexBuffer(9,UpperBuffer4);
   SetIndexStyle(10,DRAW_LINE);
   SetIndexBuffer(10,LowerBuffer4);
   SetIndexStyle(11,DRAW_LINE);
   SetIndexBuffer(11,UpperBuffer5);
   SetIndexStyle(12,DRAW_LINE);
   SetIndexBuffer(12,LowerBuffer5);

   SetIndexStyle(13,DRAW_LINE);
   SetIndexBuffer(13,UpperBuffer6);
   SetIndexStyle(14,DRAW_LINE);
   SetIndexBuffer(14,LowerBuffer6);
   SetIndexStyle(15,DRAW_LINE);
   SetIndexBuffer(15,UpperBuffer7);
   SetIndexStyle(16,DRAW_LINE);
   SetIndexBuffer(16,LowerBuffer7);

   SetIndexBuffer(17,ATR_Buffer);
   SetIndexBuffer(18,tem);
   SetIndexBuffer(19, trend);

   BandsPeriod  = (int)fmax(2,BandsPeriod);
   HalfPeriod   = (int)floor(BandsPeriod/BandsSpeed);
   HullPeriod   = (int)floor(sqrt(BandsPeriod));
   for (int i=0; i<17; i++) SetIndexShift(i,BandsShift*TimeFrame/_Period);
   returnBars        = TimeFrame==-99;
   TimeFrame         = fmax(TimeFrame,_Period);
   IndicatorShortName(timeFrameToString(TimeFrame)+" HMA("+(string)BandsPeriod+")");
   return(0);
  }

int start()
{
      // код доступен только после оплаты
   }
   handleButtonClicks();
   recalc = false;
   int      counted_bars=IndicatorCounted(), limit, i;

   if(counted_bars < 0) return(-1);
   if(counted_bars>0) counted_bars--;
      limit = Bars;
      if (show_data)
         {
          ObjectSetInteger(ChartID(),buttonId,OBJPROP_COLOR,btn_text_ON_color);
          for (int banzai=0; banzai<indicator_buffers; banzai++) //have to be here
              SetIndexStyle(banzai,DRAW_LINE);                   //have to be here

          if (returnBars) { MovingBuffer[0] = fmin(limit+1,Bars-1); return(0); }

          if (TimeFrame == Period())
          {         
            if (trend[limit]==-1) CleanPoint(limit,hmaDa,hmaDb);
            for(i=limit; i>=0; i--)
            {
             double price = getPrice(BandsPrice,Open,Close,High,Low,i,Bars);
             tem[i] = iCustomMa(BandsMethod,price,HalfPeriod,i,Bars,0)*2-iCustomMa(BandsMethod,price,BandsPeriod,i,Bars,1);
             MovingBuffer[i] = iCustomMa(BandsMethod,tem[i],HullPeriod,i,Bars,2); // you can make mode and price as variables as well
             ATR_Buffer[i]=iATR(NULL,0,100,i);//change this to some other envelope calculation as you wish
             hmaDa[i] = EMPTY_VALUE;
             hmaDb[i] = EMPTY_VALUE;
             trend[i] = (i<Bars-1) ? (MovingBuffer[i]>MovingBuffer[i+1]) ? 1 : (MovingBuffer[i]<MovingBuffer[i+1]) ? -1 : trend[i+1] : 0;  
             if (trend[i]==-1) PlotPoint

Показано первые 50% кода (символов: 18605)