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

New here- question

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

    New here- question

    First, i cannot figure out how to make a new post- only a new thread. Forgive my ignorance, but I have been trying for 30 minutes.

    Second i am working on a simple MA crossover strategy- just to see if there is errors in backtesting.

    I used you default, and switched SMA with VWMA,and I have many many errors.

    Here are two trades that seem to be completely backwards.




    #2
    Hello wprosser,

    Thanks for the report.

    New Post is similar to New Thread. You can either start a thread or post a reply to an existing one.

    Those trades don't appear as expected. In order to track down what is happening here:
    Please check that you're running the latest 7.0.1000.4 - Use Help > About to check the version.
    Attach a screenshot of the settings used to create the backtest.
    Indicate the data provider used, and the date / time of the trades that look like this.
    Confirm the only change made to SampleMACrossOver is to change SMA to VWMA

    We'll then run the same test here and look into what may be happening.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Correct response below
      Last edited by wprosser; 05-02-2011, 10:26 AM. Reason: think i responded to myself

      Comment


        #4
        The only change was SMA to VWMA. The data provider is DTN.IQ. I am using that version of ninja.

        Settings for backtest.





        code FWIW

        //
        // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
        // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
        //

        #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 VWMAxxOver : 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()
        {
        VWMA(Fast).Plots[0].Pen.Color = Color.Orange;
        VWMA(Slow).Plots[0].Pen.Color = Color.Green;

        Add(VWMA(Fast));
        Add(VWMA(Slow));

        CalculateOnBarClose = true;
        }

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

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

        Comment


          #5
          Thanks for the screenshots. Not sure why you are seeing those results. I lined up one of the trades you posted in the screenshot and it indicates correctly profitable.

          I would first simply try to create a new chart with no other strategies applied and evaluate if the trade direction is indicated correctly for all trades.
          Attached Files
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Thank you very much sir- presume that the backtest is the exact same that it was just a graphical error.

            Is there a way to make the system not trade until 845 EST as opposed to open with out changing instrument settings. Or is there a way to not have the moving averages roll over from the next day- both would solve the same problem on 20 point gap days

            Comment


              #7
              Yes, you can custom code a time filter. This reference sample can help with this:


              You can also custom code your Moving Average to start at each new session. There are many potential ways you could do this, but what may work best is including an additional condition that checks a # number of bars has elapsed before entering.BarsSinceSession can be used for this.

              if (Bars.BarsSinceSession + 1 > Slow)
              //do something
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                breakout sample

                I'm looking for a sample code that:
                - Enter Long when 1-min close > previous day high
                - STOP LOSS: close position when 1-min close < entry
                - Close out at market close

                Please help.

                Comment


                  #9
                  Hello kcpt1971,

                  Welcome to the NinjaTrader forums!

                  To get started developing strategies in NinjaScript, please see the following link on the strategy development process:


                  If you are new to programming, it's a good idea to get started using the strategy wizard, which is a point and click interface for defining trade conditions and resulting actions.


                  Enter Long when 1-min close > previous day high
                  - STOP LOSS: close position when 1-min close < entry
                  - Close out at market close
                  There's always more than one way to do things, so the following snippet is an example of one approach to this. Exiting on market close is controlled with the ExitOnClose property set when you run the strategy.

                  if (Close[0] > PriorDayOHLC().PriorHigh[0])
                  EnterLong();

                  if (Position.MarketPosition == MarketPosition.Long && Close[0] < Position.AvgPrice)
                  ExitLong();
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    I did this (which did not compile):

                    protected override void OnBarUpdate()
                    {
                    if (Bars.BarsSinceSession+1>Slow)
                    //do nothing here (notice semi colon above removed)
                    else if (CrossAbove(VWMA(Fast), VWMA(Slow), 1))
                    EnterLong();
                    else if (CrossBelow(VWMA(Fast), VWMA(Slow), 1))
                    EnterShort();



                    and I did this( which compiles), but does not work correctly.


                    protected override void OnBarUpdate()
                    {
                    if (Bars.BarsSinceSession+1>Slow);
                    else if (CrossAbove(VWMA(Fast), VWMA(Slow), 1))
                    EnterLong();
                    else if (CrossBelow(VWMA(Fast), VWMA(Slow), 1))
                    EnterShort();
                    }

                    Comment


                      #11
                      I tried using the brakes as opposed to the coma as well, compiles, but does not work correctly

                      protected override void OnBarUpdate()
                      {
                      if (Bars.BarsSinceSession+1>Slow)
                      {}
                      else if (CrossAbove(VWMA(Fast), VWMA(Slow), 1))
                      EnterLong();
                      else if (CrossBelow(VWMA(Fast), VWMA(Slow), 1))
                      EnterShort();

                      Comment


                        #12
                        I posted an example of a condition, but it was intended to be mixed with your other conditions, not stand- alone. Please see here for general help working with branching commands in NinjaScript.

                        Here is how it might fight with your crossing conditions:

                        if (Bars.BarsSinceSession + 1 > Slow && CrossAbove(VWMA(Fast), VWMA(Slow), 1)
                        EnterLong();

                        else if (Bars.BarsSinceSession + 1 > Slow && CrossBelow(VWMA(Fast), VWMA(Slow), 1))
                        EnterShort();
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Thank you Sir, obviously i over-thought that one. So if I want to change the SLOW VWMA to a simple VWAP .... I tried this, however it did not compile:


                          #region Variables
                          private int fast = 10;
                          #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()
                          {
                          VWMA(Fast).Plots[0].Pen.Color = Color.Red;
                          VWAP.Plots[0].Pen.Color = Color.Cyan;

                          Add(VWMA(Fast));
                          Add(VWAP);

                          CalculateOnBarClose = true;
                          }

                          /// <summary>
                          /// Called on each bar update event (incoming tick).
                          /// </summary>
                          protected override void OnBarUpdate()
                          {
                          if (Bars.BarsSinceSession +1> 15 && CrossAbove(VWMA(Fast), VWAP, 1))
                          EnterLong();
                          else if (Bars.BarsSinceSession +1> 15 && CrossBelow(VWMA(Fast), VWAP, 1))
                          EnterShort();
                          }

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

                          /// <summary>
                          #endregion
                          }
                          }

                          Comment


                            #14
                            VWAP is not a system indicator, so you would need to import it first in order to access. You also need to format it according to any inputs expected for the indicator.

                            In the snippet you posted, what line of code (code, not line #) is causing the compile error and what is the specific message under the error column?
                            Ryan M.NinjaTrader Customer Service

                            Comment


                              #15
                              The Code that is causing all the Error is VWAP- even tho it is a current indicator I use.

                              I think I need to define VWAP as the VWAP average?.Or I need to go into the VWAP indicator , copy and remove all the STDEV stuff?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Mestor, 03-10-2023, 01:50 AM
                              16 responses
                              388 views
                              0 likes
                              Last Post z.franck  
                              Started by rtwave, 04-12-2024, 09:30 AM
                              4 responses
                              31 views
                              0 likes
                              Last Post rtwave
                              by rtwave
                               
                              Started by yertle, Yesterday, 08:38 AM
                              7 responses
                              29 views
                              0 likes
                              Last Post yertle
                              by yertle
                               
                              Started by bmartz, 03-12-2024, 06:12 AM
                              2 responses
                              22 views
                              0 likes
                              Last Post bmartz
                              by bmartz
                               
                              Started by funk10101, Today, 12:02 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post funk10101  
                              Working...
                              X