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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      78 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X