Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Data Type Issues

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

    Data Type Issues

    Hello.

    I am a recent conversion from TradeStation to NinjaTrader and I am attempting to convert my indicators into Ninja 7. I have a few questions and an issue I cant get past

    Questions:
    ========
    1) How do you assign a value to plot? From what I understand, Ninja has something called a values collection.. but I don't understand how it is used. I have a function that I want to return a value that I want plotted. How do I tell my plot statement to use that value? I tried Values.Set(MyFunction) but I am not getting anything to plot with the Add(new Plot(color, line, "name")); function.

    2) How do you plot marker lines? I want horizontal lines at 100, 40, 0, -40, and -100 but I can seem to pass a straight value into the plot statement to get these lines to plot.


    3) I am having a weird datatype issue. It is my understanding that the double[] datatype can hold an array of numbers ... but on this statement...
    vOsc = 0; I get an error that I am trying to convert an INT to double. vOsc is declared in my variables section as private double[] vOsc;

    #2
    Here a script that should showcase what you are asking for in the first 2 questions. hope that helps you adjust your script in a correct way.

    Code:
    namespace NinjaTrader.Indicator
    {
    
        [Description("")]
        public class TestIndicator : Indicator
        {
    
    
            protected override void Initialize()
            {
                Add(new Plot(Color.Orange, "plot"));
                Add(new Line(Color.Green, 0, "Lower"));    
                Overlay                = false;
            }
    
    
            protected override void OnBarUpdate()
            {
    
                if (CurrentBar == 0)
                    Value.Set(0);
                else
                {
                    double myfunction = (Close[0]-Close[1])/Close[1];
                        Value.Set(myfunction);
                }
            }
    
            //#region Properties
            [XmlIgnore()]        
            [Browsable(false)]
            public DataSeries plot
            {
                get { return Values[0]; }
            }
            //#endregion
        }
    }
    regarding question 3.

    double is not an array, double is just a value. the difference between double and int is that double can be defined as any real number such as 0,1,1.23477,-2.34894
    while int can only be whole numbers such as -1,0,2,3

    the correct notation for a double variable is

    private double vOsc;

    if you change that, it should work.
    Last edited by BigRo; 05-24-2016, 06:01 AM.

    Comment


      #3
      To add some to BigRo's answer, C# does not do implicit casting as frequently as other programming languages do. I am including a publicly available link to the MSDN documentation for casting and type conversion, to remove any mystery as to when C# will require a cast.

      Learn about casting and type conversions, such as implicit, explicit (casts), and user-defined conversions.


      We can see in its explicit conversion section a situation where there is no implicit conversion between doubles and ints in the explicit conversion example.

      Please let us know if there are any other ways we can help.
      Jessica P.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      557 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      545 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X