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 > Application Technical Support > Automated Trading

Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader.

Reply
 
Thread Tools Display Modes
Old 08-23-2008, 06:10 AM   #1
MoreYummy
Senior Member
 
Join Date: Aug 2008
Posts: 325
Thanks: 0
Thanked 0 times in 0 posts
Default calculating differences between 2 SMA

Is there a way to calculate differences between 2 SMA using strategy, and if at certain distance, the condition is true.

I only see >= and <=, but nothing says larger(smaller) by a certain tick.

Any way to do this?
MoreYummy is offline  
Reply With Quote
Old 08-23-2008, 11:44 AM   #2
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

If it doesn't matter which SMA is above the other you can do something like...

if(Math.Abs(SMA1 - SMA2) >= someValue)
{
//insert logic here
}

if it does matter which is greater than the other just add
&& sma1 > sma2

or

&& sma1 < sma2

hope this helps
mrlogik is offline  
Reply With Quote
Old 08-23-2008, 12:12 PM   #3
MoreYummy
Senior Member
 
Join Date: Aug 2008
Posts: 325
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks. Yes in my case, which one is above which matters.

So I will have 2 "if"s for above, and below.
MoreYummy is offline  
Reply With Quote
Old 08-23-2008, 12:20 PM   #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

yes

if(Math.Abs(SMA1 - SMA2) >= someValue && SMA1 > SMA2)
{
//logic 1 here
}
else if(Math.Abs(SMA1 - SMA2) >= someValue && SMA1 < SMA2)
{
//logic 2 here
}
mrlogik is offline  
Reply With Quote
Old 08-23-2008, 12:46 PM   #5
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Also remember if you want "some" tick value to use TickSize.

Code:
10 * TickSize
NinjaTrader_Josh is offline  
Reply With Quote
Old 08-23-2008, 01:55 PM   #6
MoreYummy
Senior Member
 
Join Date: Aug 2008
Posts: 325
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks for advice, guys.
MoreYummy 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
Tick Chart Differences Kardinal Charting 6 08-14-2008 07:15 AM
Help with coding Moving average differences zphinx Strategy Development 1 05-14-2008 07:07 AM
Significant Differences between NT 6.0 and 6.5 Backtest Results kgillis23 General Programming 1 03-15-2008 12:09 PM
ESignal & IB Decimal Differences TraderGuy Connecting 3 12-17-2007 07:04 AM
Calculation differences ThePatientOne Strategy Development 1 05-24-2007 12:07 PM


All times are GMT -6. The time now is 07:18 PM.