![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Feb 2009
Location: Miami, FL
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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]); |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,573
Thanks: 262
Thanked 1,018 times in 999 posts
|
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;
}
http://www.ninjatrader-support.com/H...verview18.html http://www.ninjatrader-support.com/H...sicSyntax.html
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Feb 2009
Location: Miami, FL
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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) |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,573
Thanks: 262
Thanked 1,018 times in 999 posts
|
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?
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |