General Programming General NinjaScript programming questions.

 09-07-2007, 08:02 AM #1 Ronin Junior Member   Join Date: Sep 2007 Posts: 10 Thanks: 0 Thanked 0 times in 0 posts Simple Indicator Hello I am trying to create a simple indicator that plots the difference Bollinger Band Top and price(High). Could someone help with the codes. Thanks
 09-07-2007, 08:37 AM #2 NinjaTrader_Josh NinjaTrader Product Manager     Join Date: May 2007 Location: Denver, CO Posts: 17,458 Thanks: 1 Thanked 107 times in 70 posts Hi Ronin, To get started you can run the NinjaScript indicator wizard (Tools->New NinjaScript->Indicator). Make sure you have at least one plot when you go through the wizard pages. After you finish, press the "Generate" button to get the NinjaScript editor to open with your new indicator. If you look in the OnBarUpdate() section you will notice this line of code: Code: `Plot0.Set(Close[0]);` By default, the indicator will be plotting the close because that is what we set our plot to equal. In your case, you want Bollinger Band Top minus price high. This can be done with this code: Code: `Plot0.Set(Bollinger(2, 14).Upper[0] - High[0]);` Whatever you place in the parenthesis after .Set is what your Plot0 will take values from. What the code is doing is telling the plot to be set to the upper bollinger band's value (bollinger band has standard deviation of 2 and period of 14) minus the high price. Josh NinjaTrader Customer Service Use Kinetick, NinjaTrader’s preferred market data service - Learn More Free online training events - View Schedule
 09-07-2007, 10:50 AM #3 Ronin Junior Member   Join Date: Sep 2007 Posts: 10 Thanks: 0 Thanked 0 times in 0 posts Hi Josh Thanks. The code is working great. Regards
 09-10-2007, 11:26 PM #4 Ronin Junior Member   Join Date: Sep 2007 Posts: 10 Thanks: 0 Thanked 0 times in 0 posts In the case below I am trying to build an indicator to determine whether BB is sloping or not. The code is Plot0.Set(((Bollinger(2, 20).Upper[0] - Bollinger(2, 20).Upper[5])/Bollinger(2, 20).Upper[0]*100)); Formula is Bollinger Upper Band -Bollinger upper band 5 period ago/Bollinger upper band *100 But this code is not returning any value. Could someone please correct my code. Thanks Last edited by Ronin; 09-11-2007 at 12:51 AM.
 09-11-2007, 07:00 AM #5 NinjaTrader_Ray Administrator     Join Date: Nov 2004 Location: Denver, CO, USA Posts: 11,164 Thanks: 6 Thanked 46 times in 32 posts The problem can likely be resolved by reviewing this "Tip". http://www.ninjatrader-support.com/v...ead.php?t=3170 Ray NinjaTrader Customer Service Use Kinetick, NinjaTrader’s preferred market data service - Learn More Free online training events - View Schedule
 09-11-2007, 12:09 PM #6 Ronin Junior Member   Join Date: Sep 2007 Posts: 10 Thanks: 0 Thanked 0 times in 0 posts This partly sorted the problem. The code now plots the values. However there seems to be huge gaps in plotting the indicator. What I am actually trying to do is simply apply ROC indicator to Boll Band, SMA etc. I want to calculate rate of change of indicator value instead of price. Could you please guide me how to do this. Thanks much.
 09-11-2007, 12:17 PM #7 NinjaTrader_Ray Administrator     Join Date: Nov 2004 Location: Denver, CO, USA Posts: 11,164 Thanks: 6 Thanked 46 times in 32 posts Tutotorial Level II covers applying indicator on indicator calculations, exactly what you are looking for. Its located here - http://www.ninjatrader-support.com/H...Indicator.html Ray NinjaTrader Customer Service Use Kinetick, NinjaTrader’s preferred market data service - Learn More Free online training events - View Schedule
 09-11-2007, 01:09 PM #8 Ronin Junior Member   Join Date: Sep 2007 Posts: 10 Thanks: 0 Thanked 0 times in 0 posts Hello My code for calculating ROC on Bollinger band is returning a couple of errors. Could any programmer take a look and help me correct this or still better provide the correct code for this. Code: double robt = (ROC(Bollinger(2,20).Upper[0])); Plot0.Set(robt); Am not a programmer and therefore find this simple code a herculean task. Thanks
 09-11-2007, 01:28 PM #9 NinjaTrader_Dierk Administrator     Join Date: Mar 2005 Location: Bamberg, Germany Posts: 9,994 Thanks: 0 Thanked 6 times in 6 posts - it always helps if you paste the compiler error you experience - on your code below I would try: Plot0.Set(ROC(Bollinger(2,20).Upper, )[0]); Dierk NinjaTrader Customer Service Use Kinetick, NinjaTrader’s preferred market data service - Learn More Free online training events - View Schedule
 09-11-2007, 01:46 PM #10 Ronin Junior Member   Join Date: Sep 2007 Posts: 10 Thanks: 0 Thanked 0 times in 0 posts Hi Dierk Thanks. This did the magic.
09-16-2007, 06:42 PM   #11
KBJ
Senior Member

Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
ROC(Bollinger) Approximation

There is an approximation that could be done on this that is much simpler than what you've been attempting.

Since the Bollinger calculates the upper band value as the SMA plus a multiple of the StdDev, and the SMA will on the average be the same as the price, why not just go with calculating the rate of change of the StdDev, as follows:

Code:
```        protected override void Initialize()
{

Overlay               = false;
PriceTypeSupported    = true;
}

protected override void OnBarUpdate()
{
Values[0].Set( ROC( StdDev(Period), ROCPeriod )[0] );
}```
That should be a good approximation of the rate of change of the upper bollinger band.

Best regards,

KBJ
Attached Files
 BollingerROC.zip (4.9 KB, 15 views)

 09-18-2007, 08:30 AM #12 Ronin Junior Member   Join Date: Sep 2007 Posts: 10 Thanks: 0 Thanked 0 times in 0 posts Hi KBJ Thanks for the code. Best Regards Ronin

 Thread Tools Display Modes Linear Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home News and Announcements     News and Announcements Application Technical Support     ATM Strategies (Discretionary Trading)     Automated Trading     Charting     Connecting     Installation and Licensing     Market Analyzer     Miscellaneous Support         Historical Version 7 Beta Threads             Critical Information - Please review             Version 7 Beta General Questions & Bug Reports         Historical NinjaTrader 6.5 Archive             Historical NinjaTrader 6.5 Beta Threads     Strategy Analyzer     SuperDOM and other Order Entry Windows NinjaScript Development Support     General Programming     Indicator Development     Strategy Development NinjaScript Educational Resources     Reference Samples     Tips NinjaScript File Sharing     NinjaScript File Sharing Discussion     Version 7 Indicators     Version 7 Strategies     Version 7 Miscellaneous Suggestions and Feedback     Suggestions And Feedback

 Similar Threads Thread Thread Starter Forum Replies Last Post MGDavid Miscellaneous Support 2 06-21-2007 08:47 AM zoltran Strategy Development 2 04-02-2007 10:21 AM Oli Automated Trading 2 03-05-2007 11:42 PM Steveinvest Miscellaneous Support 1 12-30-2005 02:50 AM

All times are GMT -6. The time now is 09:12 PM.

 -- Fixed Width ---- Fluid Width NinjaTrader Support Forum - Archive - Top