No announcement yet.

Partner 728x90


Questions from a Beginner

  • Filter
  • Time
  • Show
Clear All
new posts

    Questions from a Beginner

    - I am new to Ninja circa two weeks ago.
    - Have programmed in Wealth Lab Pro for number of years, first in Pascal, then later in C#
    and am hoping to transcribe some of my Wealth Scripts into Ninja Scripts.

    - Currently have the following questions:
    1. I coded / saved a simple Ninja script as a Strategy file within Ninja that has an
    error I need help with. I wanted to attach it to this thread but can't figure out how
    to do this. If I select "Manage Attachments" under "Attach Files" and then
    "Choose File" what pathway do I follow? Or is there some alternate way?
    2. Control Canter => Tools => New Ninja Script => Strategy => Unlock Code / View Code
    gives error message "A strategy with this name already exists". I do have a few
    strategies listed within the "Strategy" category but even if one is not selected I get this.
    So, how do I pull up a new blank piece of skeleton code? I'm not using / interested in
    the New Strategy Wizard.
    3. Can charts of just regular trading hours be viewed in Ninja, i.e. can pre / post
    market and overnight bars not be displayed?

    Thanks for any inputs on these most basic of questions.

    Hello tradenj,

    Thanks for the post.

    1) If you exported the NinjaScript it will be in the following folder (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<filename>.zip
    If you have not exported the script you can do so by clicking File > Utilities > Export NinjaScript > Select the script and click the right facing arrow > enter a unique name into the 'File name:' input > click Export > click 'Yes' to include referenced scripts.

    To attach a file to your post click the Attachments button (paperclip icon) > click Choose file > Navigate to the files location > select the file and click 'Open' > click the red 'Upload' button to the right to upload the file > close the attachment window.

    Below is a link to the help guide on Exporting NinjaScripts

    2) The error usually means a script with that name already exists. It may be possible a script was saved with the default name of MyCustomStrategy. As the wizard attempts to build the new script it tries to use that name again. You can:
    a) Create a copy of the script with a different name and delete the original by:
    • Click Tools > Edit NinjaScript > Strategy > select MyCustomStrategy > click OK
    • Right-click the code window > select 'Save As...' > enter a unique filename into the 'Save as:' input > click OK
    • Close the strategy code window
    • Click Tools > Edit NinjaScript > Strategy > select MyCustomStrategy > click Delete
    b) Change the name of your strategy with the wizard before unlocking the code by:
    • Click Tools > New NinjaScript > Strategy
    • In the New Strategy Wizard click Next to get to the General settings page
    • Enter a different and unique name into the 'Name:' input
    • Click 'Unlock Code'

    3) Yes, you can change the viewable hours of a chart by changing the Data Series' Session Template to a template that has RTH in the name. RTH stands for Regular Trading Hours. You can do this by:
    • Right-click the chart > select Data Series...
    • In the parameters on the right, under Data, change the value for Session template to a related template with RTH in the name
    • Click OK

    Below are two help guide links.

    The first is to Working with Price Data within charts. In this please refer to the section 'How to edit Data Series parameters' to see where to change a Data Series session template.
    The second is to the Session Manager. This contains information about understanding session templates.

    Working with Price Data -
    Session Manager -

    Chelsea B.NinjaTrader Customer Service


      1. I'm not sure what the problem is there, but if you have an idea of where the problem is you could just copy that part of the code and paste it here.

      2. I believe you have saved a strategy before with the default name "MyCustomStrategy", you will have to click Next, and change the name to something unique. Or you could go into the strategy with that name and change its name on this line: public class MyCustomStrategy : Strategy.

      3. This one I don't know. I do believe that if you are using Kinetick EOD, you won't be able to only see regular trading hours, as that one is packaged with all data into the bars.

      Hope this helps,


        Code with Error

        Hello again and thanks for all of the directives!

        My transition in Wealth Lab from Pascal to C# was composed mainly of
        plugging procedures (translated from Pascal to C) into a C# skeleton without
        entirely understanding some overarching concepts of object-oriented programming
        or precise order / usage of "namespace", "class", "#region", etc.. Also, Wealth Lab code was not event driven.

        This little program is supposed to color the chart background green on up bars. -Will do Copy & Paste here as the file has the following problem --
        "Error on generating strategy."
        "The name 'Open'/ 'Close' do not exist in the current context."

        Would this error result from a disorder in hierarchy, an absent 'using' statement, or ...?

        -Your inputs much appreciated.

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

        // 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 MyCustomv2 : Strategy
        #region Variables
        // Wizard generated variables
        private int myInput0 = 1; // Default setting for MyInput0
        // User defined variables (add any user defined variables below)

        /// <summary>
        /// This method is used to configure the strategy and is called once before any
        strategy method is called.
        /// </summary>
        /** ************************************************** ************************* */
        public bool BarType (int ThisBar, string Which) {
        bool fnResult = false;
        switch (Which) {
        case "Up":
        if (Close(ThisBar) > Open(ThisBar))
        fnResult = true;
        case "Down":
        if (Close(ThisBar) < Open(ThisBar))
        fnResult = true;

        return fnResult;
        /** ************************************************** ************************* */
        protected override void Initialize()
        CalculateOnBarClose = true;
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate( )
        if (BarType (0,"Up"))
        BackColorSeries[0] = Color.Green;

        #region Properties
        public int MyInput0
        get { return myInput0; }
        set { myInput0 = Math.Max(1, value); }
        } /*class*/
        } /*namespace*/
        Last edited by tradenj; 02-16-2013, 03:33 PM.


          Hello tradenj,

          Thanks for your reply.

          The error "The name 'Open'/ 'Close' do not exist in the current context." is referring to how you reference the Open and Close. The Open and Close are public data series objects of whose values you can access using brackets. For example to access the last bars close price, I would use Close[0]. To get the close price one bar ago, I would use Close[1] since the value of 1 within the square brackets represents the number of bars ago whose value you wish to reference.

          Below I have added a link that goes into detail about accessing data series objects.

          Please let me know if I can be of further assistance.
          Chelsea B.NinjaTrader Customer Service


          Latest Posts


          Topics Statistics Last Post
          Started by siroki, Today, 03:22 AM
          0 responses
          Last Post siroki
          by siroki
          Started by nailui, Today, 03:01 AM
          1 response
          Last Post NinjaTrader_Jason  
          Started by an.fedorov, Today, 02:32 AM
          0 responses
          Last Post an.fedorov  
          Started by rustyspring, Today, 01:31 AM
          1 response
          Last Post NinjaTrader_Jason  
          Started by op1031, Today, 12:26 AM
          0 responses
          Last Post op1031
          by op1031