Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Background or Candle Color Change Based on Calculations

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

    Background or Candle Color Change Based on Calculations

    I would like to create an indicator that I can upload that is pretty simple but new to NinjaTrader and know how to code but need help with my first indicator if people or someone can help me.

    Here is what I want to do.

    puts inputs:

    as n, say n =3.

    Then do these things:
    1) Take the average of the 'High' of the past 3(n) candles = RangeHigh
    2) Take the average of the 'Low' of the past 3 (or n) candles = RangeLow
    3) Then get the median or the RangeHigh & RangeLow; such as Median = ((RangeHigh + RangeLow)/2)
    4) Then simply define: if Median is less than close of current bar; then that means 'Up, positive" Then using that make background Blue and/or candles Blue
    5) Then on the other side if Close < Median, then 'White'

    ---
    it would look somethign like this but in NinjaScript Language

    h=high
    l=low

    rangehigh = Average((h, n));
    def rangelow = Average((l, n));
    median = ((rangehigh + rangelow) / 2);
    updirection = if c > median then paint Blue;
    downdirection = if c < median then paint White;

    ----

    I was able to find a way to change the backgrounds using BackBrushAll (per below) but not sure how to execute what I want to do here into this... I know it is not comlicated for most people here but really need help to get started.

    PlotBrushes[0][0] = Brushes.White;

    BackBrushAll = Brushes.Blue;
    BackBrushAll = null;
    BackBrushAll = Value[0] >= 0 ? Brushes.Blue : Brushes.White;

    Thanks would really appreciate any help I can get.

    #2
    Hello EPTrader,

    Thank you for your note.

    Basically, you would want to use the built in SMA indicator to calculate the average ranges, save those to variables, calculate the Median and then it's a matter of assigning the brushes based on whether the close price is higher or lower than the calculated median.

    I've created a simple example script that has comments that should get you going in the right direction. This indicator will change the candle color, not the background.

    Please let us know if we may be of further assistance to you.
    Attached Files

    Comment


      #3
      Awesome you rock Kate!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      649 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      370 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      109 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      574 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      576 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X