NexusFi: Find Your Edge


Home Menu

 





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


Discussion in NinjaTrader

Updated
    1. trending_up 2,814 views
    2. thumb_up 3 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 5 attachments




 
Search this Thread

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

  #1 (permalink)
Spec01
Modesto, CA
 
Posts: 8 since Mar 2011
Thanks Given: 29
Thanks Received: 29

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.

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

 
Code
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?
				Values[1].Reset();
			}
			else
			{
				Values[1].Set(Volume[0]);
				Values[0].Reset();


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

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
What broker to use for trading palladium futures
Commodities
Cheap historycal L1 data for stocks
Stocks and ETFs
ZombieSqueeze
Platforms and Indicators
 
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103


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
Elite Membership required to download: VolumeMove.zip
Reply With Quote
Thanked by:
  #4 (permalink)
Spec01
Modesto, CA
 
Posts: 8 since Mar 2011
Thanks Given: 29
Thanks Received: 29

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):
 
Code
//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:
 
Code
//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
Click image for larger version

Name:	NQ 06-11 (1 Min)  4_20_2011.jpg
Views:	234
Size:	141.1 KB
ID:	38281   Click image for larger version

Name:	NQ 06-11 (1 Min)  5_2_2011.jpg
Views:	220
Size:	161.3 KB
ID:	38282   Click image for larger version

Name:	NQ 06-11 (1 Min)  5_4_2011.jpg
Views:	194
Size:	167.1 KB
ID:	38283  
Attached Files
Elite Membership required to download: LowResistance.zip
Reply With Quote
Thanked by:




Last Updated on May 9, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts