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 07-27-2009, 09:09 AM   #1
BurtOD
Junior Member
 
Join Date: Feb 2009
Location: Miami, FL
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default Bars Since condition

I used the indicator wizard and inserted the code below to calculate the bars since CCI>100 but I get error messages indicating I should have semi colons ";" where I have "-" minus signs to subtaract one value from another. The editor also flagged the leading left bracket after "If". Can you suggest how I can correct this and get the code to compile?
protectedoverridevoid OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
{
double BarsSince = 0;
double TriggerBar = 0;
}
If ((WoodiesCCI(14,6) > 100) = true & BarsSince =0);
{ TriggerBar = CurrentBar 1;
BarsSince = CurrentBar – TriggerBar;
}
Else If (WoodiesCCI(14,6) > 100 = true & BarsSince != 0);
{
BarsSince = CurrentBar – TriggerBar;
}
Else If (WoodiesCCI(14,6) > 100 != true);
{
BarsSince = 0;
TriggerBar = 0;
}
Plot0.Set(BarsSince [0]);
BurtOD is offline  
Reply With Quote
Old 07-27-2009, 09:35 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,573
Thanks: 262
Thanked 1,018 times in 999 posts
Default

BurtOD, please give this snippet a try -

Code:
 
int BarsSince = 0;
int TriggerBar = 0;

if (CCI(14)[0] > 100 && BarsSince == 0)
{ 
TriggerBar = CurrentBar - 1;
BarsSince = CurrentBar - TriggerBar;
}

else if (CCI(14)[0] > 100 && BarsSince != 0)
BarsSince = CurrentBar - TriggerBar;

else if (CCI(14)[0] > 100 != true)
{
BarsSince = 0;
TriggerBar = 0;
}
In addition I would suggest you review those tutorials for getting more into the basic NinjaScript syntax and notation -

http://www.ninjatrader-support.com/H...verview18.html

http://www.ninjatrader-support.com/H...sicSyntax.html
NinjaTrader_Bertrand is online now  
Reply With Quote
Old 08-25-2009, 02:19 PM   #3
BurtOD
Junior Member
 
Join Date: Feb 2009
Location: Miami, FL
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default Bars Since

The code compiles now and works fine but something is wrong with my design/logic. The term TriggerBar, which is supposed to stay constant after meeting the condition, continues to update so I get a constant value for BarsSince instead of an increasing value. How do I get the TriggerBar to stay constant once the condition is met until the condition changes?
if (CCI(14)[0] > 100 && BarsSince == 0)
BurtOD is offline  
Reply With Quote
Old 08-25-2009, 02:33 PM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,573
Thanks: 262
Thanked 1,018 times in 999 posts
Default

BurtOD, if your condition is still true, the 'trigger bar' would still update of course. Have you tried a CrossOver one instead of checking for the CCI being greater than 100?
NinjaTrader_Bertrand is online now  
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
Minimum bars required condition. ju1234 Strategy Development 11 06-01-2010 01:07 PM
Bars since a condition BurtOD Indicator Development 30 02-08-2010 10:39 AM
Enter on bars, exit on ticks and min bars requirment coolraz Strategy Development 3 12-15-2008 09:59 AM
Painting bars based on condition question ericadam General Programming 7 09-05-2008 09:07 AM
Bars are wrong on strategy performance (negative bars) woodside Historical NinjaTrader 6.5 Beta Threads 2 01-13-2008 10:22 PM


All times are GMT -6. The time now is 04:32 AM.