View Full Version : Simple Indicator
09-07-2007, 08:02 AM
I am trying to create a simple indicator that plots the difference Bollinger Band Top and price(High). Could someone help with the codes.
09-07-2007, 08:37 AM
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:
Plot0.Set(Close);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:
Plot0.Set(Bollinger(2, 14).Upper - High);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.
09-07-2007, 10:50 AM
Thanks. The code is working great.
09-10-2007, 11:26 PM
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 - Bollinger(2, 20).Upper)/Bollinger(2, 20).Upper*100));
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.
09-11-2007, 07:00 AM
The problem can likely be resolved by reviewing this "Tip".
09-11-2007, 12:09 PM
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.
09-11-2007, 12:17 PM
Tutotorial Level II covers applying indicator on indicator calculations, exactly what you are looking for.
Its located here - http://www.ninjatrader-support.com/HelpGuideV6/SettingUpACustomIndicator.html
09-11-2007, 01:09 PM
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.
double robt = (ROC(Bollinger(2,20).Upper));
Am not a programmer and therefore find this simple code a herculean task.
09-11-2007, 01:28 PM
- 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, <whatever period your ROC has>));
09-11-2007, 01:46 PM
Thanks. This did the magic.
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:
protected override void Initialize()
Add(new Plot(Color.Orange, "BollingerRoc"));
Overlay = false;
PriceTypeSupported = true;
protected override void OnBarUpdate()
Values.Set( ROC( StdDev(Period), ROCPeriod ) );
That should be a good approximation of the rate of change of the upper bollinger band.
09-18-2007, 08:30 AM
Thanks for the code.