basic color coding according to direction of a moving average - NinjaTrader Programming | futures io social day trading
futures io futures trading


basic color coding according to direction of a moving average
Updated: Views / Replies:2,441 / 7
Created: by stephenszpak Attachments:4

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

basic color coding according to direction of a moving average

  #1 (permalink)
Elite Member
Massachusetts (USA)
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 358 received

basic color coding according to direction of a moving average

Hi

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)?



if (SMA(2)[0] > SMA(2)[1])

BarColor=Color.Yellow;

else if (SMA(2)[0]==SMA(2)[1])

BarColor=Color.Red;


else if (SMA (2)[0]<SMA(2)[1])
BarColor = Color.Blue;

Screenshots below show original graph and graph modified in Paint to show what I'm going for.
The cyan moving average is a 2 simple.

Attached Thumbnails
basic color coding according to direction of a moving average-original-graph.png   basic color coding according to direction of a moving average-modified-paint.png  
Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,653 since Mar 2010
Thanks: 4,226 given, 25,602 received
Forum Reputation: Legendary



stephenszpak View Post
Hi

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)?



if (SMA(2)[0] > SMA(2)[1])

BarColor=Color.Yellow;

else if (SMA(2)[0]==SMA(2)[1])

BarColor=Color.Red;


else if (SMA (2)[0]<SMA(2)[1])
BarColor = Color.Blue;

Screenshots below show original graph and graph modified in Paint to show what I'm going for.
The cyan moving average is a 2 simple.


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

 
Code
if (SMA(2)[0]==SMA(2)[1])
with

 
Code
if (Math.Abs(SMA(2)[0]-SMA(2)[1]) < 0.25*TickSize
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


 
Code
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;
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.


Last edited by Fat Tails; May 29th, 2011 at 09:30 PM.
Reply With Quote
 
  #4 (permalink)
Elite Member
Massachusetts (USA)
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 358 received

Thanks Fat Tails. I'll get back to you on this. The code was so simple I
thought sure it would work.

Reply With Quote
 
  #5 (permalink)
Elite Member
Massachusetts (USA)
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 358 received

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.

Some of my program is below:

protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
CalculateOnBarClose=true;
Overlay = true;
PriceTypeSupported=false;

}



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

Reply With Quote
 
  #6 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,653 since Mar 2010
Thanks: 4,226 given, 25,602 received
Forum Reputation: Legendary

Works here with all NinjaTrader default types.

I cannot try it though on these funny Momentum No-Gap bars, as I do not have them installed.

Attached Files
Register to download File Type: zip PaintBarSMA2.zip (1.7 KB, 102 views)
Reply With Quote
The following 4 users say Thank You to Fat Tails for this post:
 
  #7 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,354 given, 83,237 received

Add some Print() statements and check your output window to find the flawed logic.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #8 (permalink)
Elite Member
Massachusetts (USA)
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 358 received

Ok Fat Tails it works! Thanks for the program.

Attached Thumbnails
basic color coding according to direction of a moving average-program-works-.png  
Reply With Quote
The following user says Thank You to stephenszpak for this post:

Reply



futures io > > > > > basic color coding according to direction of a moving average

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Some Basic NinjaTrader Coding Questions -- IDataSeries Crow NinjaTrader Programming 7 October 15th, 2017 04:49 AM
Best Moving Average sharmas Elite Automated Trading 62 April 9th, 2012 07:44 PM
Moving average Help yiman NinjaTrader Programming 4 July 29th, 2011 09:03 AM
Moving Average of RSI Blz17 NinjaTrader Programming 6 February 12th, 2011 02:52 PM
New Moving Average arnaudlx The Elite Circle 10 January 28th, 2011 06:15 AM


All times are GMT -4. The time now is 03:57 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-17 in 0.12 seconds with 20 queries on phoenix via your IP 54.227.51.103