Custom Indicator - color change?

[Deleted]  

Dear Friends,

may I ask you for help with a custom indicator?

1. I would need the value of the indicator displayed on the right axis - what should I do?

2. Is there a way how to change the color of the indicator line depending on the value? Eg. the line would be green and ONLY the parts where the line would exceed 100 it would turn red. Is it possible? I mean that the line would be two-color depending on the value, I do not want to change the whole line color...

Thank you very much! Solator

Tjipke de Vries
6919
Tjipke de Vries  
solator:

Dear Friends,

may I ask you for help with a custom indicator?

1. I would need the value of the indicator displayed on the right axis - what should I do?

2. Is there a way how to change the color of the indicator line depending on the value? Eg. the line would be green and ONLY the parts where the line would exceed 100 it would turn red. Is it possible? I mean that the line would be two-color depending on the value, I do not want to change the whole line color...

Thank you very much! Solator


show us more give a picture

or give the code how the line is created

have you seen how many indicators there are in code_base and that's not all So we don't know if we don't get more info....

onewithzachy
1863
onewithzachy  
solator:


2. Is there a way how to change the color of the indicator line depending on the value? Eg. the line would be green and ONLY the parts where the line would exceed 100 it would turn red. Is it possible? I mean that the line would be two-color depending on the value, I do not want to change the whole line color...

You have to use 2 buffers. If its below 100 the red one should EMPTY_VALUE, if it over 100 the green one should be EMPTY_VALUE.
Tjipke de Vries
6919
Tjipke de Vries  
If you don't have the source then you have to create another indicator that is reading the buffer from your first indicator and split that buffer in this new indicator that gets its value with using iCustom( )
[Deleted]  
deVries:
If you don't have the source then you have to create another indicator that is reading the buffer from your first indicator and split that buffer in this new indicator that gets its value with using iCustom( )


Hello, thanks to all of you very much. Would you please have some expample of a code that does what you suggest? My indicator is very simple and uses just one buffer.

#property indicator_separate_window

#property indicator_buffers 1

double Buffer[];

......

SetIndexBuffer(0, Buffer);

SetIndexStyle (0, DRAW_LINE, DRAW_LINE, indicator_line_width);

i = ....;

while ( i >= 0)

{

Buffer[i] = (Close[i] - .....

// here I would like to test the value and if the value is greater than 100 the rozdilBuffer[i] would turn different color

.....

i--;

}

Thanks and have a nice day!!

Solator

onewithzachy
1863
onewithzachy  

Yo ! https://www.mql5.com/en/forum/139547

//+------------------------------------------------------------------+
//|                                                  MA 2 colors.mq4 |
//|                    Copyright © *** onewithzachy ***  14 May 2012 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © *** onewithzachy ***  14 May 2012"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Magenta
#property indicator_color2 Red
#property indicator_color3 Gold
#property indicator_color4 Aqua
//--- input parameters
extern int       Fast_Period=5;
extern int       Slow_Period=20;
//--- buffers
double Fast_Above[], Fast_Below[], Slow_Below[], Slow_Above[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexBuffer(0, Fast_Below);
   SetIndexBuffer(1, Fast_Above);
   SetIndexBuffer(2, Slow_Above);
   SetIndexBuffer(3, Slow_Below);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 3);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 3);
   SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 3);
   SetIndexStyle(3, DRAW_LINE, STYLE_SOLID, 3);
   SetIndexLabel(0, "Fast Below");
   SetIndexLabel(1, "Fast Above");
   SetIndexLabel(2, "Slow Below");
   SetIndexLabel(3, "Slow Above");
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int pos, counted_bars=IndicatorCounted();
   double fast, slow;
//----
   for (pos = 0; pos <= Bars - counted_bars - 1; pos ++)
     {
      fast = iMA (Symbol(),Period(), Fast_Period, 0 ,MODE_SMA, PRICE_CLOSE, pos);
      slow = iMA (Symbol(),Period(), Slow_Period, 0 ,MODE_SMA, PRICE_CLOSE, pos); 
      if (fast >= slow)
        {
        Fast_Above[pos] = fast;
        Fast_Below[pos] = fast; // EMPTY_VALUE // ==>> thanks to dabbler for questioning these 2 EMPTY_VALUEs ...
        Slow_Below[pos] = slow;                // ==>> ... if you use this 2 EMPTY_VALUE, ...
        Slow_Above[pos] = slow; // EMPTY_VALUE // ==>> ... the 2 lines will not visibly crossed. Try it for fun
        }
        else
        {
        Fast_Above[pos] = EMPTY_VALUE;
        Fast_Below[pos] = fast;
        Slow_Below[pos] = EMPTY_VALUE;
        Slow_Above[pos] = slow;
        }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+


[Deleted]  

onewithzachy:

Amazing, thank you VERY much for your kindness! All the best! Solator

P.S.: Would you also know how to make the indicator to display the value on the right vertical axis - see the picture above. Thanks again!!


Simon Gniadkowski
17179
solator:

P.S.: Would you also know how to make the indicator to display the value on the right vertical axis - see the picture above. Thanks again!!

Draw a HorizontalLine at that price . . . Object Functions
[Deleted]  
RaptorUK:
Draw a HorizontalLine at that price . . . Object Functions


Thank you all, the colors already work and the price... I will do that later. I would need a conscise manual of the mql programming, the web version is sometimes too brief for me... Does it exist?

Have a good day! Solator

Simon Gniadkowski
17179
solator:


Thank you all, the colors already work and the price... I will do that later. I would need a conscise manual of the mql programming, the web version is sometimes too brief for me... Does it exist?

Have a good day! Solator

Concise means brief . . . you could try the Book for additional information . . .
[Deleted]  

Concise... funny, thank you, I thought it meant "detailed". Thanks for the tip and I will use the book! My first indicator works fine and now I would like to make a first EA of it.

All the best! Solator