Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawTest issue within Strategy

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

    DrawTest issue within Strategy

    I've ran into this strange issue with using DrawText within a Strategy. For some reason, the following statement will cause all labels/plots to disappear from my chart.

    DrawText("PH" + CurrentBar, "Current High", barsFromHigh, High[barsFromHigh], Color.Blue);

    I've painstaking gone through what is causing my labels/plots to disappear from the above statement and I've found the culprit is passing the variable "barsFromHigh" for the int barsAgo parameter. So if instead I used the following statement, everything would work.

    DrawText("PH" + CurrentBar, "Current High", 0, High[barsFromHigh], Color.Blue);

    What is going on? The first statement works if I use it within an Indicator, but not for a Strategy? Why can't I pass a variable to int barsAgo?

    Your help would be greatly appreciated. Thanks

    #2
    Hello,



    In your log tab do you see an error that says something like "Index out of Range.."? If so, please visit this link:



    It is likely that your number of bars ago exceeds the number of bars on the chart.
    DenNinjaTrader Customer Service

    Comment


      #3
      Hi, thanks for your reply. However, that is not the problem I having. The bars ago number is not out of range. In fact, I am able to print out the bars ago value, just not pass it into the parameter for DrawText.

      Comment


        #4
        Hello,

        If you aren't already, please Print() the value out right above the DrawText() like this:

        Print(barsFromHigh);
        DrawText("PH" + CurrentBar, "Current High", barsFromHigh, High[barsFromHigh], Color.Blue);

        Does the value have a decimal in it or is it an integer? Is it negative or positive? It must be an integer (whole number) and it must be positive.

        Also, what do you have barsFromHigh declared as? It must be declared as an integer something like this:

        int barsFromHigh = 0;

        Just to confirm, you are not getting the Index out of Range error in your log tab?

        The best way to debug these type of errors is to use a try-catch block. Please see this reference sample: http://www.ninjatrader-support.com/v...ead.php?t=9825
        DenNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        81 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        42 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        64 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        68 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        55 views
        0 likes
        Last Post CarlTrading  
        Working...
        X