# 2 decimals instead of 4 and percentage

## Recommended Posts

Hi guys,

Can you help me with the following...
I want to take the 13ema and the 34ema and strip the last 2 digits of the 4 digit decimal value.  I want to be able to search for 2 averages that sit ontop of each other. Its hard to get a match with 4 decimals:)

On another scan I would like to see a % difference between 13ema and 89ema.
I would also like to have an option to set an alert on the % diff.

I spent sometime last night reading every post on paintbar looking for examples. I'm not much of a programmer but can tinker with examples to make things work. Thanks for the help.

##### Share on other sites

I know there is a Round method.  Maybe that will help until Mike is around.

##### Share on other sites

Thanks LW.
Im not sure how to make it work. I'm going to spend some time over there to try and learn some basics. I used to play in metastock- they had a primer manual along with a huge collection of user contributed code. There was enough stuff available for me to hack stuff together.  Last time I played with stuff was a decade ago.  BTW thanks for your dragonfly code  I came across that last night.

I came across this  SetScanResult(Sum(3, Close - Open).ToString("#,###.00##")); from one of the posts here, not sure if I can use the #,###.00 to strip away what I don't want.  I think it was "prec" in metastock that did what Im looking to do.

##### Share on other sites

One more if not too much trouble.
Would it be possible to make a rule that can actually plot the percentage away from the close? Say 50sma. Something I can look at on historic charts and see when things are way over done. thanks

##### Share on other sites

If you're comparing two floating point values for equality, you definitely shouldn't just == them. You can do Math.Abs(A-B)<0.01  if you want to limit it that way. Easier than rounding them up and would take care of the case where one rounds up and the other rounds down.

So if the 50SMA is called SMA50 - you can just do these two lines:

SetColor("% diff",Color.Lime);

SetYValue(100*(SMA50-Close)/Close);

You'd need to place this paintbar on the extra chart - either above or below the main one. And probably set the shape for the paintbar to size 1 so that the shapes do not obscure the line.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.