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 Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 08-13-2009, 09:34 AM   #1
T2020
Senior Member
 
Join Date: Jun 2008
Posts: 644
Thanks: 0
Thanked 0 times in 0 posts
Default Macd with fast MA offset ?

Just wondering if something like this will work . So far these 2 lines don't
work . thx

fastEma.Set(LinReg(Input, Fast)[2]);

slowEma.Set(SMA(Input, Slow)[0]);
T2020 is offline  
Reply With Quote
Old 08-13-2009, 09:38 AM   #2
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

Hi there, are there any errors in the logs (right-most tab of Control Center)? Those two lines should work.
NinjaTrader_Austin is offline  
Reply With Quote
Old 08-13-2009, 09:57 AM   #3
T2020
Senior Member
 
Join Date: Jun 2008
Posts: 644
Thanks: 0
Thanked 0 times in 0 posts
Default

Error :

8/13/2009 8:17:17 AM Default Error on calling the 'OnBarUpdate' method for indicator 'MyMacdLregSMA2' on bar 0: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Not quite sure what that means ... Was trying on range chart .
T2020 is offline  
Reply With Quote
Old 08-13-2009, 10:05 AM   #4
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

On the first bar (bar 0), when you set this: fastEma.Set(LinReg(Input, Fast)[2]), the error you posted will occur because there is not enough data in the LinReg DataSeries. This tip applies here as well.

A solution would be to place this at the very beginning of OnBarUpdate():
Code:
protected override void OnBarUpdate()
{
// this NEEDS to be first
if (CurrentBar < 3)
    return;
}
The above code will not process any code inside OnBarUpdate() if there are less than 3 bars on the chart, thus making sure you have enough data.
NinjaTrader_Austin is offline  
Reply With Quote
Old 08-13-2009, 10:22 AM   #5
T2020
Senior Member
 
Join Date: Jun 2008
Posts: 644
Thanks: 0
Thanked 0 times in 0 posts
Default

Still problems . Maybe this will help ?
Attached Images
File Type: jpg Macd Error Pic.jpg (79.9 KB, 8 views)
T2020 is offline  
Reply With Quote
Old 08-13-2009, 10:25 AM   #6
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

These are now different problems. The highlighted portions of the attached picture are not necessary.
Attached Images
File Type: jpg unnecessary.JPG (21.4 KB, 12 views)
NinjaTrader_Austin is offline  
Reply With Quote
Old 08-13-2009, 10:34 AM   #7
T2020
Senior Member
 
Join Date: Jun 2008
Posts: 644
Thanks: 0
Thanked 0 times in 0 posts
Default

Seems to be getting more complicated . ?
Attached Images
File Type: jpg Macd Error Pic 2.jpg (82.0 KB, 8 views)
T2020 is offline  
Reply With Quote
Old 08-13-2009, 10:39 AM   #8
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

T2020, every bracket needs to have a "buddy" bracket. By that, I mean every { needs a }. In your attached picture, OnBarUpdate() has an opening bracket and two closing brackets. Thus, there is an imbalance and you will get compile errors.

If you remove the bracket below the Diff.Set line, you should be fine.
NinjaTrader_Austin is offline  
Reply With Quote
Old 08-13-2009, 10:43 AM   #9
T2020
Senior Member
 
Join Date: Jun 2008
Posts: 644
Thanks: 0
Thanked 0 times in 0 posts
Default

I just noticed that .
Thanks again .
T2020 is offline  
Reply With Quote
Old 08-21-2009, 10:47 AM   #10
T2020
Senior Member
 
Join Date: Jun 2008
Posts: 644
Thanks: 0
Thanked 0 times in 0 posts
Default

Here's the same indicator with an offset added to the slow line . It doesn't
plot ,so maybe this isn't going to work ???
Attached Images
File Type: jpg Macd Error Pic 3.jpg (27.3 KB, 14 views)
T2020 is offline  
Reply With Quote
Old 08-21-2009, 11:01 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

Those brackets you are highlighting should not be there.
NinjaTrader_Josh is offline  
Reply With Quote
Old 08-21-2009, 11:25 AM   #12
T2020
Senior Member
 
Join Date: Jun 2008
Posts: 644
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
Those brackets you are highlighting should not be there.
Still doesn't plot ???
T2020 is offline  
Reply With Quote
Old 08-21-2009, 12:18 PM   #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

You need to remove the brackets and then check your Control Center logs for errors.
NinjaTrader_Josh is offline  
Reply With Quote
Old 08-21-2009, 12:25 PM   #14
T2020
Senior Member
 
Join Date: Jun 2008
Posts: 644
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
You need to remove the brackets and then check your Control Center logs for errors.
8/21/2009 10:22:40 AM Default Error on calling the 'OnBarUpdate' method for indicator 'AZBLRMacd' on bar 3: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

what exactly does this mean ?
T2020 is offline  
Reply With Quote
Old 08-21-2009, 12:34 PM   #15
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

Please change if (CurrentBar < 3) to be less than 4.

http://www.ninjatrader-support2.com/...ead.php?t=3170
NinjaTrader_Josh 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
Stop mkt & stop limit w/offset in fast markets VinnyB SuperDOM and other Order Entry Windows 2 06-05-2009 02:12 PM
Removal the MA lines from MACD Armonistas Indicator Development 3 05-16-2009 01:03 PM
Quick MA an alternative to Juirk MA Ninja B Indicator Development 5 01-09-2009 07:14 AM
MACD with up down arrows on MACD signal line crosses moonriver Indicator Development 1 12-03-2008 10:34 AM
Hull MA of Macd Historigram Learning1 Indicator Development 11 07-07-2007 01:25 PM


All times are GMT -6. The time now is 10:20 PM.