Download MetaTrader 5

Moving Average With Direction Color Change

To add comments, please log in or register
Register as a seller and start making profit!
Gilbert Reitsma
1609
Gilbert Reitsma 2012.12.01 08:53 

Hi

Is there a moving average indicator that changes color with direction similar to Hull?

Thanks

Gil

phi nuts
2184
phi nuts 2012.12.16 16:12  
GilR:

Hi

Is there a moving average indicator that changes color with direction similar to Hull?

Thanks

Gil

You can modify the code in here https://www.mql5.com/en/docs/customind/plotindexsetinteger
Documentation on MQL5: Custom Indicators / PlotIndexSetInteger
Documentation on MQL5: Custom Indicators / PlotIndexSetInteger
  • www.mql5.com
Custom Indicators / PlotIndexSetInteger - Documentation on MQL5
Widy Prasetyo
473
Widy Prasetyo 2013.02.09 10:35  
phi.nuts:
You can modify the code in here https://www.mql5.com/en/docs/customind/plotindexsetinteger

Thanks for information,,, but this 'plotindexsetinteger' indicator is actually "Color Line" which already included in MT5....... but this indicator not always changing it's bullish-bearish color.......

I need very-very-very simple 'Color Moving Average' for MT5,,,, especially EMA 5-10,,,,,, without dot symbol, without alert sound/pop-up, and without more extra text information....... but maybe add color setting for bullish-bearish.

So, it should be original Moving Average (same as MT5 built-in) but with bullish-bearish color.


If it only need few adjustment, which part i should modify? ........ I'm really blind about programming.

or if this kind MA indicator is already there, where can I download?

Thank You

--------------------------------------

I found the indicator that I need is "Var Mov Avg",,,,,,, it showing every up-down direction in color,,,,, but this indicator have too many information, such as popup alert, dot symbol, text,,,,,,,,,, and it's too disturbing for me.

Sorry can't upload the coding here, because it might somebody's copyright,,,,,, but it easily found in google.


Ahmed Soliman
15610
Ahmed Soliman 2013.02.10 04:58  
You need someting like xpMA? I'm working in its mq5 version.
khai hoan nguyen
242
khai hoan nguyen 2013.02.10 14:28  
this a good idea to see average moving change
phi nuts
2184
phi nuts 2013.02.11 05:03  
widhie75:

Thanks for information,,, but this 'plotindexsetinteger' indicator is actually "Color Line" which already included in MT5....... but this indicator not always changing it's bullish-bearish color.......

I need very-very-very simple 'Color Moving Average' for MT5,,,, especially EMA 5-10,,,,,, without dot symbol, without alert sound/pop-up, and without more extra text information....... but maybe add color setting for bullish-bearish.

So, it should be original Moving Average (same as MT5 built-in) but with bullish-bearish color.


If it only need few adjustment, which part i should modify? ........ I'm really blind about programming.

or if this kind MA indicator is already there, where can I download?

Thank You

--------------------------------------

I found the indicator that I need is "Var Mov Avg",,,,,,, it showing every up-down direction in color,,,,, but this indicator have too many information, such as popup alert, dot symbol, text,,,,,,,,,, and it's too disturbing for me.

Sorry can't upload the coding here, because it might somebody's copyright,,,,,, but it easily found in google.


Open MetaEditor (from Mt5 press F4), press Ctrl + N and select "Custom Indicator" to create new indicator. name your indicator, click next, select "OnCalculate (... prices)", click next and click finish.

Copy and paste the code from  https://www.mql5.com/en/docs/customind/plotindexsetinteger to your new indicator.

Do this :

Find some code, to delete or to add with another code 

#property indicator_width1  3                     //<<-- find this and add the code below it
//--- input parameters
input int                MA_Period=3;         
input int                MA_Shift=0;           
input ENUM_MA_METHOD     MA_Method=MODE_SMMA;
input ENUM_APPLIED_PRICE MA_Price=PRICE_CLOSE;  
//--- indicator buffers                           //<<-- find this to add the code above
double         ColorLineBuffer[];

Find these codes and delete them all, we don't need them

//+------------------------------------------------------------------+
//| get color index                                               |
//+------------------------------------------------------------------+

int getIndexOfColor(int i)
  {
   int j=i%300;
   if(j<100) return(0);// first index
   if(j<200) return(1);// second index
   return(2); // third index
  }

Find these codes and delete to replace with another code

//---
   static int ticks=0,modified=0;
   int limit;
