Something interesting, old thread - page 116

 
mladen:

I does not matter (the language used)

But please read my post regarding that and decompiled code

Thank you to my brother, and I'm not a programmer I do not know programming codes

 Sometimes I do a simple adjustment to the settings in the indicators

Thank you for providing a wonderful indicators at this location  

 

Mr. Mladen please make this index to mq5

 
Dragon:

Mr. Mladen please make this index to mq5

Did you try to use some of the existing hull averages for metatrader 5?
 
mladen:
Did you try to use some of the existing hull averages for metatrader 5?
Index works well on a platform mq4 is my request to you to be converted into the same settings mq5
 
mladen:
Did you try to use some of the existing hull averages for metatrader 5?
//+------------------------------------------------------------------+
//|                                                HMA color nrp.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link "mladenfx@gmail.com"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1  Green
#property indicator_color2  Orange
#property indicator_width1  2
#property indicator_width2  2
#property indicator_minimum 0
#property indicator_maximum 1

//
//
//
//
//

extern string TimeFrame        = "Current time frame";
extern int    HMA_Period       = 20;
extern int    HMA_PriceType    = 0;
extern int    HMA_Method       = 3;
extern bool   alertsOn         = false;
extern bool   alertsOnCurrent  = false;
extern bool   alertsMessage    = true;
extern bool   alertsSound      = true;
extern bool   alertsEmail      = false;

extern bool   ShowArrows       = false;
extern string arrowsIdentifier = "HMA Arrows";
extern double arrowsUpperGap   = 1.0;
extern double arrowsLowerGap   = 1.0;
extern color  arrowsUpColor    = LimeGreen;
extern color  arrowsDnColor    = Red;
extern color  arrowsUpCode     = 241;
extern color  arrowsDnCode     = 242;
extern int    arrowsUpSize     = 2;
extern int    arrowsDnSize     = 2;


int HalfPeriod;
int HullPeriod;

//
//
//
//
//

double ind_buffer0[];
double ind_buffer1[];
double ind_buffer2[];
double buffer[];
double trend[];
string indicatorFileName;
bool   returnBars;
int    timeFrame;


//+------------------------------------------------------------------
//|                                                                 |
//+------------------------------------------------------------------

int init()
{
   HMA_Period = MathMax(2,HMA_Period);
   HalfPeriod = MathFloor(HMA_Period/2);
   HullPeriod = MathFloor(MathSqrt(HMA_Period));
   
   //
   //
   //
   //
   //
   
   IndicatorBuffers(5);
   SetIndexBuffer(0,ind_buffer1); SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(1,ind_buffer2); SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(2,ind_buffer0);
   SetIndexBuffer(3,buffer);
   SetIndexBuffer(4,trend);

      timeFrame         = stringToTimeFrame(TimeFrame);
      indicatorFileName = WindowExpertName();
      returnBars        = TimeFrame == "returnBars";     if (returnBars)     return(0);

   int draw_begin=HMA_Period+MathFloor(MathSqrt(HMA_Period));
   for (int i = 0; i < indicator_buffers; i++)
   {
         SetIndexDrawBegin(i,draw_begin);
         SetIndexLabel(i,"Hull Moving Average");
   }         
   IndicatorShortName("HMA("+HMA_Period+")");
   return(0);
}

