Download MetaTrader 5

most simple multi-color indicator

To add comments, please log in or register
MisterH
1132
MisterH  

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
noonehastherighttojudgeanother
235
noonehastherighttojudgeanother  
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:
MisterH
1132
MisterH  
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?
noonehastherighttojudgeanother
235
noonehastherighttojudgeanother  
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...
MisterH
1132
MisterH  
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.
noonehastherighttojudgeanother
235
noonehastherighttojudgeanother  

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
MisterH
1132
MisterH  
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.
To add comments, please log in or register