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 03-05-2006, 03:22 AM   #1
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post


How to write a code like this.

If CCI(14) > 0 then BarColor = Color.Blue;
if ema(34) > BarClose and CCI(14) > 100 then BarColor = Color.Green;
else
if CCI(14) < 0 then BarColor = Color.Fushcia;
if ema(34) < BarClose and CCI(14)< -100 then BarColor = Color.Red.


thanks for your help

I am guessing but it seems you are coming from TradeStation. There are some major coding style differences between EasyLanguage and NinjaTrader NinjaScript which is based on the C# language. Several things that I notice are:

1. Correctly referencing price data
2. Using braching statements
3. Price property names

In the Help Guide there is a NinjaScript primer which reviews basic coding structure. I suggest taking a quick review of that.

Below is what your code should look like in NinjaScript.

if (CCI(14)[0] > 0)
BarColor = Color.Blue;
else if (CCI(14)[0] > 100 &&EMA(34)[0] > Close[0])
BarColor = Color.Green;
else if (CCI(14)[0] < 0)
BarColor = Color.Fushcia;
else if (CCI(14)[0] < -100 && EMA(34)[0] < Close[0])
BarColor = Color.Red;


Alternatively you could also write it in the following way. It is more efficient but you would never notice:

double cciValue = CCI(14)[0];
double emaValue = EMA(34)[0];

if (cciValue > 0)
BarColor = Color.Blue;
else if (cciValue > 100 &&emaValue >Close[0])
BarColor = Color.Green;
else if (cciValue < 0)
BarColor = Color.Fushcia;
else if (cciValue < -100 && emaValue < Close[0])
BarColor = Color.Red;




NinjaTrader_Ray is offline  
Reply With Quote
Old 04-07-2006, 01:48 PM   #2
ViperSpeed Trader
Junior Member
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 times in 0 posts
Send a message via Skype™ to ViperSpeed Trader
Post imported post

From what I see....if the code is TradeStation....it doesn't look like the newer versions....after TS 2000i. Part of the code does look similar....but not all. I work with EasyLanguage....but have never worked with TS 2000i....so I don't know.

ViperSpeed Trader
ViperSpeed Trader 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


All times are GMT -6. The time now is 02:19 AM.