Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RSI PaintBar error above 100

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

    RSI PaintBar error above 100

    Hi

    There is a new indicator posted in the NinjaScript File Sharing section that colors the bars based on indicator values.

    I was playing around with it and found that it doesn't work for charts where the stock or index is above approx 100.

    Wonder if there is any simple solution to this?

    PHP Code:
            protected override void OnBarUpdate()
            {
                // Opaque colors (alpha value defaults to 255 -- max value).
                Color red = Color.FromArgb(255, 0, 0);
                Color green = Color.FromArgb(0, 255, 0);
                Color blue = Color.FromArgb(0, 0, 255);
                Color backcolor = Color.Empty;
                
                
                double rsiValue = RSI(period, smooth)[0];
                int rgbGreen = 0;
                int rgbRed = 0;
                rgbRed = (int) (255*(rsiValue)/100);
                rgbGreen = 255-rgbRed;
                //Print("RSI: " + rsiValue + " Green: " + rgbGreen + " Red: " + rgbRed);
                backcolor = Color.FromArgb(rgbRed,rgbGreen,0);
                BarColor = backcolor;
            } 
    
    the output window gives this error,

    Error on calling 'OnBarUpdate' method for indicator 'JooRSIPaint' on bar 0: Value of '3062' is not valid for 'red'. 'red' should be greater than or equal to 0 and less than or equal to 255.

    #2
    Hello TremblingHand,

    You should be able to view this for all instruments by adding the following statement below OnBarUpdate() {

    if
    (CurrentBar < Period)
    return;

    This statement will allow the RSI to calculate properly before doing any of the other logic.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks that fixed it.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      599 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      344 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
      558 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      557 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X