Need help Converting brief math and logic into Ninjascript syntax, VolumeUpDown - NinjaTrader Programming | futures io social day trading
futures io futures trading

Need help Converting brief math and logic into Ninjascript syntax, VolumeUpDown
Updated: Views / Replies:1,951 / 3
Created: by Spec01 Attachments:5

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 100,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

Thread Tools Search this Thread

Need help Converting brief math and logic into Ninjascript syntax, VolumeUpDown

  #1 (permalink)
Modesto, CA
Posts: 8 since Mar 2011
Thanks: 29 given, 27 received

Need help Converting brief math and logic into Ninjascript syntax, VolumeUpDown

First of all I have to thank BigMike for creating the slickest forum I've come across and for fostering such a positive comminity for traders, which is really a rare thing.

I'm struggling to create an indicator that I've made previously in much simpler platforms than Ninjatrader. I know the logic and the math is simple enough, but how to get it into the right syntax seems dauting, looking at the code for the simple indicators in Ninja mine is based on or similar to: VOLMA, ATR, VolumeUpDown. I'm slowly figuring things out through the NT tutorials, but this should be easy for someone with more experience.

The Logic and math:

Move & VolSurge are variables

// I've gathered so far that (0) refers to the current bar and (1) refers to the previous

Move = greatest of the following: close(0) - low(0) , high(0) - close(0) , close(0) - close(1)

//all the above would be net price changes

VolSurge = Vol(0) / SMA(input period) of Vol

plot(0) = Move / VolSurge
Ideally it would look almost identical to the VolumeUpDown indicator that comes with NT, except ofourse with the appropriate calculated values. Looking at the code for that indicator though, it isn't intuitive to me how it relates the change from the previous close to the color of the bar for that condition.

public class VolumeUpDown : Indicator
		protected override void Initialize()
			Add(new Plot(new Pen(Color.Lime, 2), PlotStyle.Bar, "UpVolume"));
			Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Bar, "DownVolume"));
			Add(new Line(Color.DarkGray, 0, "Zero line"));

		protected override void OnBarUpdate()
			if (Close[0] >= Open[0])
			{                                                             //I understand that this area is for what happens when  
                                                                                      //there is a positive change, but how does this get related to
				Values[0].Set(Volume[0]);           //the plot color above?

If someone experienced in coding would be willing to lend a hand, it would easily save me a few days figuring out C#, so I could get back to actually working on my trading. Thanks.

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)
Market Wizard
Berlin, Europe
Trading Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
Fat Tails's Avatar
Posts: 9,800 since Mar 2010
Thanks: 4,237 given, 26,422 received

The VolumeUpDown indicator uses two DataSeries objects. The first data series is used to hold the positive volume bars, in case that the volume is downvolume it is set to zero via Reset(). The second data series is used for the negative volume bars in the same way.

This is NinjaTrader 6.5. coding. With NinjaTrader 7 you would code an indicator with a single data series and then just paint it according to any condition. But let it be, as it works the way it has been coded.

Your definition of the move is not similar to the average true range. I have tried to code the indicator, but it gives strange results, maybe the definitions are not correct.

Attached Files
Register to download File Type: zip (3.8 KB, 24 views)
Reply With Quote
The following 2 users say Thank You to Fat Tails for this post:
  #4 (permalink)
Modesto, CA
Posts: 8 since Mar 2011
Thanks: 29 given, 27 received

Thank you, Fat Tails

Wow, thank you Fat Tails, I really wasn't expecting anyone to actually code it for me, your generousity has easily saved me many hours. I understand that ATR is calculated differently than my definition of 'Move' above, I ment that they are similar in that they are both simple math operations applied to the HLC of the current and previous bar. I hoped that I could decipher the math and logical syntax of the stock ATR indicator and apply it to what I wanted to accomplish, but I didn't find the code very intuitive.

Thank you also for the explanation of the VolUpDown coloring, I don't think I could replicate it but I don't foresee myself delving any deeper in to NT coding, since my trading is based on price action patterns and volume largely.

