Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with painting on chart

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

    Help with painting on chart

    Hi all,
    for learning puprose and to apply on my other indicators; i tried in the below code to marking the chart when the signal from of overbought / oversold from simple RSI indicator using region highlight x as drawing.
    It works but im sure it is not the right way, because it is repeating and drawing again and again the same thing when using onprice change until the last candle bar is not even visible..
    is there a way to save and access the start point and end point of each signal so that the highlight region is only drawn once? or what is the best way in general to do the below?
    advice appreciated




    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.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators.Peak
    {
    public class RSImarker : Indicator
    {

    int i = 0;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"RSI mean reversion indicator ";
    Name = "RSImarker";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    Legnth = 50;
    Smooth = 25;
    Overbought = 70;
    Oversold = 30;
    AddPlot(Brushes.Orange, "RSIgap");
    AddPlot(Brushes.Firebrick, "OB");
    AddPlot(Brushes.ForestGreen, "OS");
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    double rsi = RSI(Legnth,Smooth)[0];
    int signalState = 0;



    //signal painting on chart.
    if (rsi > Overbought)
    { signalState = 1;
    Draw.RegionHighlightX(this,"Buy"+i++,0,1,Brushes.T ransparent,Brushes.Firebrick,50);
    }
    else if (rsi < Oversold)
    { signalState = -1;
    Draw.RegionHighlightX(this,"Buy"+i++,0,1,Brushes.T ransparent,Brushes.ForestGreen,50);
    }
    else
    signalState = 0;


    RSIgap[0] = rsi;
    OB[0] = Overbought;
    OS[0] = Oversold;



    }

    region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Legnth", Order=1, GroupName="Parameters")]
    public int Legnth
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Smooth", Order=2, GroupName="Parameters")]
    public int Smooth
    { get; set; }

    [NinjaScriptProperty]
    [Range(0, double.MaxValue)]
    [Display(Name="Overbought", Order=3, GroupName="Parameters")]
    public double Overbought
    { get; set; }

    [NinjaScriptProperty]
    [Range(-1000, double.MaxValue)]
    [Display(Name="Oversold", Order=4, GroupName="Parameters")]
    public double Oversold
    { get; set; }

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

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

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

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

    region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private Peak.RSImarker[] cacheRSImarker;
    public Peak.RSImarker RSImarker(int legnth, int smooth, double overbought, double oversold)
    {
    return RSImarker(Input, legnth, smooth, overbought, oversold);
    }

    public Peak.RSImarker RSImarker(ISeries<double> input, int legnth, int smooth, double overbought, double oversold)
    {
    if (cacheRSImarker != null)
    for (int idx = 0; idx < cacheRSImarker.Length; idx++)
    if (cacheRSImarker[idx] != null && cacheRSImarker[idx].Legnth == legnth && cacheRSImarker[idx].Smooth == smooth && cacheRSImarker[idx].Overbought == overbought && cacheRSImarker[idx].Oversold == oversold && cacheRSImarker[idx].EqualsInput(input))
    return cacheRSImarker[idx];
    return CacheIndicator<Peak.RSImarker>(new Peak.RSImarker(){ Legnth = legnth, Smooth = smooth, Overbought = overbought, Oversold = oversold }, input, ref cacheRSImarker);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.Peak.RSImarker RSImarker(int legnth, int smooth, double overbought, double oversold)
    {
    return indicator.RSImarker(Input, legnth, smooth, overbought, oversold);
    }

    public Indicators.Peak.RSImarker RSImarker(ISeries<double> input , int legnth, int smooth, double overbought, double oversold)
    {
    return indicator.RSImarker(input, legnth, smooth, overbought, oversold);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.Peak.RSImarker RSImarker(int legnth, int smooth, double overbought, double oversold)
    {
    return indicator.RSImarker(Input, legnth, smooth, overbought, oversold);
    }

    public Indicators.Peak.RSImarker RSImarker(ISeries<double> input , int legnth, int smooth, double overbought, double oversold)
    {
    return indicator.RSImarker(input, legnth, smooth, overbought, oversold);
    }
    }
    }

    #endregion
    zz0.x06e5leyunzz

    #2
    Hello madb123,

    Thanks for your post.

    Draw.RegionHighlightX() will draw a region from the start bar to the end bar across the entire panel's X axis (top of the panel to the bottom of the panel) whenever the method is called.

    When using Calculate.OnPriceChange, the indicator will draw the region up to the current bar forming on the chart since it is processing logic on each change in price. If you would like the indicator to only process logic at the close of a bar, Calculate.OnBarClose should be used.

    If you provide the Draw.RegionHighlightX() method's Tag parameter with a unique signal name, a new object will be drawn on the chart anytime the condition to draw the object becomes true.

    To only draw the object a single time, you would need to use the same Tag parameter each time the Draw.Region() method is called.

    From the Draw.RegionHighlightX() help guide: "If you pass in a value of "myTag", each time this tag is used, the same draw object is modified. If unique tags are used each time, a new draw object will be created each time."

    Draw.RegionHighlightX(): https://ninjatrader.com/support/help...highlightx.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    563 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    329 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    547 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    548 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X