Indicator does show up false on live chart

 

I've tried recreating an Indicator by copy and pasting. It works just fine when debugging on historical data, but works terribly on live cahrt (if it shows up it shows one bar).

Please ignore the terrible Coding Style, since I don't really know MQL5 I just tried wielding the Power of Copy and Paste.

Since you probably have way more experience than I have, I hope you could help me in finding my mistakes.
//+------------------------------------------------------------------+
//|                                                  Brooky.mh5      |
//|                        Copyright 2010, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
//+--------------------------------------------
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_plots   6
//--- plot slow_array
#property indicator_label1  "slow_array"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDodgerBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_level1 0
//--- plot up_hist
#property indicator_label2  "up_hist"
#property indicator_type2   DRAW_HISTOGRAM
#property indicator_color2  clrDodgerBlue
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2
//--- plot dn_hist
#property indicator_label3  "dn_hist"
#property indicator_type3   DRAW_HISTOGRAM
#property indicator_color3  clrCrimson
#property indicator_style3  STYLE_SOLID
#property indicator_width3  2
//--- plot tup_hist
#property indicator_label4  "tup_hist"
#property indicator_type4   DRAW_HISTOGRAM
#property indicator_color4  clrGray
#property indicator_style4  STYLE_SOLID
#property indicator_width4  2
//--- plot tdn_hist
#property indicator_label5  "tdn_hist"
#property indicator_type5   DRAW_HISTOGRAM
#property indicator_color5  clrDodgerBlue
#property indicator_style5  STYLE_SOLID
#property indicator_width5  2
//--- plot sig_array
#property indicator_label6  "sig_array"
#property indicator_type6   DRAW_LINE
#property indicator_color6  clrPink
#property indicator_style6  STYLE_SOLID
#property indicator_width6  2
//--- plot move_array
//#property indicator_label7  "move_array"
//#property indicator_type7   DRAW_LINE
//#property indicator_color7  clrMediumOrchid
//#property indicator_style7  STYLE_SOLID
//#property indicator_width7  1

#define     MODE_OPEN  0
#define     MODE_CLOSE  1
#define     MODE_HIGH  2
#define     MODE_LOW  3
#define     MODE_TICKVOLUME  4
#define     MODE_REALVOLUME  5


#define     PERIOD_CURRENT  0
#define     PERIOD_M1  1
#define     PERIOD_M5  5
#define     PERIOD_M15  15
#define     PERIOD_M30  30
#define     PERIOD_H1  16385
#define     PERIOD_H4  16388
#define     PERIOD_D1  16408
#define     PERIOD_W1  32769
#define     PERIOD_MN1  49153

