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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      57 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      78 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      39 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      101 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      61 views
      0 likes
      Last Post PaulMohn  
      Working...
      X