most simple multi-color indicator

 

Hi,

Is it possible to give me a very, very simple example of an indicator that gives a green color when it's rising and red when it's going down: let's say on this buffer: ma[i]=iMA(0,0,10,0,2,0,i); I realize it will need at least 3 buffers: 1 for the value, 1 for the rising (that paints green) and 1 for the declining values (in red). but a simple if (ma[i]>ma[i+1]) {up[i]=ma[i];} else {dn[i]=ma[i];} doesn't seem to work...

thanks;

Files:
colors.mq4  2 kb
 
MrH:

Hi,

Is it possible to give me a very, very simple example of an indicator that gives a green color when it's rising and red when it's going down: let's say on this buffer: ma[i]=iMA(0,0,10,0,2,0,i); I realize it will need at least 3 buffers: 1 for the value, 1 for the rising (that paints green) and 1 for the declining values (in red). but a simple if (ma[i]>ma[i+1]) {up[i]=ma[i];} else {dn[i]=ma[i];} doesn't seem to work...

thanks;




close?
Files:
colorsw1u.mq4  2 kb
 
serpentsnoir:

close?

thanks, but this one has 3 colors (including yellow), and it shows empty gaps between pieces of red and green, so how would you code it with only 2 colors (red & green) and without the gaps between the pieces?
 
MrH:

thanks, but this one has 3 colors (including yellow), and it shows empty gaps between pieces of red and green, so how would you code it with only 2 colors (red & green) and without the gaps between the pieces?

sorry, I only changed your code enough to show you the way... it was not intended to be the solution... from your intial post, I thought you were just stuck getting to the next step...
 
serpentsnoir:

sorry, I only changed your code enough to show you the way... it was not intended to be the solution... from your intial post, I thought you were just stuck getting to the next step...

I tried adding
if(ma[i]==ma[i+1])
   {
   up[i]=up[i+1];
   dn[i]=dn[i+1];
   }
but that still leaves the gaps.
And adding IndicatorDigits(Digits); for more precision is not a solution either.
Can you show me the entire solution please?
I'll be able to use it for all my code.
 

yup, no problem. see attached. this had me puzzled for a long time - you will see that we needed two calls to the ma to get this right...

I added a block to make the line gold when the last two ma values are equal - don't think it worked. take it out if you want.

sn

Files:
colorsv2.mq4  3 kb
 
serpentsnoir:

yup, no problem. see attached. this had me puzzled for a long time - you will see that we needed two calls to the ma to get this right...

I added a block to make the line gold when the last two ma values are equal - don't think it worked. take it out if you want.

sn


Yes that's it, thanks for helping me with this.