Problem in assigning a custom color as #property

 

Hi, a good day to everybody.

Can someone help me? I want to let the user modify the color in the  Example indicator ZigZag, so I added this code to it:

enum Colors
  {
   color1=clrBlack, // Black
   color2=clrBrown, // Brown 
   color3=clrLimeGreen, // LimeGreen
   color4=clrMediumSeaGreen, // MediumSeaGreen
   color5=clrOrangeRed, //OrangeRed
   color6=clrRed, //Red
   color7=clrYellow, //Yellow
   color8=clrOrange, //Orange
   color9=clrAquamarine, //Aquamarine
   color10=clrDodgerBlue, //DodgerBlue
   color11=clrPink, //Pink
   color12=clrOrchid, //Orchid
   color13=clrLightGray, //LightGray
   color14=clrGray, //Gray
   color15=clrWhite, //White
   
   
   
  };



input Colors zigzag_colors = color6; // Zig Zag Color 
color zigzag_color = zigzag_colors;
 

but I have difficulties when I try to pass the variable as a property in the line

#property indicator_color1  zigzag_colors

that produce the error constant needed.

Is that possible? Thanks

Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Program Properties (#property) - Preprocessor - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
danerstizz:

Hi, a good day to everybody.

Can someone help me? I want to let the user modify the color in the  Example indicator ZigZag, so I added this code to it:

but I have difficulties when I try to pass the variable as a property in the line

#property indicator_color1  zigzag_colors

that produce the error constant needed.

Is that possible? Thanks

Try this 
Instead of “clrBlack” just write “Black”. Test and if it works, do it for all the colours
 
Chioma Obunadike #:
Try this 
Instead of “clrBlack” just write “Black”. Test and if it works, do it for all the colours
Hi, thanks for the help. I modified the line as said but the result is the same. The fact is that I can use the above method in a custom indicator without any problem but I don't know how to pass the custom color to a #property variable.
 

No need to declare an enumeration. Use the color data-type.

Here is an example of multiple color inputs ...

   input color
      clrBandingCenter        = clrYellow,   // Colour of Center Banding
      clrBandingDevaitions    = clrGray,     // Colour of Band Deviations
      clrBandingUpper         = clrAqua,     // Colour of Upper Banding
      clrBandingLower         = clrMagenta,  // Colour of Lower Banding
      clrBandingTrendUp       = clrAqua,     // Colour of Up Trend Symbol
      clrBandingTrendDown     = clrMagenta,  // Colour of Down Trend Symbol
      clrSignalBuy            = clrAqua,     // Colour of Buy Signal Symbol
      clrSignalSell           = clrMagenta;  // Colour of Sell Signal Symbol



Documentation on MQL5: Language Basics / Data Types / Integer Types / Color Type
Documentation on MQL5: Language Basics / Data Types / Integer Types / Color Type
  • www.mql5.com
Color Type - Integer Types - Data Types - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

Just an example ...



Many thanks Fernando, very interesting and I will use your example. But my problem is a complete different one. I need to pass the color name as a #property in the line

#property indicator_color1 custom_color
 that produces the error constant needed. Do you know the solution?
 
danerstizz #: Many thanks Fernando, very interesting and I will use your example. But my problem is a complete different one. I need to pass the color name as a #property in the line that produces the error constant needed. Do you know the solution?

Do you mean like this?

#define MClrCandleUp    C'38,166,154'
#define MClrCandleDown  C'239,83,80'
#define MClrCandleNone  C'239,166,117'

#property indicator_color1 MClrCandleDown
#property indicator_color2 MClrCandleUp
#property indicator_color3 MClrCandleDown
#property indicator_color4 MClrCandleUp
#property indicator_color5 MClrCandleUp
#property indicator_color6 MClrCandleNone

Please note, that the properties are set at compile time and that inputs are collected at run-time.

So you cannot assign an "input" to a "property". To set the colour of a plot, you need to use the PlotIndexSetInteger function ...

PlotIndexSetInteger( plot_index, PLOT_LINE_COLOR, clrDrawColour ); // Drawing Colour
Documentation on MQL5: Custom Indicators / PlotIndexSetInteger
Documentation on MQL5: Custom Indicators / PlotIndexSetInteger
  • www.mql5.com
PlotIndexSetInteger - Custom Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Your topic has been moved to the section: Technical Indicators — In the future, please consider which section is most appropriate for your query.
 
Fernando Carreiro #:

Do you mean like this?

Please note, that the properties are set at compile time and that inputs are collected at run-time.

So you cannot assign an "input" to a "property". To set the colour of a plot, you need to use the PlotIndexSetInteger function ...

As you said Fernando, I've added the line

  PlotIndexSetInteger( 0, PLOT_LINE_COLOR, zigzag_color );


and deleted the #property one. Now I can assign a custom color.

Many thanks and sorry for the wrong section.