Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I need help with code to add color to candles/bars ?

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

    I need help with code to add color to candles/bars ?

    My knowledge in NT8 programming is very little and I need to add the following situation in the source code, but I have already tried some alternatives, but without success.



    If possible, someone who can help me and write the code, because I already had the help of the support that indicated technical documents, but I couldn't put it into practice in the indicator code.​



    Change the candlesticks/bars chains, when:

    HS = (d18[0] > 0 && dO18[0] < 0 && d18[0] > d38[0] && dO18[0] < d38[0]);
    color Lime

    LS = (d18[0] < 0 && dO18[0] > 0 && d18[0] < d38[0] && dO18[0] > d38[0]);
    color red

    H = (d18[0] > 0 && dO18[0] < 0 && d18[0] > d38[0] && dO18[0] < d38[0] && d18[0] > d208[0] && dO18[0 ] < d208[0]);
    color cyan

    L = (d18[0] < 0 && dO18[0] > 0 && d18[0] < d38[0] && dO18[0] > d38[0] && d18[0] < d208[0] && dO18[0 ] > d208[0]);
    color magenta


    ================================================== =====


    Below is the complete and working code, but without the candles/bars coloring coding.


    ================================================== ===


    //
    region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    namespace NinjaTrader.NinjaScript.Indicators.mah_Indicators
    {
    public class Indicators : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "SJunior";
    Name = "SJunior";
    IsSuspendedWhileInactive = true;

    AddPlot(new Stroke(Brushes.LightPink, 4), PlotStyle.Line, "d38");
    AddPlot(new Stroke(Brushes.DarkGreen, 4), PlotStyle.Line, "d208");
    AddPlot(new Stroke(Brushes.Cyan, 1), PlotStyle.Bar, "d18");
    AddPlot(new Stroke(Brushes.Yellow, 1), PlotStyle.Bar, "dO18");
    AddPlot(new Stroke(Brushes.LightCyan, 1), PlotStyle.Line, "osc");
    AddPlot(new Stroke(Brushes.Goldenrod, 1), PlotStyle.Line, "srs");
    AddPlot(new Stroke(Brushes.Goldenrod, 1), PlotStyle.Line, "sri");
    AddPlot(new Stroke(Brushes.Yellow, 1), PlotStyle.Line, "nvel_0");


    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 20) return;

    d38[0] = (((SMA(1)[0]-SMA(8)[0])/SMA(8)[0])*100);
    d208[0] = (((SMA(20)[0]-SMA(8)[0])/SMA(8)[0])*100);
    d18[0] = (((SMA(1)[0]-SMA(8)[0])/SMA(8)[0])*100);
    dO18[0] = (((SMA(1)[1]-SMA(8)[0])/SMA(8)[0])*100);
    osc[0] = (d38[0]-d208[0]);
    srs[0] = (((2*StdDev(8)[0])/SMA(8)[0])*100);
    sri[0] = (((-2*StdDev(8)[0])/SMA(8)[0])*100);
    nivel_0[0] = 0;



    if (d208[0] <= 0 && d208[0] < d208[1])
    PlotBrushes[1][0] = Brushes.Green;
    else if (d208[0] >= 0 && d208[0] > d208[1])
    PlotBrushes[1][0] = Brushes.Red;
    else if (d208[0] <= 0 && d208[0] > d208[1])
    PlotBrushes[1][0] = Brushes.Magenta;
    else if (d208[0] >= 0 && d208[0] < d208[1])
    PlotBrushes[1][0] = Brushes.Orange;


    if (osc[0] >= 0 && osc[0] > osc[1])
    PlotBrushes[4][0] = Brushes.Green;
    else if (osc[0] <= 0 && osc[0] < osc[1])
    PlotBrushes[4][0] = Brushes.Red;
    else if (osc[0] >= 0 && osc[0] < osc[1])
    PlotBrushes[4][0] = Brushes.Magenta;
    else if (osc[0] <= 0 && osc[0] > osc[1])
    PlotBrushes[4][0] = Brushes.Orange;



    }

    region Properties

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> d38
    {
    get { return Values[0]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> d208
    {
    get { return Values[1]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> d18
    {
    get { return Values[2]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> dO18
    {
    get { return Values[3]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> osc
    {
    get { return Values[4]; }
    }


    [Browsable(false)]
    [XmlIgnore]
    public Series<double> srs
    {
    get { return Values[5]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> sri
    {
    get { return Values[6]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> nivel_0
    {
    get { return Values[7]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public bool HiE
    {
    get; set;
    }

    [Browsable(false)]
    [XmlIgnore]
    public bool LoE
    {
    get; set;
    }

    [Browsable(false)]
    [XmlIgnore]
    public bool Hi
    {
    get; set;
    }

    [Browsable(false)]
    [XmlIgnore]
    public bool Lo
    {
    get; set;
    }

    #endregion
    }
    }

    region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private mah_Indicators.Indicators[] cacheIndicators;
    public mah_Indicators.Indicators Indicators()
    {
    return Indicators(Input);
    }

    public mah_Indicators.Indicators Indicators(ISeries<double> input)
    {
    if (cacheIndicators != null)
    for (int idx = 0; idx < cacheIndicators.Length; idx++)
    if (cacheIndicators[idx] != null && cacheIndicators[idx].EqualsInput(input))
    return cacheIndicators[idx];
    return CacheIndicator<mah_Indicators.Indicators>(new mah_Indicators.Indicators(), input, ref cacheIndicators);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.mah_Indicators.Indicators Indicators()
    {
    return indicator.Indicators(Input);
    }

    public Indicators.mah_Indicators.Indicators Indicators(ISeries<double> input )
    {
    return indicator.Indicators(input);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.mah_Indicators.Indicators Indicators()
    {
    return indicator.Indicators(Input);
    }

    public Indicators.mah_Indicators.Indicators Indicators(ISeries<double> input )
    {
    return indicator.Indicators(input);
    }
    }
    }

    #endregion​

    #2
    The color of the candle body is determined by BarBrush.

    The background color of the vertical column that contains
    the candle is controlled by BackBrush.

    Comment


      #3
      bltdavid, Yes, but I couldn't do the coding of this function in my indicator.

      Could you help me with this coding?
      Last edited by SJunior; 06-28-2023, 06:06 AM.

      Comment


        #4
        Hello SJunior,

        As an example:

        Code:
        if (d18[0] > 0 && dO18[0] < 0 && d18[0] > d38[0] && dO18[0] < d38[0])
        BarBrush = Brushes.Red;

        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script.

        You can search our extensive library of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more!

        https://ninjatraderecosystem.com/sea...mming-services

        Educators - https://ninjatraderecosystem.com/sea...ures=education

        You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third party services for NinjaTrader all pricing and support information will need to be obtained through the consultant.

        This NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The companies and services listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.​
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        81 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        42 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        64 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        68 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        55 views
        0 likes
        Last Post CarlTrading  
        Working...
        X