• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Questions from a Beginner

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

    Questions from a Beginner

    Hello:
    - 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.

    #2
    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
    http://www.ninjatrader.com/support/h...nt7/export.htm


    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 - http://www.ninjatrader.com/support/h...price_data.htm
    Session Manager - http://www.ninjatrader.com/support/h...on_manager.htm

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      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,

      Comment


        #4
        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;
        #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 MyCustomv2 : 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>
        /** ************************************************** ************************* */
        public bool BarType (int ThisBar, string Which) {
        bool fnResult = false;
        switch (Which) {
        case "Up":
        if (Close(ThisBar) > Open(ThisBar))
        fnResult = true;
        break;
        case "Down":
        if (Close(ThisBar) < Open(ThisBar))
        fnResult = true;
        break;

        default:
        break;
        }
        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
        [Description("")]
        [GridCategory("Parameters")]
        public int MyInput0
        {
        get { return myInput0; }
        set { myInput0 = Math.Max(1, value); }
        }
        #endregion
        } /*class*/
        } /*namespace*/
        Last edited by tradenj; 02-16-2013, 04:33 PM.

        Comment


          #5
          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.
          http://ninjatrader.com/support/forum...ad.php?t=19346


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

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Da vinci, Today, 04:19 PM
          0 responses
          8 views
          0 likes
          Last Post Da vinci  
          Started by brunoviveiros, Today, 09:36 AM
          1 response
          20 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by GARZONJ, Today, 11:22 AM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by KonalGondal, Today, 10:18 AM
          1 response
          19 views
          0 likes
          Last Post NinjaTrader_Kate  
          Started by Jorge.andres.o, Today, 09:24 AM
          4 responses
          24 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Working...
          X