NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript File Sharing > NinjaScript File Sharing Discussion

NinjaScript File Sharing Discussion Discussion for shared NinjaScript files.

Reply
 
Thread Tools Display Modes
Old 12-29-2008, 04:27 PM   #1
PrTester
Senior Member
 
Join Date: Mar 2007
Posts: 212
Thanks: 0
Thanked 3 times in 3 posts
Default VSA Indicator - Beta

I try to port an existing VSA Indicator from an Amibroker code. Anyone can check the AFL File to see if the port is good?, first time working with Ami codes. Also comments from VSA Fans are welcome to see if we can have a useful indicator

Here you can find the Original code: http://www.vpanalysis.blogspot.com/

PD
Thanks Roonius for the fix in the shading routine.

Regards
Attached Images
File Type: jpg VPA Indicator.jpg (80.3 KB, 2422 views)
Attached Files
File Type: zip VPAAnalysis.zip (22.8 KB, 1335 views)
Last edited by PrTester; 01-04-2009 at 03:35 PM. Reason: update File
PrTester is offline  
Reply With Quote
Old 01-01-2009, 09:41 AM   #2
scjohn
Senior Member
 
Join Date: Dec 2004
Location: , ,
Posts: 224
Thanks: 0
Thanked 11 times in 8 posts
Default

Here is my take on the same AmiBroker code.

Notes: I coded a Wilder MA indicator that is included in the attached file. I also used LinRegSlopSFX to find the slope. Also, I used a slightly different color scheme to paint the bars with.
Attached Files
File Type: zip VPA.zip (17.6 KB, 752 views)
scjohn is offline  
Reply With Quote
The following user says thank you to scjohn for this post:
Old 01-01-2009, 10:28 AM   #3
PrTester
Senior Member
 
Join Date: Mar 2007
Posts: 212
Thanks: 0
Thanked 3 times in 3 posts
Default

Quote:
Originally Posted by scjohn View Post
Here is my take on the same AmiBroker code.

Notes: I coded a Wilder MA indicator that is included in the attached file. I also used LinRegSlopSFX to find the slope. Also, I used a slightly different color scheme to paint the bars with.
scjohn, thanks for the share, i will check my interpretation with your code to see where its different, also my color scheme it's horrible I will check it and revise, he, he.

Best Regards, and Happy Holidays.
PrTester is offline  
Reply With Quote
Old 01-04-2009, 03:37 PM   #4
PrTester
Senior Member
 
Join Date: Mar 2007
Posts: 212
Thanks: 0
Thanked 3 times in 3 posts
Default

With the help of scjohn code I made some updates and fix to my port, uploaded in the first post.
PrTester is offline  
Reply With Quote
Old 01-05-2009, 04:33 AM   #5
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

Thanks PrTester and scjohn, great work!
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-05-2009, 10:38 AM   #6
Mindset
Senior Member
 
Join Date: Mar 2008
Location: UK West Sussex
Posts: 665
Thanks: 9
Thanked 9 times in 7 posts
Default div by zero error?

great code and thanks for sharing.

Code:
//			Price information
			upbar.Set(Close[0] > Close[1] ? true : false); 	
			dnbar.Set(Close[0] < Close[1] ? true : false); 
			Cloc=Close[0]-Low[0];
			x=spread[0]/Cloc;
			x1 =( Close[0] - Low[0] == 0.00 ? arg[0] : x );
could someone help explain why this doesn't return a div by zero error when the close[0] = low[0]? To my tiny knowledge Cloc therefore = 0?
Mindset is offline  
Reply With Quote
Old 01-05-2009, 10:42 AM   #7
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Potentially double.Epsilon issues: http://www.ninjatrader-support2.com/...ead.php?t=3929
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-05-2009, 11:06 AM   #8
Mindset
Senior Member
 
Join Date: Mar 2008
Location: UK West Sussex
Posts: 665
Thanks: 9
Thanked 9 times in 7 posts
Default that is an issue

