• 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

New-code problems

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

    New-code problems

    I am testing a simple system in AAPL, 365 days of data but I get just one trade that is closed at the last day, meaning that profit target PT and stop-loss SL of 2% do not work
    Thanks


    Code:
    #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 POL : Strategy
        {
            #region Variables
            // Wizard generated variables
            private double pT = 2.000; // Default setting for PT
            private double sL = 2.000; // Default setting for SL
            // 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()
            {
                SetProfitTarget("", CalculationMode.Percent, PT);
                SetStopLoss("", CalculationMode.Percent, SL, true);
                CalculateOnBarClose = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Condition set 1
                if (Close[0] > Close[10])
                {
                    EnterLong(DefaultQuantity, "");
                }
    			
    			
            }
    
            #region Properties
            [Description("profit target")]
            [GridCategory("Parameters")]
            public double PT
            {
                get { return pT; }
                set { pT = Math.Max(1, value); }
            }
    
            [Description("stop-loss")]
            [GridCategory("Parameters")]
            public double SL
            {
                get { return sL; }
                set { sL = Math.Max(1, value); }
            }
            #endregion
        }
    }

    #2
    Hello ricko,

    Thank you for your post.

    So I may investigate this matter further please answer the following questions.

    What version of NinjaTrader are you using? You can check under Help -> About (Example: 7.0.1000.30)

    Who are you connected to? This is displayed by green on lower left corner of the Control Center window.

    What interval is selected for your chart(s)? (Example: Tick, Minute, Day, etc.)

    I look forward to your response.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Thanks. v 7 1000.30 Connected to yahoo. Interval day.

      Note that your moving average cross example works with the AAPL chart and I get a backtest with signals, etc. My strategy I quoted does not work. The first entry signal is correct but then no exit until the last bar..

      Comment


        #4
        Hello ricko,

        Thank you for your response.

        Are you trying to do 200%, or 2%? If 2%, try 0.02 instead of 2.00.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Hello Partick,

          I wanted 2% profit target and 2% stop-loss. I changed the 2 to 0.02 but again same thing: first entry point and then no exit until last bar. I used AAPL daily data 365 bars. Here is the code.

          #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>
          /// Percent, open, long
          /// </summary>
          [Description("Percent, open, long")]
          public class PercOL : Strategy
          {
          #region Variables
          // Wizard generated variables
          private double pT = 0.02; // Default setting for PT
          private double sL = 0.02; // Default setting for SL
          // 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()
          {
          SetProfitTarget("", CalculationMode.Percent, PT);
          SetStopLoss("", CalculationMode.Percent, SL, true);

          CalculateOnBarClose = true;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // Condition set 1
          if (Close[0] > Close[10])
          {
          EnterLong(DefaultQuantity, "");
          }
          }

          #region Properties
          [Description("Profit taregt")]
          [GridCategory("Parameters")]
          public double PT
          {
          get { return pT; }
          set { pT = Math.Max(0.02, value); }
          }

          [Description("Stop loss")]
          [GridCategory("Parameters")]
          public double SL
          {
          get { return sL; }
          set { sL = Math.Max(0.02, value); }
          }
          #endregion
          }
          }

          Comment


            #6
            I think I found the problem. It appears that I have to put a name for the signal and put that also in the profit target and stop-loss order.

            Comment


              #7
              Hello ricko,

              That is actually how it should be done. Although I would recommend an actual value rather than a blank string of "". So try "Long" for example.
              Patrick H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by JPPoulin, Today, 01:32 PM
              2 responses
              11 views
              0 likes
              Last Post JPPoulin  
              Started by bltdavid, Today, 01:09 PM
              0 responses
              9 views
              0 likes
              Last Post bltdavid  
              Started by pstrusi, Today, 12:50 PM
              2 responses
              8 views
              0 likes
              Last Post pstrusi
              by pstrusi
               
              Started by ralett, Today, 11:52 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_PatrickG  
              Started by rtwave, Yesterday, 07:06 PM
              2 responses
              27 views
              0 likes
              Last Post rtwave
              by rtwave
               
              Working...
              X