NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 11-08-2009, 01:30 AM   #1
rkhanen
Junior Member
 
Join Date: Sep 2007
Posts: 17
Thanks: 0
Thanked 1 time in 1 post
Exclamation New to NJ Script question

Hi,

I´m trying to make a simple % deviation from af moving average calculation. In plain language something like this:

((price.close-SMA(period))/SMA(period))*100

But although I have read the instructions in the help file I can´t seem to get it right in NJ Script - and I have no programming experience.

Can anyone provide me with the correct code for this indicator? And maybe a small explanation in plain english of how it is constructed?

King Regards

René
rkhanen is offline  
Reply With Quote
Old 11-08-2009, 08:21 AM   #2
VTtrader
Senior Member
 
Join Date: Feb 2008
Location: www.integratedtradingtech.com
Posts: 270
Thanks: 1
Thanked 79 times in 64 posts
Default

Rene,
Try it like this.
((Close[0] - SMA(period)[0]) / SMA(period)[0]) * 100

VT

Edit: Didn't see the english explanation part.
Close[0] = Current bar's close.
SMA(period) = the moving average but as a series, you need the [0] afterwards to reference the current bar's value of the SMA.

Hope that helps.
Last edited by VTtrader; 11-08-2009 at 08:43 AM.
VTtrader is offline  
Reply With Quote
Old 11-08-2009, 11:51 AM   #3
rkhanen
Junior Member
 
Join Date: Sep 2007
Posts: 17
Thanks: 0
Thanked 1 time in 1 post
Default

Thanks a lot for helping me! I have tried out your answer and got an error. I have probably messed something up
rkhanen is offline  
Reply With Quote
Old 11-08-2009, 11:58 AM   #4
mrlogik
Certified NinjaScript Consultant
 
mrlogik's Avatar
 
Join Date: Sep 2006
Location: New York, USA
Posts: 774
Thanks: 1
Thanked 7 times in 5 posts
Default

You're missing the semi-colon

Code:
((Close[0] - SMA(period)[0]) / SMA(period)[0]) * 100;
"You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later"

PureLogikTrading
mrlogik is offline  
Reply With Quote
Old 11-09-2009, 12:17 AM   #5
rkhanen
Junior Member
 
Join Date: Sep 2007
Posts: 17
Thanks: 0
Thanked 1 time in 1 post
Default

Thanks for looking into it and helping out I am still getting an error code, but i think I can get ahead from here by putting more effort into it - thx again guys!
rkhanen 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
Took the NT auto script on-line class and have question? rehtrade Automated Trading 1 05-18-2009 02:20 AM
Newby Script question rehtrade Automated Trading 1 03-26-2009 10:15 AM
Question about Time and Ninja Script rehtrade Automated Trading 1 03-26-2009 10:14 AM
First Ninja Script Question Sidhartha Indicator Development 4 04-03-2008 07:35 AM
code script question abikambic General Programming 8 06-19-2007 07:23 AM


All times are GMT -6. The time now is 02:03 PM.