Download MetaTrader 5
To add comments, please log in or register
Trade with MetaTarder 5. Download it right now!
Xennon
84
Xennon 2012.04.19 00:00 
I found a nice little *indicator* that allows the user to place horizontal lines on the chart as user-defined intervals (ie a grid type setup). However, the line color and style is hard coded and I want to change that so the use can choose the color, width and style of the lines from the inputs popup. I have managed to place ...
#property indicator_color1 DarkSeaGreen

... at the top of the code and this results in an option in the Colors tab of the inputs window ~BUT~ my problem is: How do I query the user's settings as chosen via the inputs > colors tab and employ them in drawing the lines?

Currently the line drawing code is

ObjectCreate("Grid"+I, OBJ_HLINE, 0, Time[1], I);
ObjectSet("Grid"+I, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("Grid"+I, OBJPROP_COLOR, GridColor);  // I changed the hardcoded color to a variable "GridColor" 
                                                // but want to use the user chosen one from input window

I want to change the "STYLE_SOLID" to whatever the user set it to in the inputs > Colors tab and same for the color.

Can someone enlighten me as to the code needed to
(1) query the user's choices and
(2) Set the function ObjectSet() to use those options.

Or tell me where I can find an explanation on how to do this.

Many thanks.

(ps: i'm only starting to learn mql4 so my apologies if this is a silly question)
onewithzachy
2274
onewithzachy 2012.04.19 00:15  

Attach the CI please, coz ...

#property indicator_color1 DarkSeaGreen

Got nothing to do with ...

ObjectCreate()

... If fact they are technically different. :)

However i'm in the good mood

put the extern input way above start() and init()

extern color GridColor=Red;
extern int   GridStyle=STYLE_SOLID;
extern int   GridWidth=3;
extern bool  GridBackground=False;


ObjectCreate("Grid"+I, OBJ_HLINE, 0, Time[1], I);
ObjectSet   ("Grid"+I, OBJPROP_STYLE, GridStyle);
ObjectSet   ("Grid"+I, OBJPROP_COLOR, GridColor);
ObjectSet   ("Grid"+I, OBJPROP_WIDTH, GridWidth);
ObjectSet   ("Grid"+I, OBJPROP_BACK,  GridBackground);
Xennon
84
Xennon 2012.04.22 00:45  
onewithzachy:

Attach the CI please, coz ... << What is "CI" ??

Got nothing to do with ...

... If fact they are technically different. :)

However i'm in the good mood

put the extern input way above start() and init()

Clearly you didn't read my post properly. I want to know how to determine what the user selected via the "COLORS" tab of the inputs popup window. For example - on the popup window you can choose the color/line type/ line width ... how can the programmer know what the user selected??



onewithzachy
2274
onewithzachy 2012.04.22 01:57  
xennon:

Clearly you didn't read my post properly. I want to know how to determine what the user selected via the "COLORS" tab of the inputs popup window. For example - on the popup window you can choose the color/line type/ line width ... how can the programmer know what the user selected??

CI stands for Custom Indicator, EA stands for Expert Advisors, Script stand for ... well ... scripts :), My apology I forget to explain that :).

Color tabs are for indicator buffer not for object drawing. Does your indicator have something like this below ?.

SetIndexStyle  ( ... );

Tab color are for that functions not for object function. SetIndexStyle() function has 5 parameters in which the last 3 parameters has default value. So sometime SetIndexStyle() is written with only it's first 2 parameters. The property is useful as input for the other 3 parameters.

There's no way to find out what user select via tab color. The only way to find out what user has chose is by creating external input.

There's indicator called Heikin Aishi (HA) in your MetaEditor, it has property and external input. Why don't you play with it. HA has these in it's code blocks :

#property indicator_color1 Red          // <<=== all these are ...
#property indicator_color2 White        // <<=== ... color properties ...
#property indicator_color3 Red          // <<=== ... which will be shown ...
#property indicator_color4 White        // <<=== ... on property window color tab :)
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3

//----
extern color color1 = Red;              // <<=== all these are ...
extern color color2 = White;            // <<=== ... external input ...
extern color color3 = Red;              // <<=== ... which will be shown ...
extern color color4 = White;            // <<=== ... on property windows input tab :)
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, color1);    // <<=== Here are SetIndexStyle() function ...
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, color2);    // <<=== ... with all it's 5 parameters written ...
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3, color3);    // <<=== ... but accept color from extern input ...
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3, color4);    // <<=== ... not from property window color tab :).
   SetIndexBuffer(3, ExtMapBuffer4);

  ....

Attach HA to a chart - make sure you use line chart instead of bar or candlestick chart - and you can change the color of HA from both input and color tab. Now, remove HA from the chart and do this, comment out the HA color properties like this below then compile (F5 or F7),

//#property indicator_color1 Red
//#property indicator_color2 White
//#property indicator_color3 Red
//#property indicator_color4 White

Attach HA to a chart, and you will notice that HA tab color will be black !. You may have to re-attach HA several times - but do not change it's color tab or it's input tab - you will see later that HA will be displayed correctly despite having black color in it's color tab. This happen because the external input from the input tab draws the color of HA.

To find out what color, a user has chose, use the external input.

The Object function has nothing to do with indicator property window. Except if we define external input for object function, object function has external input in input tab.

aminlv
91
aminlv 2016.06.30 09:14  
onewithzachy:

Attach the CI please, coz ...

Got nothing to do with ...

... If fact they are technically different. :)

However i'm in the good mood

put the extern input way above start() and init()

good one thanks lad
/
To add comments, please log in or register