int deinit()
{
   deleteArrows();
    
return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int start()
{
   int counted_bars = IndicatorCounted();
   int limit,i;
   

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
           limit = MathMin(Bars-counted_bars,Bars-1);
           if (returnBars) { ind_buffer1[0] = limit+1; return(0); }
           if (timeFrame != Period())
           {
               limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));
               for(i=limit; i>=0; i--)
               {
                  int y = iBarShift(NULL,timeFrame,Time[i]);               
                     ind_buffer1[i] = iCustom(NULL,timeFrame,indicatorFileName,"",HMA_Period,HMA_PriceType,HMA_Method,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,ShowArrows,arrowsIdentifier,arrowsUpperGap,arrowsLowerGap,arrowsUpColor,arrowsDnColor,arrowsUpCode,arrowsDnCode,arrowsUpSize,arrowsDnSize,0,y);
                     ind_buffer2[i] = iCustom(NULL,timeFrame,indicatorFileName,"",HMA_Period,HMA_PriceType,HMA_Method,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,ShowArrows,arrowsIdentifier,arrowsUpperGap,arrowsLowerGap,arrowsUpColor,arrowsDnColor,arrowsUpCode,arrowsDnCode,arrowsUpSize,arrowsDnSize,1,y);
               }
               return(0);
            }

   //
   //
   //
   //
   //
   
   for(i=limit; i>=0; i--)
         buffer[i]=iMA(NULL,0,HalfPeriod,0,HMA_Method,HMA_PriceType,i)*2-
                   iMA(NULL,0,HMA_Period,0,HMA_Method,HMA_PriceType,i);
   for(i=limit; i>=0; i--)
   {
      ind_buffer0[i] = iMAOnArray(buffer,0,HullPeriod,0,HMA_Method,i);
      ind_buffer1[i] = EMPTY_VALUE;
      ind_buffer2[i] = EMPTY_VALUE;
      
      //
      //
      //
      //
      //

      trend[i] = trend[i+1];            
         if (ind_buffer0[i] > ind_buffer0[i+1]) trend[i] =  1; 
         if (ind_buffer0[i] < ind_buffer0[i+1]) trend[i] = -1; 
         if (trend[i] ==  1) ind_buffer1[i] = 1;
         if (trend[i] == -1) ind_buffer2[i] = 1;
         manageArrow(i); 
   }
   manageAlerts();
   return(0);
}



//-------------------------------------------------------------------
//                                                                  
//-------------------------------------------------------------------
//
//
//
//
//

void manageAlerts()
{
   if (alertsOn)
   {
      if (alertsOnCurrent)
           int whichBar = 0;
      else     whichBar = 1; 
      if (trend[whichBar] != trend[whichBar+1])
      {
         if (trend[whichBar] ==  1) doAlert(whichBar,"up");
         if (trend[whichBar] == -1) doAlert(whichBar,"down");
      }
   }
}

//
//
//
//
//

void doAlert(int forBar, string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
   if (previousAlert != doWhat || previousTime != Time[forBar]) {
       previousAlert  = doWhat;
       previousTime   = Time[forBar];

       //
       //
       //
       //
       //

       message =  timeFrameToString(Period())+" "+Symbol()+" at "+TimeToStr(TimeLocal(),TIME_SECONDS)+" hull trend changed to "+doWhat;
          if (alertsMessage) Alert(message);
          if (alertsEmail)   SendMail(Symbol()+" hull trend",message);
          if (alertsSound)   PlaySound("alert2.wav");
   }
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

void manageArrow(int i)
{
   if (ShowArrows)
   {
      deleteArrow(Time[i]);
      if (trend[i]!=trend[i+1])
      {
         if (trend[i] == 1) drawArrow(i,arrowsUpColor,arrowsUpCode,arrowsUpSize,false);
         if (trend[i] ==-1) drawArrow(i,arrowsDnColor,arrowsDnCode,arrowsDnSize, true);
      }
   }
}               

//
//
//
//
//

//
//
//
//
//

void drawArrow(int i,color theColor,int theCode,int theWidth, bool up)
{
   string name = arrowsIdentifier+":"+Time[i];
   double gap  = iATR(NULL,0,20,i);   
   
      //
      //
      //
      //
      //
      
      ObjectCreate(name,OBJ_ARROW,0,Time[i],0);
         ObjectSet(name,OBJPROP_ARROWCODE,theCode);
         ObjectSet(name,OBJPROP_COLOR,theColor);
         ObjectSet(name,OBJPROP_WIDTH,theWidth);
         if (up)
               ObjectSet(name,OBJPROP_PRICE1,High[i] + arrowsUpperGap * gap);
         else  ObjectSet(name,OBJPROP_PRICE1,Low[i]  - arrowsLowerGap * gap);
}

//
//
//
//
//

void deleteArrows()
{
   string lookFor       = arrowsIdentifier+":";
   int    lookForLength = StringLen(lookFor);
   for (int i=ObjectsTotal()-1; i>=0; i--)
   {
      string objectName = ObjectName(i);
         if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName);
   }
}

//
//
//
//
//

void deleteArrow(datetime time)
{
   string lookFor = arrowsIdentifier+":"+time; ObjectDelete(lookFor);
}

//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

//
//
//
//
//

int stringToTimeFrame(string tfs)
{
   StringToUpper(tfs);
   for (int i=ArraySize(iTfTable)-1; i>=0; i--)
         if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period()));
                                                      return(Period());
}
string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}
 
