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

Using Time

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

    Using Time

    I'm wondering why the following code is not working. I'm trying to draw text on the bottom left hand side of panel 1 if the current time is between a start and end time.

    At the moment this code display these text "Check news" all of the time.

    Code:
      protected override void OnBarUpdate()
            {  
            // If time is between 11:08 AM and 11:10 AM, draw text in the bottom left corner of panel 1    
                if (ToTime(Time[0]) >= 110800 && ToTime(Time[0]) <= 111000) 
                    {
                    DrawTextFixed("BoxBottom",("Check news"), TextPosition.BottomLeft, Color.Black, new Font("Arial", 14), Color.Blue, Color.GreenYellow, 7);
                    }   
            }

    #2
    Originally posted by suprsnipes View Post
    I'm wondering why the following code is not working. I'm trying to draw text on the bottom left hand side of panel 1 if the current time is between a start and end time.

    At the moment this code display these text "Check news" all of the time.

    Code:
      protected override void OnBarUpdate()
            {  
            // If time is between 11:08 AM and 11:10 AM, draw text in the bottom left corner of panel 1    
                if (ToTime(Time[0]) >= 110800 && ToTime(Time[0]) <= 111000) 
                    {
                    DrawTextFixed("BoxBottom",("Check news"), TextPosition.BottomLeft, Color.Black, new Font("Arial", 14), Color.Blue, Color.GreenYellow, 7);
                    }   
            }

    After you put the Fixed Text you have to remove it when conditions are no longer met.
    RemoveDrawObject("BoxBottom");

    Comment


      #3
      Thanks for your reply Roonius, but how do I remove it? And where would I place the code?

      Comment


        #4
        Hi Suprsnipes,

        Add the snippet below to remove your box when you're not using it. This goes after the last closing bracket } of your if statement.

        Code:
        [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT]
        [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]{[/SIZE][/FONT]
        [SIZE=2][FONT=Courier New]RemoveDrawObject([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BoxBottom"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]); [/SIZE][/FONT]
        [SIZE=2][FONT=Courier New]}[/FONT][/SIZE][/SIZE][/FONT]
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Really appreciate the help guys.

          This is the code, however, it does not behave as expected...

          The "BoxBottom" text still remains.

          Code:
           protected override void OnBarUpdate()
                  {            
                  // Time between 12:01 PM and 12:03 PM    
                      if (ToTime(Time[0]) >= 120100 && ToTime(Time[0]) <= 120300) 
                          {
                          DrawTextFixed("BoxBottom","Check news", TextPosition.BottomLeft, Color.Black, new Font("Arial", 14), Color.Blue, Color.GreenYellow, 7);
                          }
                              else
                              {
                                  RemoveDrawObject("BoxBottom"); 
                              }
                  }

          Comment


            #6
            Ok, the code is working no problems (I had it on an instrument that wasn't trading any volume)

            Thanks alot for your help Roonius and NinjaTrader_RyanM.

            Originally posted by suprsnipes View Post
            Really appreciate the help guys.

            This is the code, however, it does not behave as expected...

            The "BoxBottom" text still remains.

            Code:
             protected override void OnBarUpdate()
                    {            
                    // Time between 12:01 PM and 12:03 PM    
                        if (ToTime(Time[0]) >= 120100 && ToTime(Time[0]) <= 120300) 
                            {
                            DrawTextFixed("BoxBottom","Check news", TextPosition.BottomLeft, Color.Black, new Font("Arial", 14), Color.Blue, Color.GreenYellow, 7);
                            }
                                else
                                {
                                    RemoveDrawObject("BoxBottom"); 
                                }
                    }

            Comment


              #7
              Alternative solution

              See here

              Produced by Roonius himself - a masterclass in NS - very useful and completely non intrusive

              Comment


                #8
                Thanks alot Mindset

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Skifree, Today, 03:41 AM
                1 response
                2 views
                0 likes
                Last Post Skifree
                by Skifree
                 
                Started by usazencort, Today, 01:16 AM
                0 responses
                1 view
                0 likes
                Last Post usazencort  
                Started by kaywai, 09-01-2023, 08:44 PM
                5 responses
                603 views
                0 likes
                Last Post NinjaTrader_Jason  
                Started by xiinteractive, 04-09-2024, 08:08 AM
                6 responses
                23 views
                0 likes
                Last Post xiinteractive  
                Started by Pattontje, Yesterday, 02:10 PM
                2 responses
                23 views
                0 likes
                Last Post Pattontje  
                Working...
                X