//--- first calculation or number of bars was changed
   if(prev_calculated==0)
     {
      //--- copy values of MA into indicator buffer ColorLineBuffer
      int copied=CopyBuffer(MA_handle,0,0,rates_total,ColorLineBuffer);
      if(copied<=0) return(0);// copying failed - throw away
      //--- now set line color for every bar
      for(int i=0;i<rates_total;i++)
         ColorBuffer[i]=getIndexOfColor(i);
     }
   else
     {
      //--- copy values of MA into indicator buffer ColorLineBuffer
      int copied=CopyBuffer(MA_handle,0,0,rates_total,ColorLineBuffer);
      if(copied<=0) return(0);
 
      ticks++;// ticks counting
      if(ticks>=5)//it's time to change color scheme
        {
         ticks=0; // reset counter
         modified++; // counter of color changes
         if(modified>=3)modified=0;// reset counter 
         ResetLastError();
         switch(modified)
           {
            case 0:// first color scheme
               PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrRed);
               PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrBlue);
               PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrGreen);
               Print("Color scheme "+modified);
               break;
            case 1:// second color scheme
               PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrYellow);
               PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrPink);
               PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrLightSlateGray);
               Print("Color scheme "+modified);
               break;
            default:// third color scheme
               PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrLightGoldenrod);
               PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrOrchid);
               PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrLimeGreen);
               Print("Color scheme "+modified);
           }
        }
      else
        {
         //--- set start position
         limit=prev_calculated-1;
         //--- now we set line color for every bar
         for(int i=limit;i<rates_total;i++)
            ColorBuffer[i]=getIndexOfColor(i);
        }
     }

 ...and replace it with this code

   int limit;
   if (prev_calculated == 0)
       limit = prev_calculated + MA_Period + 1;
      else
       limit = prev_calculated - 1;
   
   //--- copy values of MA into indicator buffer ColorLineBuffer
   int copied=CopyBuffer(MA_handle,0,0,rates_total,ColorLineBuffer);
   if(copied<=0) return(0);// copying failed - throw away
   
   //Print ("rates total ",rates_total," prev_calc ",prev_calculated," limit ",limit," copied ", copied);
   
   for (int i = limit; i < rates_total; i++)
      {
      //--- now set line color for every bar
         if (ColorLineBuffer [i-1] == ColorLineBuffer [i])
            ColorBuffer[i] = 0;
            else
            if (ColorLineBuffer [i-1] < ColorLineBuffer [i])
               ColorBuffer[i] = 1;
               else
               ColorBuffer[i] = 2;
      
      }

Then press F7 to compile, if you're doing it right there will be no problem and you will have what you want.

You may also want to change this code for the color

#property indicator_type1   DRAW_COLOR_LINE        //<<-- find this
#property indicator_color1  clrRed,clrLime,clrBlue //<<-- this is the code for the color
#property indicator_style1  STYLE_SOLID            //<<-- find this
Documentation on MQL5: Custom Indicators / PlotIndexSetInteger
Documentation on MQL5: Custom Indicators / PlotIndexSetInteger
  • www.mql5.com
Custom Indicators / PlotIndexSetInteger - Documentation on MQL5
Widy Prasetyo
473
Widy Prasetyo 2013.02.11 05:37  

Thanks Phi.nuts and all guys here...........

I'll try it,,,,, and if i success to compile, i will upload it here.......

phi nuts
2184
phi nuts 2013.02.11 06:12  
widhie75:

Thanks Phi.nuts and all guys here...........

I'll try it,,,,, and if i success to compile, i will upload it here.......

Just don't forget to copyright it on your name. There's a case that other user stole the code and published it in code base as his code.

Better yet post it as your code in code base 

Widy Prasetyo
473
Widy Prasetyo 2013.02.12 03:33  

It works...... compiled without error.

Thanks phi.nuts

---------------------------------

but it seems something wrong with indicator setting. I try to change any MA Period, MA Method into "Simple, Exponential, Smoothed - Close Price, Open Price, etc"..... but the result still the same..... maybe still more work to improve this.

but currently, this version is 90% closed for what i need.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
phi nuts
2184
phi nuts 2013.02.12 04:24  
widhie75:

It works...... compiled without error.

Thanks phi.nuts

---------------------------------

but it seems something wrong with indicator setting. I try to change any MA Period, MA Method into "Simple, Exponential, Smoothed - Close Price, Open Price, etc"..... but the result still the same..... maybe still more work to improve this.

but currently, this version is 90% closed for what i need.

Ah yes, I didn't check that yesterday :(

Will be back later. 

phi nuts
2184
phi nuts 2013.02.12 04:34  
phi.nuts:

Ah yes, I didn't check that yesterday :(

Will be back later. 

Find this code

//--- indicator buffers mapping
   SetIndexBuffer(0,ColorLineBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ColorBuffer,INDICATOR_COLOR_INDEX);
//--- get MA handle
   MA_handle=iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE);
//---

Replace with this

//--- indicator buffers mapping
   SetIndexBuffer(0,ColorLineBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ColorBuffer,INDICATOR_COLOR_INDEX);
   PlotIndexSetInteger(0, PLOT_SHIFT, MA_Shift);
//--- get MA handle
   MA_handle=iMA(Symbol(),_Period,MA_Period, 0,MA_Method,MA_Price);

 And please reply back for the err.

Sorry about that. 

12
To add comments, please log in or register