Interesting. How does the close/low ever equal something that was not traded? I assume that NT just takes the transmitted data price ( in my case IB)?
eg close = 2157. It can't equal for example 2157.000000001 or can it?

Would the correct code therefore be
nb I have now removed the cloc variable altogether
Code:
if (Instrument.MasterInstrument.Compare (Close[0], Low[0]) == 0
{x = 0;}
else
{x = range[0] / (Close[0] - Low[0]);}
I should add no div by zero error or crash of any kind has happened with the original code but I am learning C# 101.
Dollars are in the detail.
Last edited by Mindset; 01-05-2009 at 11:21 AM.
Mindset is offline  
Reply With Quote
Old 01-05-2009, 11:23 AM   #9
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

When you do any subtraction, multiplication, etc with double values they can end up not equaling zero exactly. Long story short, you have to be mindful of the double.Epsilon. This is a more technical C# topic. For more information try combing through google.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-05-2009, 11:34 AM   #10
Mindset
Senior Member
 
Join Date: Mar 2008
Location: UK West Sussex
Posts: 665
Thanks: 9
Thanked 9 times in 7 posts
Default data and doubles and epsilon

Ok but just to confirm if Low[0] = 1234 then it always equals 1234 unless you start to manipulate it. NT doesn't do any "data processing" of it's own?

In which case, Close[0] = low[0] could return zero - and I am right back to the original query - how is the div by zero error avoided?

I am not being difficult but I need to understand.
Mindset is offline  
Reply With Quote
Old 01-05-2009, 11:42 AM   #11
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

NT does not change the data it receives. Your check for 0 is already manipulating it. Close[0] - Low[0] is stored into your temp variable. That temp variable is no guaranteed to be 0.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-06-2009, 09:09 AM   #12
Mindset
Senior Member
 
Join Date: Mar 2008
Location: UK West Sussex
Posts: 665
Thanks: 9
Thanked 9 times in 7 posts
Default learn something

Well I spent some time last night testing out this data concept and it appears you are right - 3.56 - 3.55 does not equal .01 difference.
It often has rogue digits 4,5 or even 10 decimal places away!

One thing however - where close and low were equal my print statement always returned zero. But now I don't know whether that really is a true zero or has some weird digit 17 decimal places away that I can't see ( I understand that double values go approx 15- 16 decimal places?)
Last edited by Mindset; 01-06-2009 at 09:09 AM. Reason: sp
Mindset is offline  
Reply With Quote
Old 01-06-2009, 09:16 AM   #13
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Mindset,

This is C# and the concept revolves around double.Epsilon. It may be best for you to research this matter on MSDN. Unfortunately I cannot provide any more assistance on this.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-06-2009, 09:26 AM   #14
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Hello Mindset,

when I have to use price bar numbers heavily for calculations then I convert them into the tick representation before usage. That also avoids these special double-issues.

Regards
Ralph
Ralph is offline  
Reply With Quote
Old 01-06-2009, 10:26 AM   #15
Mindset
Senior Member
 
Join Date: Mar 2008
Location: UK West Sussex
Posts: 665
Thanks: 9
Thanked 9 times in 7 posts
Default tick representation

Do you mean TickSize?
Perhaps you could show an example?
Mindset is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VSA indicator request dokebilee Indicator Development 8 01-11-2010 10:37 AM
VSA - Volume Spread Analysis markm NinjaScript File Sharing Discussion 4 12-30-2008 06:12 PM
VSA Trade Alerts kronie Indicator Development 3 11-17-2008 12:11 PM
6.5 Beta 6 - the same downloaded file as Beta 5 cmrodrig Historical NinjaTrader 6.5 Beta Threads 4 01-17-2008 02:05 AM
Beta 6.5 pgabriel Historical NinjaTrader 6.5 Beta Threads 17 11-26-2007 02:52 PM


All times are GMT -6. The time now is 01:26 AM.