Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawTextFixed() Question

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

    DrawTextFixed() Question

    I am trying to draw on the screen "CL IN session" if the time is >= to 8:30 AM and <= 10:30 AM and "CL NOT In Session" if the time is <= 8:29 AM OR >= to 10:31 AM

    The following is the code I am using, but it won't print to the chart:


    protected override void OnBarUpdate()
    {
    if (Historical)
    return;

    if (ToTime(Time[0]) >= ToTime(8, 30, 0) && ToTime(Time[0]) <= ToTime(10, 30, 0))
    {
    DrawTextFixed("Session","CL IN Session",TextPosition.TopRight);
    }

    if (ToTime(Time[0]) <= ToTime(8, 29, 0) || ToTime(Time[0]) >= ToTime(10, 31, 0))
    {
    DrawTextFixed("Session","CL NOT In Session",TextPosition.TopRight);
    }

    // Logic for long entry
    if (long conditions are true)
    {
    do stuff
    }

    // Logic for short entry
    if (short conditions are true)
    {
    do stuff
    }

    }


    Any thoughts?

    #2
    Hello ghunt,

    Your snippet is working OK here.

    Are there any error messages in the log tab of the control center?
    Which version are you using? Check with Help > About
    Can you confirm that it's a strategy you're using?
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan,

      I am using version 6.5.1000.16. There are no error messages in the log tab and yes, it is a strategy.

      Thanks!

      Comment


        #4
        I'm not sure why it's not displaying for you. Have you attempted to remove and reapply to your chart?

        Since you're using if (Historical) return; are you on a chart that is currently receiving incoming data?
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Ryan,

          I just quit, then restarted NT, then deleted, removed, then applied a new chart. I am running in Sim mode with live data, to test the strategy...still doesn't work!

          Comment


            #6
            I see. Syntax looks good and I'm not sure what else to check.

            Let's proceed with a phone call and remote assistance so I can see your setup from here. Can you send a note to [email protected] Attn RyanM and reference this thread:
            Support for the development of custom automated trading strategies using NinjaScript.


            Include your phone number and availability as well. .
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Thanks for your time on the phone today. We determined the issue was caused by RemoveDrawObjects(); statement you had later on in the code.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Ryan,

                Thanks for your time today.

                I put the RemoveDrawObjects() into the code because I wanted the horizontal lines and text that was printed on the chart to be removed after the trade was completed. So I fixed it by putting the lines to print "CL IN Session" and "CL NOT In Session" after the RemoveDrawObjects() code:

                // If the strategy has terminated reset the strategy id
                else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
                atmStrategyId = string.Empty;
                RemoveDrawObjects();

                if (ToTime(Time[0]) >= ToTime(8, 30, 0) && ToTime(Time[0]) <= ToTime(10, 30, 0))
                {
                DrawTextFixed("Session","CL IN Session",TextPosition.TopRight);
                Print("a" + Time[0]);
                }

                if (ToTime(Time[0]) <= ToTime(8, 29, 0) || ToTime(Time[0]) >= ToTime(10, 31, 0))
                {
                DrawTextFixed("Session","CL NOT In Session",TextPosition.TopRight);
                Print("b" + Time[0]);
                }

                It now works like I had planned.

                Thanks again for your help!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                649 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                370 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                109 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                574 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                576 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X