I'd agree that the results are strange, but it is similar to what I was looking for. This is actually a variation of the original one I used on daily charts. The original used price change(%) divided by the volume surge(SMA period 50).

To change it to my original and make it look a bit less wierd:

Here's what you coded(which is exactly what I asked for by the way, no fault on your part):
//line 53:
move = Math.Max(Close[0]-Low[0],Math.Max(High[0]-Close[0],Math.Abs(Close[0]-Close[1])));
Here's how I changed it to make it like my original, which was easy to do since you provided the syntax and did all the work:
//line 53:
move = Math.Abs(Close[0]-Close[1]);
I've overlayed the 2 in the same panel with the new version in pink/neon green and the original in Dark green/red. A problem with the new version is that it makes bars with small ranges and very small volume relative to the SMA look enormous, due to the math of dividing by a small fraction. Going forward I will likely only use my original version which is really just a tweak of what you made.

Since you took the time to code it for me I'll explain how I use it. I've just recently switched my focus to intraday trading and I am surprised at how well my strategies work on lower time frames. Now I'm using the 1min like my daily and the 5min like my weekly. It isn't an indicator in the traditional sense that provides me with signals, I use it in addition to price and volume analysis. I generally try to trade breakouts from ranges. In my experience what price will do is make a clean 'curl' like action within a range before breaking free from it, and forming a new trend. Often times the bar that completes the curl will have a large range and relatively low volume. The indicator helps to highlight these bars in addition to their size and placement in price action.

In my experience it is a fallacy that significant moves in price are always accompanied by volume when they start. This is at least the case with stocks on a position trading timeframe. The trends that I traded in stocks start by having relatively large bars with lower volume. That is not to say there are not false positives, I only use this to give me more confidence in the price patterns I trade. I've attached a few charts where I think this indicator(which I prefer to call LR, short for Least Resistance) is useful in anticipating a positive expectancy area to enter in price action in the transition from ranging to trending.

A couple hours after I wrote the above:
After some subjective backtesting, it doesn't appear as useful for trading futures intraday as it was for position trading stocks. Looks like I'll just stick to price action patterns and Vol. But thanks anyways Fat Tails, it would have been bugging me for a while if I couldn't actually test it.

Attached Thumbnails
Need help Converting brief math and logic into Ninjascript syntax, VolumeUpDown-nq-06-11-1-min-4_20_2011.jpg   Need help Converting brief math and logic into Ninjascript syntax, VolumeUpDown-nq-06-11-1-min-5_2_2011.jpg   Need help Converting brief math and logic into Ninjascript syntax, VolumeUpDown-nq-06-11-1-min-5_4_2011.jpg  
Attached Files
Register to download File Type: zip (3.7 KB, 31 views)
Reply With Quote
The following user says Thank You to Spec01 for this post:


futures io > > > > > Need help Converting brief math and logic into Ninjascript syntax, VolumeUpDown

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

futures io is celebrating 10-years w/ over $18,000 in prizes!

Right now

$250 Amazon Gift Cards with our "Thanks Contest" challenge!

Right now

Using Order Flow Analysis & Longer Term Trading w/John @ No BS Trading

Elite only

Similar Threads
Thread Thread Starter Forum Replies Last Post
NT Falling() Syntax aligator NinjaTrader 6 March 10th, 2011 09:11 PM
Embarrassed at the simplicity, but I don't get it - C# basic syntax Crassius NinjaTrader Programming 5 February 22nd, 2011 05:49 PM
What's wrong with my SUM logic? gordo NinjaTrader Programming 1 July 18th, 2010 09:04 PM
Logic Error in Strategy HJay NinjaTrader Programming 14 November 1st, 2009 07:05 PM
Organize logic flow terry NinjaTrader Programming 1 July 12th, 2009 01:16 PM

All times are GMT -4. The time now is 01:58 AM. (this page content is cached, log in for real-time version)

Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432,
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