Мультитаймфреймовые индикаторы - страница 1225

 
пробовал DRAW_SECTION не помогло
 
Oleg Kubenko #:

попытался переписать индикатор новый на MQL5 https://www.mql5.com/en/code/49534?utm_source=mql5.com.tg&utm_medium=message&utm_campaign=articles.codes.repost

но он не отображается , можете помочь?


он в упор не хочет отображаться 

Разверните индексацию буферов при помощи ArraySetAsSeries().

 
и что это дало? 
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots   5
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDeepSkyBlue
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrYellow
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrDeepSkyBlue
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrYellow
#property indicator_type5   DRAW_LINE
#property indicator_color5  clrRed
#property indicator_width5  2
input int                inpRsiPeriod        = 14;          // RSI period
input ENUM_APPLIED_PRICE inpPrice            = PRICE_CLOSE; // RSI price

input int                inpSmoothing        = 14;          // Smoothing period for RSI
input double             inpOverbought       = 70;          // Overbought level %
input double             inpOversold         = 30;          // Oversold level %
input double             inpUpperNeutral     = 55;          // Upper neutral level %
input double             inpLowerNeutral     = 45;          // Lower neutral level %

double bupu[],bupd[],bdnu[],bdnd[],rsi[];
//+------------------------------------------------------------------+
int OnInit()
{
   SetIndexBuffer(0, bupu, INDICATOR_DATA);
   SetIndexBuffer(1, bupd, INDICATOR_DATA);
   SetIndexBuffer(2, bdnu, INDICATOR_DATA);
   SetIndexBuffer(3, bdnd, INDICATOR_DATA);
   SetIndexBuffer(4, rsi, INDICATOR_CALCULATIONS);

   ArraySetAsSeries(bupu, true);
   ArraySetAsSeries(bupd, true);
   ArraySetAsSeries(bdnu, true);
   ArraySetAsSeries(bdnd, true);
   ArraySetAsSeries(rsi, true);

   PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(0, PLOT_LINE_COLOR, clrDeepSkyBlue);
   PlotIndexSetInteger(0, PLOT_LINE_WIDTH, 1);

   PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(1, PLOT_LINE_COLOR, clrYellow);
   PlotIndexSetInteger(1, PLOT_LINE_WIDTH, 1);

   PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(2, PLOT_LINE_COLOR, clrDeepSkyBlue);
   PlotIndexSetInteger(2, PLOT_LINE_WIDTH, 1);

   PlotIndexSetInteger(3, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(3, PLOT_LINE_COLOR, clrYellow);
   PlotIndexSetInteger(3, PLOT_LINE_WIDTH, 1);

   PlotIndexSetInteger(4, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(4, PLOT_LINE_COLOR, clrRed);
   PlotIndexSetInteger(4, PLOT_LINE_WIDTH, 2);

   return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
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 limit = prev_calculated > 0 ? rates_total - prev_calculated + 1 : rates_total - 1;

   for(int i = rates_total - 1; i >= 0; i--) {
      Print(i);
      rsi[i] = iRSI(NULL, PERIOD_CURRENT, inpRsiPeriod, inpPrice);
      double _rsi = (rsi[i] != EMPTY_VALUE) ? rsi[i] : 0;

      bupu[i] = iEma(_rsi - inpOverbought, inpSmoothing, i, 0);
      bdnu[i] = iEma(_rsi - inpOversold, inpSmoothing, i, 1);
      bupd[i] = iEma(_rsi - inpUpperNeutral, inpSmoothing, i, 2);
      bdnd[i] = iEma(_rsi - inpLowerNeutral, inpSmoothing, i, 3);

      double pr = 2.0 / (inpSmoothing + 1.0);
      if(i < rates_total - 1) {
         bupu[i] = (_rsi - inpOverbought) * pr + bupu[i + 1] * (1 - pr);
         bdnu[i] = (_rsi - inpOversold) * pr + bdnu[i + 1] * (1 - pr);
         bupd[i] = (_rsi - inpUpperNeutral) * pr + bupd[i + 1] * (1 - pr);
         bdnd[i] = (_rsi - inpLowerNeutral) * pr + bdnd[i + 1] * (1 - pr);
      } else {
         bupu[i] = (_rsi - inpOverbought);
         bdnu[i] = (_rsi - inpOversold);
         bupd[i] = (_rsi - inpUpperNeutral);
         bdnd[i] = (_rsi - inpLowerNeutral);
      }

      rsi[i] -= 50;
   }
   return rates_total;
}

//+------------------------------------------------------------------+
#define _emaInstances 4
#define _emaRingSize 6
double workEma[_emaRingSize][_emaInstances];
//
//---
//


double iEma(double price, double period,int i, int _inst=0)
{
   int _indCurrent = (i  )%_emaRingSize;
   int _indPrevious = (i-1)%_emaRingSize;

   if(i>0 && period>1)
      workEma[_indCurrent][_inst] = workEma[_indPrevious][_inst] + (2.0/(1.0+period)) * (price-workEma[_indPrevious][_inst]);
   else   workEma[_indCurrent][_inst]=price;
   return(workEma[_indCurrent][_inst]);
}
 

в общем долго колдуя и мучаясь удалось собрать такой код этого индикатора но тут красная линия мне кажется не так выглядит как у автора

#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots   5
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDeepSkyBlue
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrYellow
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrDeepSkyBlue
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrYellow
#property indicator_type5   DRAW_LINE
#property indicator_color5  clrRed
#property indicator_width5  1

input int                inpRsiPeriod        = 14;          // RSI period
input ENUM_APPLIED_PRICE inpPrice            = PRICE_CLOSE; // RSI price
input int                inpSmoothing        = 14;          // Smoothing period for RSI
input double             inpOverbought       = 70;          // Overbought level %
input double             inpOversold         = 30;          // Oversold level %
input double             inpUpperNeutral     = 55;          // Upper neutral level %
input double             inpLowerNeutral     = 45;          // Lower neutral level %

double bupu[], bupd[], bdnu[], bdnd[], rsi[];

int rsiHandle;

//+------------------------------------------------------------------+
int OnInit()
{
   SetIndexBuffer(0, bupu, INDICATOR_DATA);
   SetIndexBuffer(1, bupd, INDICATOR_DATA);
   SetIndexBuffer(2, bdnu, INDICATOR_DATA);
   SetIndexBuffer(3, bdnd, INDICATOR_DATA);
   SetIndexBuffer(4, rsi, INDICATOR_CALCULATIONS);

   ArraySetAsSeries(bupu, true);
   ArraySetAsSeries(bupd, true);
   ArraySetAsSeries(bdnu, true);
   ArraySetAsSeries(bdnd, true);
   ArraySetAsSeries(rsi, true);

   PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(0, PLOT_LINE_COLOR, clrDeepSkyBlue);
   PlotIndexSetInteger(0, PLOT_LINE_WIDTH, 1);

   PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(1, PLOT_LINE_COLOR, clrYellow);
   PlotIndexSetInteger(1, PLOT_LINE_WIDTH, 1);

   PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(2, PLOT_LINE_COLOR, clrDeepSkyBlue);
   PlotIndexSetInteger(2, PLOT_LINE_WIDTH, 1);

   PlotIndexSetInteger(3, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(3, PLOT_LINE_COLOR, clrYellow);
   PlotIndexSetInteger(3, PLOT_LINE_WIDTH, 1);

   PlotIndexSetInteger(4, PLOT_DRAW_TYPE, DRAW_LINE);
   PlotIndexSetInteger(4, PLOT_LINE_COLOR, clrRed);
   PlotIndexSetInteger(4, PLOT_LINE_WIDTH, 1);

   rsiHandle = iRSI(NULL, 0, inpRsiPeriod, inpPrice);
   if (rsiHandle == INVALID_HANDLE)
   {
      Print("Не удалось создать хэндл индикатора iRSI, код ошибки: ", GetLastError());
      return (INIT_FAILED);
   }

   return (INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
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 limit = rates_total - prev_calculated;
   if (prev_calculated == 0)
      limit -= 1;

   if (CopyBuffer(rsiHandle, 0, 0, limit, rsi) <= 0)
   {
      Print("Не удалось скопировать данные из индикатора iRSI, код ошибки: ", GetLastError());
      return (prev_calculated);
   }

for (int i = limit; i >= 0; i--) {
   bupu[i] = iMAOnArray(rsi, rates_total, inpSmoothing, 0, MODE_SMA, i) - inpOverbought;
   bdnu[i] = iMAOnArray(rsi, rates_total, inpSmoothing, 0, MODE_SMA, i) - inpOversold;
   bupd[i] = iMAOnArray(rsi, rates_total, inpSmoothing, 0, MODE_SMA, i) - inpUpperNeutral;
   bdnd[i] = iMAOnArray(rsi, rates_total, inpSmoothing, 0, MODE_SMA, i) - inpLowerNeutral;

   double midUpper = (bupu[i] + bdnu[i]);
   double midLower = (bupd[i] + bdnd[i]);

   rsi[i] = (midUpper + midLower);
}

   return rates_total;
}

//+------------------------------------------------------------------+
double iMAOnArray(const double &array[], int total, int period, int shift, int method, int index)
{
   if (period <= 0)
      return 0.0;

   double sum = 0.0;
   int count = 0;
   for (int i = index - period + 1; i <= index; i++) {
      if (i >= 0) {
         sum += array[i];
         count++;
      }
   }

   if (count == 0)
      return 0.0;

   return sum / count;
}

//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   if (rsiHandle != INVALID_HANDLE)
      IndicatorRelease(rsiHandle);
}
 

вобщем поколдовал еще но теперь линия красная находится над всеми оcтальными , подскажите как ее сделать в центре как у автора на изображении

 

сейчас это вот так:


#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots   5
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrBlue
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrWhite
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrLime
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrOrange
#property indicator_type5   DRAW_LINE
#property indicator_color5  clrRed
#property indicator_width5  1

input int                inpRsiPeriod        = 14;          // RSI period
input ENUM_APPLIED_PRICE inpPrice            = PRICE_CLOSE; // RSI price
input int                inpSmoothing        = 14;          // Smoothing period for RSI
input double             inpOverbought       = 70;          // Overbought level %
input double             inpOversold         = 30;          // Oversold level %
input double             inpUpperNeutral     = 55;          // Upper neutral level %
input double             inpLowerNeutral     = 45;          // Lower neutral level %

double Overbought[], UpperNeutral[], Oversold[], LowerNeutral[], Center[];

int RsiHandle = 0;

//+------------------------------------------------------------------+
int OnInit()
{
   SetIndexBuffer(0, Overbought, INDICATOR_DATA);
   SetIndexBuffer(1, UpperNeutral, INDICATOR_DATA);
   SetIndexBuffer(2, Oversold, INDICATOR_DATA);
   SetIndexBuffer(3, LowerNeutral, INDICATOR_DATA);
   SetIndexBuffer(4, Center, INDICATOR_DATA);

   ArraySetAsSeries(Overbought, true);
   ArraySetAsSeries(UpperNeutral, true);
   ArraySetAsSeries(Oversold, true);
   ArraySetAsSeries(LowerNeutral, true);
   ArraySetAsSeries(Center, true);

   RsiHandle = iRSI(_Symbol, _Period, inpRsiPeriod, inpPrice);
   if (RsiHandle == INVALID_HANDLE)
   {
      Print("Не удалось создать хэндл индикатора iRSI, код ошибки: ", GetLastError());
      return (INIT_FAILED);
   }

   return (INIT_SUCCEEDED);
}

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[])
{
   if (rates_total < inpRsiPeriod)
   {
      Print("Недостаточно данных для расчета RSI.");
      return 0;
   }

   int limit = rates_total - prev_calculated;
   if (prev_calculated == 0)
   {
      limit = rates_total - 1;
   }

   if (RsiHandle == INVALID_HANDLE)
   {
      Print("Хэндл индикатора iRSI недействителен.");
      return prev_calculated;
   }

   if (CopyBuffer(RsiHandle, 0, 0, rates_total, Center) < 0)
   {
      Print("Не удалось скопировать данные из индикатора iRSI, код ошибки: ", GetLastError());
      return prev_calculated;
   }

   for (int i = limit - 1; i >= 0; i--)
   {
      Overbought[i] = iMAOnArray(Center, rates_total, inpSmoothing, 0, MODE_SMA, i) - inpOverbought;
      Oversold[i] = iMAOnArray(Center, rates_total, inpSmoothing, 0, MODE_SMA, i) - inpOversold;

      UpperNeutral[i] = iMAOnArray(Center, rates_total, inpSmoothing, 0, MODE_SMA, i) - inpUpperNeutral;
      LowerNeutral[i] = iMAOnArray(Center, rates_total, inpSmoothing, 0, MODE_SMA, i) - inpLowerNeutral;

      Center[i] = (UpperNeutral[i] + LowerNeutral[i]) / 2;
   }

   return rates_total;
}

double iMAOnArray(const double &array[], int total, int period, int shift, int method, int index)
{
   if (period <= 0)
      return 0.0;

   double sum = 0.0;
   int count = 0;
   for (int i = index - period + 1; i <= index; i++) {
      if (i >= 0) {
         sum += array[i];
         count++;
      }
   }

   if (count == 0)
      return 0.0;

   return sum / count;
}

void OnDeinit(const int reason)
{
   if (RsiHandle != INVALID_HANDLE)
      IndicatorRelease(RsiHandle);
}
 
что примечательно с 15 минутного графика все норм а вот на одноминутном нехочет центрироваться линия
 
Oleg Kubenko #:

вобщем поколдовал еще но теперь линия красная находится над всеми оcтальными , подскажите как ее сделать в центре как у автора на изображении

 

сейчас это вот так:

Как этот и предыдущие вопросы связаны с темой ветки? Попробуйте написать в топики, более соответствующие вашим проблемам, может и ответы пойдут быстрее.
Причина обращения: