Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Issues plotting my indicator

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

    Issues plotting my indicator

    Hey, I'm new to ninja trader code and i'm trying to develop an indicator that gives me the lowest and highest RSI values from the last X values. I tested it through print function and i'm getting values in the output panel. Despite that i'm not getting any line on my graph when plotting the indicator on my chart (the window appears but no lines visible). Can you help me? I leave my code as it is at the moment.

    I'm mainly doing this to implement on a strategy since i can't figure out how to call the lowest RSi value from the past 50 bars in my strategey. If you know how to do it and what is the lines of code for that i would appreciate the help.

    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
    {
    public class RSIExtremes1 : Indicator
    {
    private Series<double> DataSeries;
    private Series<double> lowestRSI;
    private Series<double> highestRSI;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "RSIExtremes1";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = false;
    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 = false;
    Period = 10;
    Period_RSI = 10;
    AddPlot(Brushes.Red, "Lowest");
    AddPlot(Brushes.DarkGreen, "Highest");
    }

    else if (State == State.DataLoaded)
    {
    DataSeries = new Series<double>(this);
    lowestRSI = new Series<double>(this);
    highestRSI = new Series<double>(this);

    }
    }

    protected override void OnBarUpdate()
    {
    Print("Lowest RSI: " + lowestRSI[0]); // Print RSI value
    //Add your custom indicator logic here.
    if (CurrentBar < Period)
    return;

    double lowest = double.MaxValue;
    double highest = double.MinValue;

    lowest = 100;
    highest = 0;

    for (int i = 0; i < Period; i++)
    {
    double rsiValue = RSI(Period_RSI,1)[i];

    if (rsiValue < lowest)
    {
    lowest = rsiValue;
    }
    if (rsiValue > highest)
    {
    highest = rsiValue;
    }
    }

    lowestRSI[0] = lowest;
    highestRSI[0] = highest;
    }

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

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

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

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

    }
    }

    region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private RSIExtremes1[] cacheRSIExtremes1;
    public RSIExtremes1 RSIExtremes1(int period, int period_RSI)
    {
    return RSIExtremes1(Input, period, period_RSI);
    }

    public RSIExtremes1 RSIExtremes1(ISeries<double> input, int period, int period_RSI)
    {
    if (cacheRSIExtremes1 != null)
    for (int idx = 0; idx < cacheRSIExtremes1.Length; idx++)
    if (cacheRSIExtremes1[idx] != null && cacheRSIExtremes1[idx].Period == period && cacheRSIExtremes1[idx].Period_RSI == period_RSI && cacheRSIExtremes1[idx].EqualsInput(input))
    return cacheRSIExtremes1[idx];
    return CacheIndicator<RSIExtremes1>(new RSIExtremes1(){ Period = period, Period_RSI = period_RSI }, input, ref cacheRSIExtremes1);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.RSIExtremes1 RSIExtremes1(int period, int period_RSI)
    {
    return indicator.RSIExtremes1(Input, period, period_RSI);
    }

    public Indicators.RSIExtremes1 RSIExtremes1(ISeries<double> input , int period, int period_RSI)
    {
    return indicator.RSIExtremes1(input, period, period_RSI);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.RSIExtremes1 RSIExtremes1(int period, int period_RSI)
    {
    return indicator.RSIExtremes1(Input, period, period_RSI);
    }

    public Indicators.RSIExtremes1 RSIExtremes1(ISeries<double> input , int period, int period_RSI)
    {
    return indicator.RSIExtremes1(input, period, period_RSI);
    }
    }
    }

    #endregion

    #2
    Hello BlackMaps,

    Thanks for your post and welcome to the NinjaTrade Forums!

    In the code you shared I do not see where you are assigning a value to the plots. For plots to appear on the chart window you would need to assign a value to each plot in the script.

    The name of the plots in the AddPlot() method is "Lowest" and "Highest".

    In the Properties section of code you shared you are using the lowercase "lowest" and "highest". You should change the public Series properties of the plots to use the correct names "Lowest" and "Highest".

    Also, both public Series for the plots are set to Values[0]. The "Highest" public Series property should be changed to Values[1] so it is not the same as the "Lowest" property

    For example:

    Code:
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Lowest
    {
    get { return Values[0]; }
    }
    
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Highest
    {
    get { return Values[1]; }
    }
    ​To assign a value to the first plot you would call Values[0][0] = X, where X is the value you want to assign to the plot.

    To assign a value to the second plot you would call Values[1][0] = X, where X is the value you want to assign to the plot

    Please see the help guide documentation below for more information and sample code.

    AddPlot(): https://ninjatrader.com/support/help...t8/addplot.htm
    Values: https://ninjatrader.com/support/help...nt8/values.htm
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rhyminkevin, Today, 04:58 PM
    3 responses
    48 views
    0 likes
    Last Post Anfedport  
    Started by iceman2018, Today, 05:07 PM
    0 responses
    5 views
    0 likes
    Last Post iceman2018  
    Started by lightsun47, Today, 03:51 PM
    0 responses
    7 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    14 views
    0 likes
    Last Post 00nevest  
    Started by futtrader, 04-21-2024, 01:50 AM
    4 responses
    50 views
    0 likes
    Last Post futtrader  
    Working...
    X