Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can't draw

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

    Can't draw

    What's the problem with the following code? It doesn't draw. Tried everything - to no avail.

    private double sessionOpen = 0;

    protected override void OnMarketData()
    {
    if (sessionOpen == 0)
    {
    sessionOpen = Close[0];
    DrawHorizontalLine("sessionOpenLine", true, sessionOpen, Color.Blue, DashStyle.Solid, 1);
    }
    }

    #2
    Hello,

    Are you receiving any errors on the Log tab?

    Why are you doing this in OnMarketData? This would be more CPU intensive. I'd suggest moving it to OnBarUpdate()

    If you wish to use it in OnMarketData, you are missing some over rides.

    The following should work as long as your connected to a data provider and getting OnMarketData calls

    Code:
            protected override void OnMarketData(MarketDataEventArgs e)
            {
    
                if (sessionOpen == 0)
                {
    
                    sessionOpen = Close[0];
                    DrawHorizontalLine("sessionOpenLine", true, sessionOpen, Color.Blue, DashStyle.Solid, 1);
    
                }
    
            }
    MatthewNinjaTrader Product Management

    Comment


      #3
      No errors, tried also inside OnBarUpdate, doesn't work. I feel myself stupid..
      Should one call suffice, or do I need to call the method in connection with each new bar? All I need is one horizontal line extending from start of trading to present.

      Comment


        #4
        One call should be enough to Draw it.

        Are you connected to a data provider when doing this?

        If you put a Print(Time[0]) statement in OnBarUpdate, do you get any recent calls?
        MatthewNinjaTrader Product Management

        Comment


          #5
          Simulated data feed, Sim account, OnBarUpdate and OnMarketData get called by turns (verified), and everything else works as one could expect with Sim feed & account. Or do draw methods require real-time data?

          Comment


            #6
            Matthew,
            Interesting finding: If I launch the strategy from a chart, the line appears. If from Control Center / Strategies tab (right click and so forth...), it doesn't. Is this a bug or a feature

            Comment


              #7
              Originally posted by jp_kettunen View Post
              Matthew,
              Interesting finding: If I launch the strategy from a chart, the line appears. If from Control Center / Strategies tab (right click and so forth...), it doesn't. Is this a bug or a feature
              If you don't start the strategy in a chart, the strategy won't know where to draw things.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              581 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              338 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              552 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X