Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Infinite Loop in My NinjaScript Code?

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

    Infinite Loop in My NinjaScript Code?

    Hello,

    I'm learning C# and NinjaScript and am working with an indicator to help with this.

    I have an alert indicator that gives me an audio alert, paints the candlestick bars a different color and draws a horizontal line when the RSI is above 50 or below 45.

    But the horizontal lines drawn would stay on the chart the entire time I was analyzing the markets, which is not what I want.

    I only want for the horizontal line that corresponds to the current condition of the RSI (bullish or bearish) to be there.

    So I created a While Loop hoping to have one of the horizontal lines that were drawn, the one that no longer applies, to be removed from the chart when the RSI changes from bullish to bearish or vise versa.

    But that seems to have created an infinite loop. My computer was getting stuck. But I was able to later comment out that While Loop code.

    Screenshot attached.

    Any other such loops or code that I can use to have only one of the horizontal lines present, based on if the RSI is above 50 or below 45?

    How about a Switch Statement or If Else Statement? Any suggestions?
    Attached Files

    #2
    Hello i2w8am9ii2,

    Thanks for your post.

    If I may suggest, you might be better off using panel coloring to indicate when your conditions are true. Using BackBrushAll would allow you to paint the background of both price and indicator panel: https://ninjatrader.com/support/help...ckbrushall.htm

    Otherwise, to answer your question of having one line or the other, the easy answer would be to use the same tag name for both lines as this automatically means only the latest one will remain on the chart. You may also want to add a condition where if it (RSI) is between 45 and 50, to remove the line by the tag name in RemoveDrawObject() https://ninjatrader.com/support/help...drawobject.htm

    Comment


      #3
      Hi Paul,

      Great. Thanks once again for your help.

      I will try that out.

      Comment


        #4
        Hi Paul,

        I tried out your suggestion and it worked great.

        Thanks again. I appreciate the info, ideas and help.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        605 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        351 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        560 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        561 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X