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

User Preference for Time

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

    #16
    Hello,
    With your code I am seeing everything run within the correct time filter. Can you provide a screenshot of the chart showing the drawobjects or entry orders outside of the time filter?
    Cody B.NinjaTrader Customer Service

    Comment


      #17
      Im glad it´s working your end, it was starting to drive me insane

      It must be something (probably very simple) that is wrong inside my code as a whole, this is the first strategy I've ever done from scratch - I'm kind of shocked it compiled at all. lol.

      Thanks for your help.

      Screenshot attached, as you can see it is missing the time filter altogether and printing all trades without break, pretty messy obviously lol. Based on the settings in the screenshot, it shouldn´t have started until 9am.

      I´m going to investigate further and see if I can find what is causing the issue.
      Attached Files

      Comment


        #18
        Hello,
        Unfortunately the screenshot did not come through properly.
        Can I have you try and upload it again?
        Cody B.NinjaTrader Customer Service

        Comment


          #19
          screenshot again. not sure what happened there.
          Attached Files
          Last edited by ScottieDog; 04-05-2016, 08:33 AM.

          Comment


            #20
            This is as simple as it gets, only 2 conditions, with the time filter on each.

            Sorry for the hassle. I´m sure it is something silly.

            It´s totally ignoring the time filter. Can you see why?

            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 MyCustomStrategy : Strategy
                {
                    #region Variables
                    
                    private int startTime = 090000; // Default setting for StartTime
                    private int endTime = 100000; // Default setting for EndTime
            		
                    #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()
                    {
                        CalculateOnBarClose = true;
                    }
            
                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
            			if (GetCurrentAsk() > High[1]
                            && ToTime(Time[0]) >= (startTime) && ToTime(Time[0]) < (endTime));   
                        {
                     //       ExitShort("", "");
                            EnterLong(DefaultQuantity, "");
                        }
            
                   
                        if (GetCurrentBid() < Low[1]
                            && ToTime(Time[0]) >= (startTime) && ToTime(Time[0]) < (endTime));
                       {
                    //        ExitLong("", "");
                            EnterShort(DefaultQuantity, "");
                        }
            		}
            
                    #region Properties
                    [Description("Trading Start")]
                    [GridCategory("Parameters")]
                    public int StartTime
                    {
                        get { return startTime; }
                        set { startTime = Math.Max(1, value); }
                    }
            
                    [Description("Trading End")]
                    [GridCategory("Parameters")]
                    public int EndTime
                    {
                        get { return endTime; }
                        set { endTime = Math.Max(1, value); }
                    }
            		
                    #endregion
                }
            }
            Last edited by ScottieDog; 04-05-2016, 12:18 PM.

            Comment


              #21
              Hello,
              It would appear that you have a semicolon entered after each of your if statement thus ending the condition without an action. I am seeing that the orders are entered in correctly with the semi colon removed.
              If , else if, and else statements do not end with a semi colon. Please see the following link for the syntax when using these conditions: http://ninjatrader.com/support/helpG...g_commands.htm
              Cody B.NinjaTrader Customer Service

              Comment


                #22
                That´s sorted it! Thank-you.

                Is there a way to check for this kind of error without doing it manually? I thought the error log at the bottom of the window would check such things like that, like when it says a ; is missing etc.

                I´m glad thats sorted, that drove me insane the last 24 hours. Thanks again.

                Can´t believe I missed that..



                Originally posted by NinjaTrader_CodyB View Post
                Hello,
                It would appear that you have a semicolon entered after each of your if statement thus ending the condition without an action. I am seeing that the orders are entered in correctly with the semi colon removed.
                If , else if, and else statements do not end with a semi colon. Please see the following link for the syntax when using these conditions: http://ninjatrader.com/support/helpG...g_commands.htm

                Comment


                  #23
                  Hello,
                  This was a logic error not a syntax error really. if(Condition); is considered correct syntax the strategy processes this in a logically faction in the it checks the condition and then when the condition is true its told not to do anything. Logic errors do not come up as compile errors. The only way to resolve logic errors is through debugging.
                  I would highly recommend to review the following thread on debugging your NinjaScript code: http://ninjatrader.com/support/forum...ead.php?t=3418
                  Cody B.NinjaTrader Customer Service

                  Comment


                    #24
                    I´ve added a second time INT in the Variables. This is on a bool which when true exits all trades at a specific time.

                    Cant get it to compile though, i´m not sure why, i´m using the same code as before just with a different variable name.


                    Code:
                    private bool exitAll = true; // Bool to exit all trades
                    private int exitTime = 100000; // Default setting for ExitTime
                    
                     
                    // Condition set 2
                    			if (ExitAll == true
                                    && ToTime(Time[0]) == ToTime(exitTime))
                    			{
                                  // do stuff
                                }
                    I´m getting a CS1502, and CS 1503 when I use the (exitTime)

                    If I use ToTime(10, 0, 0) then it compiles and works as it should. I thought I could just replace the (10,0,0) with a Variable which can be changed in the Preferences?

                    Can you point out my error please?




                    EDIT: When I use
                    Code:
                    ToTime(exitHour, exitMin, 0)
                    it also works, why won't it work using the exitTime I configured?
                    Last edited by ScottieDog; 04-12-2016, 12:08 PM.

                    Comment


                      #25
                      Hello,
                      For this comparison to work you will not have ToTime(exitTime). The ToTime() method takes a datetime variable and has it return as an integer to compare to another integer. As exitTime is already an integer you do not need to have it within the ToTime() method. If exitTime was a datetime object then you would.

                      Please try the following instead:

                      Code:
                      if(ToTime(Time[0] == exitTime)
                          //Do Something
                      
                      ]
                      Cody B.NinjaTrader Customer Service

                      Comment


                        #26
                        Thank-you! That sorted it.

                        Originally posted by NinjaTrader_CodyB View Post
                        Hello,
                        For this comparison to work you will not have ToTime(exitTime). The ToTime() method takes a datetime variable and has it return as an integer to compare to another integer. As exitTime is already an integer you do not need to have it within the ToTime() method. If exitTime was a datetime object then you would.

                        Please try the following instead:

                        Code:
                        if(ToTime(Time[0] == exitTime)
                            //Do Something
                        
                        ]

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by MGHORBEL, 05-06-2024, 06:41 AM
                        4 responses
                        21 views
                        0 likes
                        Last Post MGHORBEL  
                        Started by ChastiJose, Today, 03:37 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post ChastiJose  
                        Started by Klaus Hengher, Today, 03:13 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post Klaus Hengher  
                        Started by ewileznwpods, Today, 02:57 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post ewileznwpods  
                        Started by 1001111, Today, 01:35 AM
                        0 responses
                        6 views
                        0 likes
                        Last Post 1001111
                        by 1001111
                         
                        Working...
                        X