Change of color

 

Helou,

sorry for stupid question, but in my mother language is hard to stady mql5. I dont know how to change color of MA line, which i add to chart :

   double maFast[];
   ArraySetAsSeries(maFast,true);
   int maFastHandle = iMA(_Symbol,_Period,MAFastPeriod,MAFastShift,MAFastMethod,MAFastPrice);
   CopyBuffer(maFastHandle,0,0,10,maFast);

   ChartIndicatorAdd(0,0,maFastHandle);

and here  I need some function to change the preset color to different one, because i want two different MA.

Thanks a lot.

 
vanuatu:

Helou,

sorry for stupid question, but in my mother language is hard to stady mql5. I dont know how to change color of MA line, which i add to chart :

   double maFast[];
   ArraySetAsSeries(maFast,true);
   int maFastHandle = iMA(_Symbol,_Period,MAFastPeriod,MAFastShift,MAFastMethod,MAFastPrice);
   CopyBuffer(maFastHandle,0,0,10,maFast);

   ChartIndicatorAdd(0,0,maFastHandle);

and here  I need some function to change the preset color to different one, because i want two different MA.

Thanks a lot.

You can't change the color of iMA indicator by code. You can try to use a template.
 
angevoyageur:
You can't change the color of iMA indicator by code. You can try to use a template.

Hi, i will try templates.

thanks for quick response, and sorry for my english. I am working on my Diploma Thesis. I chose iMA function, because I have problems with the custom indicator. 

I put settings in #property indicator_separate_window and so on, than use onCalculate function, but i dont know how to change setting of more indicators?? I have tried IndicatorSetInteger(), but it doesnt distuinguished

more indicators.....

or how to put more indicators in property.....?

Any idea? thanks a lot

 
vanuatu:

Hi, i will try templates.

thanks for quick response, and sorry for my english. I am working on my Diploma Thesis. I chose iMA function, because I have problems with the custom indicator. 

I put settings in #property indicator_separate_window and so on, than use onCalculate function, but i dont know how to change setting of more indicators?? I have tried IndicatorSetInteger(), but it doesnt distuinguished

more indicators.....

or how to put more indicators in property.....?

Any idea? thanks a lot

What do you mean by "how to put more indicators in property" ? Do you mean buffers maybe ?
 
angevoyageur:
What do you mean by "how to put more indicators in property" ? Do you mean buffers maybe ?

i know that MA has one buffer, set in property 2 buffers,one for each indicator,

#property indicator_chart_window
#property indicator_buffers 2

what I want to know is the function to change the settings ( color, width-...) of both my MA indicators.

I dont know how to distinguished between them, they just have a handle for buffer not a name or number

in function IndicatorSerIntiger() there is NO identifier for the specific indicator i want to change setting..

maybe i am wrong, so that is why i am asking :)

better?

 
vanuatu:

i know that MA has one buffer, set in property 2 buffers,one for each indicator,

#property indicator_chart_window
#property indicator_buffers 2

what I want to know is the function to change the settings ( color, width-...) of both my MA indicators.

I dont know how to distinguished between them, they just have a handle for buffer not a name or number

in function IndicatorSerIntiger() there is NO identifier for the specific indicator i want to change setting..

maybe i am wrong, so that is why i am asking :)

better?

You can only change color, width, etc... from within the code of a custom indicator. So you can't change it for MA which is a standard MT5 indicator.

To set color, width,etc...you have to use PlotIndexSetInteger() function, you can also use #property indicator_color1 or #property indicator_width1, etc...

See documentation : https://www.mql5.com/en/docs/customind/propertiesandfunctions

Documentation on MQL5: Custom Indicators / Connection between Indicator Properties and Functions
Documentation on MQL5: Custom Indicators / Connection between Indicator Properties and Functions
  • www.mql5.com
Custom Indicators / Connection between Indicator Properties and Functions - Documentation on MQL5
 

Hi,

i tried your advice and here is result:

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot MAFast
#property indicator_label1  "MAFast"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- plot MASlow
#property indicator_label2  "MASlow"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrBlue
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2

//--- input parameters
input int                   MAFastPeriod= 14;
input int                   MAFastShift = 0;
input ENUM_MA_METHOD        MAFastMethod = MODE_EMA;
input ENUM_APPLIED_PRICE    MAFastPrice = PRICE_CLOSE;

input int                   MASlowPeriod = 30;
input int                   MASlowShift = 0;
input ENUM_MA_METHOD        MASlowMethod = MODE_EMA;
input ENUM_APPLIED_PRICE    MASlowPrice = PRICE_CLOSE;

//--- indicator buffers
double         MAFastBuffer[];
double         MASlowBuffer[];
int            MAFast_handle;
int            MASlow_handle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,MAFastBuffer,INDICATOR_DATA);
   ArrayGetAsSeries(MAFastBuffer);

   SetIndexBuffer(1,MASlowBuffer,INDICATOR_DATA);
   ArrayGetAsSeries(MASlowBuffer);

  
   //--- get MA handle
   MAFast_handle=iMA(_Symbol,_Period,MAFastPeriod,MAFastShift,MAFastMethod,MAFastPrice);
   MASlow_handle=iMA(_Symbol,_Period,MASlowPeriod,MASlowShift,MASlowMethod,MASlowPrice);
  
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
  
  }
  //+------------------------------------------------------------------+
//| 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[])
  {
//--- check if all data calculated
   if(BarsCalculated(MAFast_handle)<rates_total) return(0);
//--- we can copy not all data
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<=0) to_copy=rates_total;
   else
     {
      to_copy=rates_total-prev_calculated;
      //--- last value is always copied
      to_copy++;
     }
//--- try to copy
   if(CopyBuffer(MAFast_handle,0,0,to_copy,MAFastBuffer)<=0) return(0);
//--- return value of prev_calculated for next call
   return(rates_total);

  }

This works! i have changed the color of line but,

Now the OnCalculate is counting the MAFast only, how should I adjust it , that it will be calculate both MAFast and MASlow?

Should I write same code( I mean the body of OnCalculate)  for MASlow??

or what?

 

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


 
vanuatu:

Hi,

i tried your advice and here is result:


This works! i have changed the color of line but,

Now the OnCalculate is counting the MAFast only, how should I adjust it , that it will be calculate both MAFast and MASlow?

Should I write same code( I mean the body of OnCalculate)  for MASlow??

or what?

Only the CopyBuffer() part.
 

I just want to say Thank you!

Everithing is working and next time i will use the SRC Button for posting a code.

 
vanuatu:

I just want to say Thank you!

Everithing is working and next time i will use the SRC Button for posting a code.

You are welcome.