Indicator only appears in debugger! (Solved but new problem)

 

I have this extremely annoying problem - if someone can PLEASE help me.


I have written a Hull moving average, but it only appears on my chart when I run the debugger. If I attach it normally it doesn't run. If I exit the debugger, and then compile, it disappears again.

Please I need some help.

Must I attach source code?


Cobus

 
CobusSteyn0105:

I have this extremely annoying problem - if someone can PLEASE help me.


I have written a Hull moving average, but it only appears on my chart when I run the debugger. If I attach it normally it doesn't run. If I exit the debugger, and then compile, it disappears again.

Please I need some help.

Must I attach source code?


Cobus

If you don't attach the source code it will make it less likely that somebody will be able to suggest anything.

 
CobusSteyn0105:

I have this extremely annoying problem - if someone can PLEASE help me.


I have written a Hull moving average, but it only appears on my chart when I run the debugger. If I attach it normally it doesn't run. If I exit the debugger, and then compile, it disappears again.

Please I need some help.

Must I attach source code?


Cobus

I guess it's mql4 indicator and you are not using #property strict. Use it and fix your code.
 

Thank you Keith and Alain for your responses. I eventually got it sorted but are now confronted with a new problem and I'm stuck.

Yes it's mql4, and I have property strict on.

My new problem is this: the Hull moving average is drawn fine for a large part of the chart, but on scrolling to older portions it gets all wacky. I'll attach a screenshot.

wacky


Here is the source:

#property copyright "Copyright 2018 - Cobus Steyn"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots   2
//--- plot Hull_Up
#property indicator_label1  "Hull_Up"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrMediumSeaGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//---Plot Hull_Down
#property indicator_label2  "Hull_Down"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrTomato
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2

#include <CFXHullMA.mqh>


string HMAModesStr[] = {"SMA","EMA","SMMA","LWMA"};
enum HMAStatus {HMASTATUS_UP,HMASTATUS_DOWN};

//--- input parameters
extern int      period=10;
extern CFXHULLMA_MODE mode=CFXHMA_LWMA; //Mode: 0=SMA 1=EMA 2=SMMA 3=LWMA


//--- indicator buffers
double Hull_UpBuffer[],Hull_DownBuffer[],Hull_CurrStatus[];

CCFXHullMA CFXHMA; //Class

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  { 
//--- indicator buffers mapping
   SetIndexBuffer(0,Hull_UpBuffer);
   SetIndexBuffer(1,Hull_DownBuffer);
   SetIndexBuffer(2,Hull_CurrStatus,INDICATOR_CALCULATIONS);
   SetIndexStyle(2,DRAW_NONE);
   IndicatorShortName("CFX Hull Moving Average ("+IntegerToString(period)+")"+"("+HMAModesStr[mode]+")");
   IndicatorDigits(Digits+1);
   CFXHMA.Create(Symbol(),0,period,CFXHMA_LWMA);
 
//---
   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 idx,limit;
   double h0,h1,h2;
  
   //Print("rates_total = "+string(rates_total));
 //  Print("prev_calculated = "+string(prev_calculated));
   
   
   for (int i=rates_total-period;i>=0;i--) 
   {  
      h0 = CFXHMA.Calculate(i);
      h1 = CFXHMA.Calculate(i+1);
      h2 = CFXHMA.Calculate(i+2);
   
      if (h0>=h1 && h1>=h2) //up leg
      { Hull_UpBuffer[i] = h0; 
        Hull_UpBuffer[i+1] = h1;
        Hull_UpBuffer[i+2]=h2;
        Hull_CurrStatus[i] = HMASTATUS_UP;
      }
      if (h0<=h1 && h1<=h2) //down leg
      { Hull_DownBuffer[i] = h0;
        Hull_DownBuffer[i+1] = h1;
        Hull_DownBuffer[i+2] = h2;
        Hull_CurrStatus[i] = HMASTATUS_DOWN;
      }
      if (h0>=h1 && h1<=h2)  //pivot up
      { Hull_DownBuffer[i+1] = h1;
        Hull_UpBuffer[i+1] = h1;
        Hull_UpBuffer[i] = h0;
        Hull_DownBuffer[i+2] = h2;
        Hull_CurrStatus[i] = HMASTATUS_UP;
      }
      if (h0<h1 && h1>h2) //pivot down
      {
         Hull_DownBuffer[i+1] = h1;
         Hull_UpBuffer[i+1]=h1;
         Hull_DownBuffer[i]=h0;
         Hull_UpBuffer[i+2] = h2;
         Hull_CurrStatus[i] = HMASTATUS_DOWN;
      }
    }    
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

And the class:

#property copyright "Copyright 2019 - Cobus Steyn auxanotrading@gmail.com"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
/* CFX Hull moving average class */



enum CFXHULLMA_MODE {CFXHMA_SMA,CFXHMA_EMA,CFXHMA_SMMA,CFXHMA_LWMA}; //LWMA preferred
enum CFXHULLMA_STATE {CFXHMA_UP,CFXHMA_DOWN,CFXHMA_UNDEF};

class CCFXHullMA
{
private:
         int m_ind_period;
         int m_hull_period;
         double m_hull_arr[];
         double m_rates_arr[];
         string m_symbol;
         CFXHULLMA_STATE m_state;
         CFXHULLMA_MODE m_mode;
         ENUM_TIMEFRAMES m_ind_tf;

public:
                     CCFXHullMA();
                    ~CCFXHullMA();
                    bool Create(string symb,ENUM_TIMEFRAMES tf,int p,CFXHULLMA_MODE mode);
                    double Calculate(int index);
                   
};


      
      
CCFXHullMA::CCFXHullMA()
  {
   
  }
CCFXHullMA::~CCFXHullMA()
  {
  }
  
bool CCFXHullMA::Create(string symb,ENUM_TIMEFRAMES tf,int p,CFXHULLMA_MODE m)
{
   
   m_ind_period = p;
   m_mode = m;
   m_symbol = symb;
   m_ind_tf = tf;
   m_state = CFXHMA_UNDEF;
   m_hull_period = int(round(sqrt(m_ind_period)));
   if (ArrayResize(m_rates_arr,m_ind_period)==-1) return false;
   if (ArrayResize(m_hull_arr,m_hull_period)==-1) return false;
   ArraySetAsSeries(m_rates_arr,true); //!
   ArraySetAsSeries(m_hull_arr,true);  //!
   return true;
}

double CCFXHullMA::Calculate(int index)
{
   int c;
   double ret,wma1,wma2,wma3;
   
   c=0;
  // if (CopyClose(m_symbol,m_ind_tf,index,m_ind_period,m_rates_arr) == -1) Print("error copying rates");
  
   for (int j=0;j<m_hull_period;j++,c++) 
   { 
     wma1 = iMA(m_symbol,m_ind_tf,m_ind_period,0,3,PRICE_CLOSE,index+j);
     wma2 = iMA(m_symbol,m_ind_tf,int(round(m_ind_period/2)),0,3,PRICE_CLOSE,index+j);
     wma3 = wma2*2 - wma1;
     m_hull_arr[c] = wma3;
   }
   ret = iMAOnArray(m_hull_arr,0,m_hull_period,0,3,0);
   return ret;
}

//+------------------------------------------------------------------+

Any help greatly appreciated.