double            Open[];
double            Close[];
double            High[];
double            Low[];
double Ask,Bid;
int CountedMQL4;
//--- input parameters
input int      SlowPeriod=26;
input int      FastPeriod=12;
input int SignalPeriod = 9;
input ENUM_MA_METHOD      SignalPeriodMethod;
input ENUM_MA_METHOD     SlowPeriodMethod;
input ENUM_MA_METHOD      FastPeriodMethod;
input ENUM_APPLIED_PRICE      PriceConstant=MODE_CLOSE;
input int      MinMove=1;
input int      HighLowbarsBack=5;
//--- indicator buffers
double         slow_arrayBuffer[];
double         up_histBuffer[];
double         dn_histBuffer[];
double         tup_histBuffer[];
double         tdn_histBuffer[];
double         sig_arrayBuffer[];
double         move_arrayBuffer[];


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
ENUM_TIMEFRAMES FixTF(int TimeFrame)
  {
   switch(TimeFrame)
     {
      case 0:
         return(PERIOD_CURRENT);
      case 1:
         return(PERIOD_M1);
      case 5:
         return(PERIOD_M5);
      case 15:
         return(PERIOD_M15);
      case 30:
         return(PERIOD_M30);
      case 60:
         return(PERIOD_H1);
      case 240:
         return(PERIOD_H4);
      case 1440:
         return(PERIOD_D1);
      case 10080:
         return(PERIOD_W1);
      case 43200:
         return(PERIOD_MN1);

      case 2:
         return(PERIOD_M2);
      case 3:
         return(PERIOD_M3);
      case 4:
         return(PERIOD_M4);
      case 6:
         return(PERIOD_M6);
      case 10:
         return(PERIOD_M10);
      case 12:
         return(PERIOD_M12);
      case 16385:
         return(PERIOD_H1);
      case 16386:
         return(PERIOD_H2);
      case 16387:
         return(PERIOD_H3);
      case 16388:
         return(PERIOD_H4);
      case 16390:
         return(PERIOD_H6);
      case 16392:
         return(PERIOD_H8);
      case 16396:
         return(PERIOD_H12);
      case 16408:
         return(PERIOD_D1);
      case 32769:
         return(PERIOD_W1);
      case 49153:
         return(PERIOD_MN1);
      default:
         return(PERIOD_CURRENT);
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,slow_arrayBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,up_histBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,dn_histBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,tup_histBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,tdn_histBuffer,INDICATOR_DATA);
   SetIndexBuffer(5,sig_arrayBuffer,INDICATOR_DATA);
   SetIndexBuffer(6,move_arrayBuffer,INDICATOR_CALCULATIONS);
   ArraySetAsSeries(slow_arrayBuffer,true);
   ArraySetAsSeries(up_histBuffer,true);
   ArraySetAsSeries(dn_histBuffer,true);
   ArraySetAsSeries(tup_histBuffer,true);
   ArraySetAsSeries(tdn_histBuffer,true);
   ArraySetAsSeries(sig_arrayBuffer,true);
   ArraySetAsSeries(move_arrayBuffer,true);
   ArraySetAsSeries(Open,true);
   ArraySetAsSeries(Close,true);
   ArraySetAsSeries(High,true);
   ArraySetAsSeries(Low,true);



//---
   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[])
  {
//---
   int bars = MQL4Run(rates_total, prev_calculated);

   int limit;
   double ma_now,ma_b4;
   int counted_bars=prev_calculated;
//---- check for possible errors
   if(counted_bars<0)
      return(-1);
//---- the last counted bar will be recounted
   if(counted_bars>0)
      counted_bars--;
   limit=bars-counted_bars;
//---- main loop
   for(int i=0; i<limit; i++)
     {
      //--trend--+
      //--sensitivity--+
      move_arrayBuffer[i] = MathAbs((((iHighest(NULL,0,MODE_HIGH,HighLowbarsBack,i)-iLowest(NULL,0,MODE_LOW,HighLowbarsBack,i)))*_Point)*100000);
      //--power--+
      slow_arrayBuffer[i] = iStdDevMql4(NULL,0,SlowPeriod,0,SlowPeriodMethod,PriceConstant, i)
                            - iATRMql4(NULL,0,SlowPeriod,i);
      int ma_now =iMAMql4(NULL, 0,FastPeriod,0,FastPeriodMethod,PriceConstant, i);
      int ma_b4 =iMAMql4(NULL, 0, FastPeriod,0,FastPeriodMethod,PriceConstant, i+1);

      //--drawing--+
      if(ma_now>=ma_b4 && move_arrayBuffer[i]>=MinMove)
         up_histBuffer[i] = slow_arrayBuffer[i];


      if(ma_now<=ma_b4 && move_arrayBuffer[i]>=MinMove)
         dn_histBuffer[i] = slow_arrayBuffer[i];


      if(ma_now<=ma_b4 && move_arrayBuffer[i]<=MinMove)
         tup_histBuffer[i]=slow_arrayBuffer[i];

      if(ma_now>=ma_b4 && move_arrayBuffer[i]<=MinMove)
         tdn_histBuffer[i]=slow_arrayBuffer[i];
     }
//--power smooth--+
   for(int i=0; i<limit; i++)
     {
      sig_arrayBuffer[i] = iMAOnArrayMql4(slow_arrayBuffer,0,SignalPeriod,0,SignalPeriodMethod,i);


     }


//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int MQL4Run(int rates_total,int prev_calculated)// bars - number of bars for recalculation
  {
   int Uncount=rates_total-prev_calculated;
   if(Uncount==0)
     {
      GetMQL4Tick();
     }
   else
      GetMQL4();
   return(ArraySize(Close));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void GetMQL4()
  {
   datetime endAte=0;
   datetime startdate=TimeTradeServer();

   CopyOpen(Symbol(),Period(),startdate,endAte,Open);
   CopyHigh(Symbol(),Period(),startdate,endAte,High);
   CopyLow(Symbol(),Period(),startdate,endAte,Low);
   CopyClose(Symbol(),Period(),startdate,endAte,Close);

   MqlTick  tick;
   SymbolInfoTick(Symbol(),tick);
   Ask = tick.ask;
   Bid = tick.bid;
   CountedMQL4=0;
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void GetMQL4Tick()
  {
   MqlRates rates[1];
   CopyRates(Symbol(),0,0,1,rates);
   Open[0]=rates[0].open;
   Close[0]=rates[0].close;
   High[0]=rates[0].high;
   Low[0]=rates[0].low;
   MqlTick  tick;
   SymbolInfoTick(Symbol(),tick);
   Ask = tick.ask;
   Bid = tick.bid;
   CountedMQL4=ArraySize(Close);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double iMAMql4(string Symb,int TimFrame,int iMAPeriod,int ma_shift,ENUM_MA_METHOD ma_method,ENUM_APPLIED_PRICE applied_price,int Shift)
  {
   ENUM_TIMEFRAMES TimFram=FixTF(TimFrame);
   double mass[1];
   int handle=iMA(Symb,TimFram,iMAPeriod,ma_shift,ma_method,applied_price);
   if(handle<0)
     {
      Print("Failed to create the iMA object: Error ",GetLastError());
      return(0);
     }
   else
      if(CopyBuffer(handle, 0, Shift, 1, mass) <= 0)
         return(0);
   return(mass[0]);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double iStdDevMql4(string Symb,int TimFrame,int iMAPeriod,int ma_shift,ENUM_MA_METHOD ma_method,ENUM_APPLIED_PRICE applied_price,int Shift)
  {
   ENUM_TIMEFRAMES TimFram=FixTF(TimFrame);
   double mass[1];
   int handle=iStdDev(Symb,TimFram,iMAPeriod,ma_shift,ma_method,applied_price);
   if(handle<0)
     {
      Print("Failed to create the iMA object: Error ",GetLastError());
      return(0);
     }
   else
      if(CopyBuffer(handle, 0, Shift, 1, mass) <= 0)
         return(0);
   return(mass[0]);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double iATRMql4(string Symb,int TimFrame,int iMAPeriod,int Shift)
  {
   ENUM_TIMEFRAMES TimFram=FixTF(TimFrame);
   double mass[1];
   int handle=iATR(Symb,TimFram,iMAPeriod);
   if(handle<0)
     {
      Print("Failed to create the iMA object: Error ",GetLastError());
      return(0);
     }
   else
      if(CopyBuffer(handle, 0, Shift, 1, mass) <= 0)
         return(0);
   return(mass[0]);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double iMAOnArrayMql4(double &Array[],int total,int iMAPeriod,int ma_shift,ENUM_MA_METHOD ma_method,int Shift)
  {
   double buf[];
   if(total>0 && total<=iMAPeriod)
      return(0);
   if(total==0)
      total=ArraySize(Array);
   if(ArrayResize(buf,total)<0)
      return(0);
   switch(ma_method)
     {
      case MODE_SMA :
        {
         double sum=0;
         int    i,pos=total-1;
         for(i=1; i<iMAPeriod; i++,pos--)
            sum+=Array[pos];
         while(pos>=0)
           {
            sum+=Array[pos];
            buf[pos]=sum/iMAPeriod;
            sum-=Array[pos+iMAPeriod-1];
            pos--;
           }
         return(buf[Shift+ma_shift]);
        }
      case MODE_EMA :
        {
         double pr=2.0/(iMAPeriod+1);
         int    pos=total-2;
         while(pos>=0)
           {
            if(pos==total-2)
               buf[pos+1]=Array[pos+1];
            buf[pos]=Array[pos]*pr+buf[pos+1]*(1-pr);
            pos--;
           }
         return(buf[Shift+ma_shift]);
        }
      case MODE_SMMA :
        {
         double sum=0;
         int    i,k,pos;
         pos=total-iMAPeriod;
         while(pos>=0)
           {
            if(pos==total-iMAPeriod)
              {
               for(i=0,k=pos; i<iMAPeriod; i++,k++)
                 {
                  sum+=Array[k];
                  buf[k]=0;
                 }
              }
            else
               sum=buf[pos+1]*(iMAPeriod-1)+Array[pos];
            buf[pos]=sum/iMAPeriod;
            pos--;
           }
         return(buf[Shift+ma_shift]);
        }
      case MODE_LWMA :
        {
         double sum=0.0,lsum=0.0;
         double price;
         int    i,weight=0,pos=total-1;
         for(i=1; i<=iMAPeriod; i++,pos--)
           {
            price=Array[pos];
            sum+=price*i;
            lsum+=price;
            weight+=i;
           }
         pos++;
         i=pos+iMAPeriod;
         while(pos>=0)
           {
            buf[pos]=sum/weight;
            if(pos==0)
               break;
            pos--;
            i--;
            price=Array[pos];
            sum=sum-lsum+price*iMAPeriod;
            lsum-=Array[i];
            lsum+=price;
           }
         return(buf[Shift+ma_shift]);
        }
      default:
         return(0);
     }
   return(0);
  }
//+------------------------------------------------------------------+

Thanks in advance.

 
double iMAMql4(string Symb,int TimFrame,int iMAPeriod,int ma_shift,ENUM_MA_METHOD ma_method,ENUM_APPLIED_PRICE applied_price,int Shift)
  {
   ENUM_TIMEFRAMES TimFram=FixTF(TimFrame);
   double mass[1];
   int handle=iMA(Symb,TimFram,iMAPeriod,ma_shift,ma_method,applied_price);
   if(handle<0)
     {
      Print("Failed to create the iMA object: Error ",GetLastError());
      return(0);
     }
   else
      if(CopyBuffer(handle, 0, Shift, 1, mass) <= 0)

Perhaps you should read the manual, especially the examples.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
          MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
          How to call indicators in MQL5 - MQL5 Articles (2010)