Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
basic color coding according to direction of a moving average
I'm just looking to color code momentum bars (created by eman).
The code I wrote below either doesn't work as written or there is
something more I need to do in the indicator script.
As you can see all that is needed is to compare the current value of a
simple moving average of value 2, to what it was in the previous bar. Is it more (yellow),
or the same (red), or less(blue)?
Maybe the problem is caused by checking two double values for equality. As both values are calculated, there may be rounding errors, which cause the oscillations.
Try to replace
with
If the difference is smaller than 0.25*TickSize, the two values must be identical.
If you think about it, there is an even easier solution. Comparing SMA(2)[0] and SMA(2)[1] is the same as
comparing Close[0] with Close[2], as both SMA(2)[0] and SMA(2)[1] are calculated by using Close[1], so you simply can throw it away and your code would look like this
In this case the comparison Close[0]== Close[2] should work, as the values are not calculated but just collected from the datafeed. Not sure but you can try.
You forgot a parenthesis in the first line, but it still doesn't work. I never
program so I don't remember/know about the generic code that NT has
built in. Not even sure if it is important or not.
if (Close[0] > Close[2])
BarColor=Color.Yellow;
else if (Close[0]==Close[2])
BarColor=Color.Red;
else if (Close[0]<Close[2])
BarColor = Color.Blue;
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot0
{
get { return Values[0]; }
}
[Description("")]
[GridCategory("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
#endregion