HMA Type Conversion error for sqrt function

 
#property indicator_buffers 3


//---Indicator Colours
#property indicator_color1 clrGreen//up arrow
#property indicator_color2 clrRed//down arrow
#property indicator_color3 clrRed//HMA

//---Indicator Width
#property indicator_width1 2
#property indicator_width2 2

#include <WinUser32.mqh>
extern bool show=true;//Show Indicators?

int input n=2;

double UpArrow[];
double DownArrow[];
double HMA[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {

//--- indicator buffers mapping
   SetIndexBuffer(0,UpArrow);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,233);
   SetIndexLabel(0,"Buy Signal.");
//---
   SetIndexBuffer(1,DownArrow);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,234);
   SetIndexLabel(1,"Sell Signal.");
//---
   SetIndexBuffer(2,HMA);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexLabel(2,"HMA.");

   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[])
  {
//---for loop
   int counted_bars=IndicatorCounted();
   int limit= Bars-counted_bars;
   for(int i=1;i<limit;i++)
     {        
     double Hma1=((iMA(NULL,0,(n/2),0,MODE_LWMA,PRICE_MEDIAN,i)*2)-(iMA(NULL,0,n,0,MODE_LWMA,PRICE_MEDIAN,i)));
     int SQR=(sqrt(Hma1));  
     double Hma=iMA(NULL,0,SQR,0,MODE_LWMA,PRICE_MEDIAN,i);
     double HmaBack=iMA(NULL,0,SQR,0,MODE_LWMA,PRICE_MEDIAN,i+1);
     double Price=(High[i]+Low[i])/2;     
     
      if(show==true)
        {
         HMA[i]=Hma;
        }
      if(Hma>HmaBack)

        {
         UpArrow[i]=Open[i];
        }

      if(Hma<HmaBack)

        {
         DownArrow[i]=Open[i];
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
I get a type conversion error for SQR function, how should this be handled?
 

You should make it typecast.

//int SQR=(sqrt(Hma1));

int SQR=(int)(sqrt(Hma1));
 
Naguisa Unada:

You should make it typecast.

Thanks Naguisa that seems like a simple fix :)