Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Referencing data values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Referencing data values


    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;




    RayNinjaTrader Customer Service

    #2
    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

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by GussJ, 03-04-2020, 03:11 PM
    12 responses
    3,239 views
    0 likes
    Last Post Leafcutter  
    Started by AveryFlynn, Today, 04:57 AM
    0 responses
    5 views
    0 likes
    Last Post AveryFlynn  
    Started by RubenCazorla, 08-30-2022, 06:36 AM
    3 responses
    79 views
    0 likes
    Last Post PaulMohn  
    Started by f.saeidi, Yesterday, 12:14 PM
    9 responses
    25 views
    0 likes
    Last Post f.saeidi  
    Started by Tim-c, Today, 03:54 AM
    0 responses
    5 views
    0 likes
    Last Post Tim-c
    by Tim-c
     
    Working...
    X