Индикатор мультитаймфрейма

 
Здравствуйте,

Я хотел бы создать индикатор, который проверяет на H1 и M15, есть ли Low<Скользящее среднее, а также закрывается ли цена выше Скользящего среднего. Я пробовал это делать некоторое время, но стрелок не видно и Скользящее среднее не рассчитывается. Кто-нибудь знает решение проблемы? Заранее спасибо.

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 3

#property indicator_label1 "Moving Average"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrRed,clrAzure

#property indicator_label2 "Arrow - Up"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrYellow

#property indicator_label3 "Arrow - Down"
#property indicator_type3 DRAW_ARROW
#property indicator_color3 clrAqua

int MovingAverage;
int MovingAverage2;

double UpBuffer[];
double DownBuffer[];
double MovingAverageBuffer[];
double MovingAverageBuffer2[];
double MovingAverageColor[];

int H1_M15;
int H1_H1;

datetime Period_Time_H1;

int NumberBars;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   SetIndexBuffer(0,MovingAverageBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,MovingAverageColor,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2,UpBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(2,PLOT_ARROW,233);
   SetIndexBuffer(3,DownBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(3,PLOT_ARROW,234);
   SetIndexBuffer(4,MovingAverageBuffer2,INDICATOR_CALCULATIONS);
   
   MovingAverage=iMA(_Symbol,PERIOD_H1,50,0,MODE_EMA,PRICE_CLOSE);
   if(MovingAverage==INVALID_HANDLE)
   {
      Print("The iMA object was not created: Error ",GetLastError());
      return INIT_FAILED;
   }
   
   MovingAverage2=iMA(_Symbol,PERIOD_M15,50,0,MODE_EMA,PRICE_CLOSE);
   if(MovingAverage2==INVALID_HANDLE)
   {
      Print("The iMA object was not created: Error ",GetLastError());
      return INIT_FAILED;
   }
   
   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[])
{
   MqlRates m_Rates_M15[];
   MqlRates m_Rates_H1[];
   
   ArraySetAsSeries(MovingAverageBuffer,true);
   ArraySetAsSeries(MovingAverageColor,true);
   ArraySetAsSeries(MovingAverageBuffer2,true);
   ArraySetAsSeries(UpBuffer,true);
   ArraySetAsSeries(DownBuffer,true);
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(m_Rates_M15,true);
   ArraySetAsSeries(m_Rates_H1,true);

   int copyRates_M15=CopyRates(_Symbol,PERIOD_M15,0,Bars(_Symbol,PERIOD_M15),m_Rates_M15);
   int copyRates_H1=CopyRates(_Symbol,PERIOD_H1,0,Bars(_Symbol,PERIOD_H1),m_Rates_H1);
   
   int copied=CopyBuffer(MovingAverage,0,0,Bars(_Symbol,PERIOD_H1),MovingAverageBuffer);
   int copied2=CopyBuffer(MovingAverage2,0,0,Bars(_Symbol,PERIOD_M15),MovingAverageBuffer2);
   
   if(Bars(_Symbol,PERIOD_H1)<Bars(_Symbol,PERIOD_M15))
   {
      NumberBars=Bars(_Symbol,PERIOD_H1);
   }
   else
   {
      NumberBars=Bars(_Symbol,PERIOD_M15);
   }
   
//   for(int i=0;i<rates_total;i++)
   for(int i=NumberBars-2;i>=0;i--)
   {
      UpBuffer[H1_H1]=EMPTY_VALUE;
      DownBuffer[H1_H1]=EMPTY_VALUE;
//      MovingAverageColor[H1_H1]=EMPTY_VALUE;
      
      Period_Time_H1=iTime(_Symbol,PERIOD_H1,i);
      H1_M15=iBarShift(_Symbol,PERIOD_M15,Period_Time_H1);
      H1_H1=iBarShift(_Symbol,PERIOD_H1,Period_Time_H1);
      
      Comment("H1_H1: ",H1_H1,
              "\nH1_M15: ",H1_M15);
      
      MovingAverageColor[H1_H1]=0;
      
      if(m_Rates_H1[H1_H1].open<m_Rates_H1[H1_H1].close)
      {
         if((m_Rates_H1[H1_H1].low<MovingAverageBuffer[H1_H1] && m_Rates_H1[H1_H1].open>MovingAverageBuffer[H1_H1])
         && (m_Rates_M15[H1_M15].low<MovingAverageBuffer2[H1_M15] && m_Rates_M15[H1_M15].open>MovingAverageBuffer2[H1_M15]))
         {
            UpBuffer[H1_H1]=low[H1_H1];
         }
      }
      if(m_Rates_H1[H1_H1].open>m_Rates_H1[H1_H1].close)
      {
         if((m_Rates_H1[H1_H1].low<MovingAverageBuffer[H1_H1] && m_Rates_H1[H1_H1].close>MovingAverageBuffer[H1_H1])
         && (m_Rates_M15[H1_M15].low<MovingAverageBuffer2[H1_M15] && m_Rates_M15[H1_M15].close>MovingAverageBuffer2[H1_M15]))
         {
            UpBuffer[H1_H1]=low[H1_H1];
         }
      }
   }

   return(rates_total);
}
//+------------------------------------------------------------------+
Причина обращения: