Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Errors in my simple code

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

    Errors in my simple code

    Hello All

    I'm a beginner and I'm trying ti write a simple code as a learning experience. I'm doing something wrong as I get errors when I compile.

    I'm adding a condition to go long if the current price is higher then the last bar and going short if the current price at bar close is lower the the last bar to the NINJATRADER SAMPLE STRATEGY MACROSSOVER

    Is anyone able to see my problem and help me correct it so that I can move on with some backtesting.

    Thank you very much!!! Dennis

    #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.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Simple moving average cross over strategy.
    /// </summary>
    [Description("Simple moving average cross over strategy.")]
    public class DKAMACrossOver : Strategy
    {
    #region Variables
    private int fast = 10;
    private int slow = 25;
    #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()
    {
    SMA(Fast).Plots[0].Pen.Color = Color.Orange;
    SMA(Slow).Plots[0].Pen.Color = Color.Green;

    Add(SMA(Fast));
    Add(SMA(Slow));

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick).
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (CrossAbove(SMA(Fast), SMA(Slow), 1)
    && (Close[1] > Close[0]) )
    EnterLong();
    else if (CrossBelow(SMA(Fast), SMA(Slow), 1)
    && (Close[1] < Close[0]))
    EnterShort();
    }[/COLOR]

    #region Properties
    /// <summary>
    /// </summary>
    [Description("Period for fast MA")]
    [GridCategory("Parameters")]
    public int Fast
    {
    get { return fast; }
    set { fast = Math.Max(1, value); }
    }

    /// <summary>
    /// </summary>
    [Description("Period for slow MA")]
    [GridCategory("Parameters")]
    public int Slow
    {
    get { return slow; }
    set { slow = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    Hello dennis3495,

    Thank you for writing in.

    Please remove the text [/COLOR] from your code as this is not valid syntax. Your code will then compile once this is removed.

    Originally posted by dennis3495 View Post
    protected override void OnBarUpdate()
    {
    if (CrossAbove(SMA(Fast), SMA(Slow), 1)
    && (Close[1] > Close[0]) )
    EnterLong();
    else if (CrossBelow(SMA(Fast), SMA(Slow), 1)
    && (Close[1] < Close[0]))
    EnterShort();
    }[/COLOR]


    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thank You Zachary
      I'm still have a problem. when I compile I'm getting errors on line 68,76,84 and 91 ??

      66 {
      67 get { return fast; }
      68 set { fast = Math.Max(1, value); }
      69 }
      70
      71 /// <summary>
      72 /// </summary>
      73 [Description("Period for slow MA")]
      74 [GridCategory("Parameters")]
      75 public int Slow
      76 {
      77 get { return slow; }
      78 set { slow = Math.Max(1, value); }
      79 }
      80 #endregion
      81 }
      }

      Comment


        #4
        Hello dennis3495,

        Please provide the actual strategy script itself rather than copying and pasting the code on the forum so I may investigate further.

        The strategy can be found within the Documents\NinjaTrader 7\bin\Custom\Strategy folder on your computer.

        Once you have found your script, attach it to your reply post.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          OK here you go!
          Attached Files

          Comment


            #6
            Hello dennis3495,

            I am not seeing any compile errors with the script you have provided me.

            Can you please provide a screenshot of the errors that you are seeing when compiling?

            To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

            Click here for instructions

            Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

            Click here for detailed instruction

            Please attach the screenshot to your reply post.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              THanks

              Here you go!!
              Attached Files

              Comment


                #8
                Hello dennis3495,

                Errors in orange are referring to a different script.

                Take a look at the NinjaScript File column. These errors are from the dkaNEXTBARSMA.cs script and not the current script you're looking at.

                Double-click on an error and it'll automatically open a new NinjaScript Editor window for that script. You can then resolve the errors there.
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  OK Thanks!!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Waxavi, Today, 02:10 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post Waxavi
                  by Waxavi
                   
                  Started by TradeForge, Today, 02:09 AM
                  0 responses
                  9 views
                  0 likes
                  Last Post TradeForge  
                  Started by Waxavi, Today, 02:00 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post Waxavi
                  by Waxavi
                   
                  Started by elirion, Today, 01:36 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post elirion
                  by elirion
                   
                  Started by gentlebenthebear, Today, 01:30 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post gentlebenthebear  
                  Working...
                  X