Converting MT4 indicator to MT5
 
Dragon:
...
Please, did you check any of the existing Hull moving averages for metatrader 5, not the metatrader 4 version code that you posted here? There are quite a few versions for metatrader 5 that already exist
 

Yes sir I use this indicator in MetaTrader 5 it moves with candles and I want to be at the bottom in the form of who is in hma_histo_amp_alerts__arrows_mtf_nmc Index

Files:
 
Dragon:

Yes sir I use this indicator in MetaTrader 5 it moves with candles and I want to be at the bottom in the form of who is in hma_histo_amp_alerts__arrows_mtf_nmc Index

There is an averages histo version too. Use that version
 

I beg you to make this HISTO index by noon at the bottom

This indicator matches the averages that moves with candles 

This is the only code make it appear at the bottom as in the picture

please please 

 //------------------------------------------------------------------

#property copyright "mladen"
#property link      "mladen"
//------------------------------------------------------------------
#property indicator_buffers 2
#property indicator_plots   1
#property indicator_label1  "hull"
#property indicator_type1   DRAW_COLOR_LINE
#property indicator_color1  clrLimeGreen,clrOrange
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2

//
//
//
//
//

enum enPrices
{
   pr_close,      // Close
   pr_open,       // Open
   pr_high,       // High
   pr_low,        // Low
   pr_median,     // Median
   pr_typical,    // Typical
   pr_weighted,   // Weighted
   pr_average     // Average (high+low+oprn+close)/4
};

input double   HmaLength =   14;     // Hull period
input double   HmaPower  =    1;     // Hull power
input enPrices Price     = pr_close; // Price

double hull[];
double colorInd[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int OnInit()
{
   SetIndexBuffer(0,hull    ,INDICATOR_DATA); 
   SetIndexBuffer(1,colorInd,INDICATOR_COLOR_INDEX); 
   return(0);
}

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

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 HalfPeriod = (int)MathFloor(HmaLength/2);
   int HullPeriod = (int)MathFloor(MathSqrt(HmaLength));
   for (int i=(int)MathMax(prev_calculated-1,1); i<rates_total; i++)
   {
      double price       = getPrice(Price,open,close,high,low,rates_total,i);
             hull[i]     = iLwmp(2.0*iLwmp(price,HalfPeriod,HmaPower,rates_total,i,0)-iLwmp(price,HmaLength,HmaPower,rates_total,i,1),HullPeriod,HmaPower,rates_total,i,2);
             colorInd[i] = colorInd[i-1];
               if (hull[i]>hull[i-1]) colorInd[i] = 0;
               if (hull[i]<hull[i-1]) colorInd[i] = 1;
   }
   return(rates_total);
}


//------------------------------------------------------------------
//                                                                  
//------------------------------------------------------------------
//
//
//
//
//

double getPrice(enPrices price, const double& open[], const double& close[], const double& high[], const double& low[], int bars, int i)
{
   switch (price)
   {
      case pr_close:     return(close[i]);
      case pr_open:      return(open[i]);
      case pr_high:      return(high[i]);
      case pr_low:       return(low[i]);
      case pr_median:    return((high[i]+low[i])/2.0);
      case pr_typical:   return((high[i]+low[i]+close[i])/3.0);
      case pr_weighted:  return((high[i]+low[i]+close[i]+close[i])/4.0);
      case pr_average:   return((high[i]+low[i]+close[i]+open[i])/4.0);
   }
   return(0);
}

//------------------------------------------------------------------
//                                                                 
//------------------------------------------------------------------
//
//
//
//
//

double workLwmp[][3];
double iLwmp(double price, double period, double power, int bars, int r, int instanceNo=0)
{
   if (ArrayRange(workLwmp,0)!= bars) ArrayResize(workLwmp,bars);
   
   //
   //
   //
   //
   //
   
   workLwmp[r][instanceNo] = price;
      double sumw = MathPow(period,power);
      double sum  = sumw*price;
      for(int k=1; k<period && (r-k)>=0; k++)
      {
         double weight = period-k;
                sumw  += MathPow(weight,power);
                sum   += MathPow(weight,power)*workLwmp[r-k][instanceNo];  
      }             
   return(sum/sumw);
}
Files:
hma_histo.JPG  108 kb
Reason: