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

More Questions from a Ninja Beginner

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

    More Questions from a Ninja Beginner

    Hello:

    1. I don't seem to be able to execute an edited version of a script. If I edit/ save a script and then run it, the prior, unedited version is run instead.

    2. I'm trying to add an indicator to a script -- SMA plotted in the price pane in this example and am pasting a piece of code with the following compilation error:
    "An object reference is required for the non-static field, method, or property
    'NinjaTrader.Strategy.Strategy.SMA (NinjaTrader.Data.IDataSeries, int)' ".

    Thank you !

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class Hello : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    /** ************************************************** ************************* */
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    }
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    public double value = SMA(High, 20)[0];
    protected override void OnBarUpdate( )
    {
    Print("The current SMA value is " + value.ToString());

    }
    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    Hello tradenj,

    1. After you have changed/edited your Strategy you will want to make sure you Compile the Strategy inside of NinjaTrader to make sure that NinjaTrader will use the changed version.

    2. When you are accessing Price data make sure it is inside of a method that is going to be called from the incoming data like placing it inside of OnBarUpdate(). Example:

    Code:
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    public double value;
    // User defined variables (add any user defined variables below)
    #endregion
    
    protected override void OnBarUpdate( )
    {
    	value = SMA(High, 20)[0];
    Print("The current SMA value is " + value.ToString());
    
    }
    You may want to view the following thread that has some good information and links for beginners with Strategies.
    JCNinjaTrader Customer Service

    Comment


      #3
      ...of course!

      ...of course! Many thanks for your guidance. Sometimes when attempting to absorb a new system things can seem more overwhelming than they really are.
      Last edited by tradenj; 02-20-2013, 05:41 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by benmarkal, Yesterday, 12:52 PM
      3 responses
      23 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by helpwanted, Today, 03:06 AM
      1 response
      19 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      11 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      244 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      388 views
      1 like
      Last Post Gavini
      by Gavini
       
      Working...
      X