Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Paul H.NinjaTrader Customer Service

    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 habeebft, Today, 07:27 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Started by AveryFlynn, Today, 04:57 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Max238, Today, 01:28 AM
        4 responses
        37 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by r68cervera, Today, 05:29 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by geddyisodin, Today, 05:20 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X