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

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 Rapine Heihei, Today, 08:19 PM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by Rapine Heihei, Today, 08:25 PM
      0 responses
      3 views
      0 likes
      Last Post Rapine Heihei  
      Started by f.saeidi, Today, 08:01 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by Rapine Heihei, Today, 07:51 PM
      0 responses
      6 views
      0 likes
      Last Post Rapine Heihei  
      Started by frslvr, 04-11-2024, 07:26 AM
      5 responses
      96 views
      1 like
      Last Post caryc123  
      Working...
      X