Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with DrawTextFixed()

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

    Problem with DrawTextFixed()

    If I add DrawTextFixed() to a multi timeframe indicator, it stops working. Please find below the indicator

    - TestMTF -> works
    - TestMTFFailure -> fails

    I have only added a single line (line 48) to prevent the indicator from working. Used a simple 15 min chart, secondary data series was 5 min. The failure-indicator only works, if the bar period of the secondary series is larger than the bar period of the primary series.
    Attached Files

    #2
    Harry,

    When working with multi-time frame scripts it is important to ensure your Bars actually have enough bars before beginning. You will need to add the following at the very beginning of OnBarUpdate():
    Code:
    if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired)
         return;
    For more information on this concept please see here: http://www.ninjatrader.com/support/h...nstruments.htm

    Basically what is happening when you use a primary > secondary series your first OnBarUpdate() event is the secondary series which is used to build up that first primary series bar. Your code tries to do a Draw() method while no primary bars exist, but since drawing is only relevant on the primary you run into the issue you experienced.
    Code:
    Error on calling 'OnBarUpdate' method for indicator 'TestMTFFailure' on bar 0: Bar index needs to be greater/equal 0
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your answer. I made the changes as suggested.

      The point which confuses me is that DrawTextFixed() is not related to any bars object and I expected that it would plot irrespectively whether the BarSeries 0 or the BarSeries 1 is called.

      Comment


        #4
        That is correct. It will plot irrespective, BUT it needs to actually have bars it can plot on. When there are no bars in the primary there is nothing to plot on and that is where you ran into the issue.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmoran13, Yesterday, 01:02 PM
        0 responses
        23 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        16 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        160 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        94 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        147 views
        2 likes
        Last Post CaptainJack  
        Working...
        X