Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can't make the AddPlot function to work

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

    Can't make the AddPlot function to work

    Hello There, I am trying to create a strategy that has 3 indicators and output of Indicator 1 is input to indicators 2 & 3. I also want to plot these indicators on the chart in a panel below the main chart panel. I've read the documentation and other similar questions on the forum, but I can't make this to work. Following is the code that I've come up with so far :-



    Code:
    using NinjaTrader.Cbi;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.NinjaScript.Strategies;
    using System;
    using System.CodeDom.Compiler;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using NinjaTrader.NinjaScript.Indicators;
    using System.Threading.Tasks;
    using System.Windows.Media;
    using System.ComponentModel;
    using System.Xml.Serialization;
    using NinjaTrader.Gui;
    
    namespace NinjaTrader.Custom.Strategies.Udemy
    {
    internal class SampleStrat : Strategy
    {
    private const int rsi_period = 9;
    private const int vwma_period = 21;
    private const int ema_period = 3;
    
    private Indicator _rsi;
    private Indicator _vwma;
    private Indicator _ema;
    
    [NinjaScriptProperty]
    [Display(Name = "Trace My Orders", GroupName = "Parameters", Order = 3)]
    public bool TraceMyOrders { get; set; }
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    SetDefaults();
    SetParameters();
    }
    else if (State == State.Configure)
    {
    ClearOutputWindow();
    TraceOrders = TraceMyOrders;
    CreateIndicators();
    }
    else if (State == State.Terminated)
    {
    
    }
    }
    
    private void CreateIndicators()
    {
    _rsi = RSI(Close, rsi_period, 3);
    _vwma = VWMA(_rsi, vwma_period);
    _ema = EMA(_rsi, ema_period);
    }
    
    private void SetParameters()
    {
    TraceMyOrders = false;
    }
    
    private void SetDefaults()
    {
    Name = "SampleStrat";
    Calculate = Calculate.OnBarClose;
    TraceOrders = false;
    StartBehavior = StartBehavior.WaitUntilFlat;
    IsExitOnSessionCloseStrategy = false;
    BarsRequiredToTrade = 65;
    BarsRequiredToPlot = 65;
    IsOverlay = false;
    
    AddPlot(new Stroke(Brushes.White), PlotStyle.Line, "rsiPlot");
    AddPlot(new Stroke(Brushes.Red), PlotStyle.Line, "vwmaPlot");
    //AddPlot(new Stroke(Brushes.Blue, DashStyleHelper.Solid, 25, 150), PlotStyle.Line, "ema");
    }
    
    protected override void OnBarUpdate()
    {
    rsiPlot[0] = RSI(Close, rsi_period, 3)[0];
    vwmaPlot[0] = VWMA((RSI(Close, rsi_period, 3)), vwma_period)[0];
    //ema[0] = 3;
    }
    
    [HASHTAG="t3322"]region[/HASHTAG] Properties
    
    //Properties
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> rsiPlot
    {
    get { return Values[0]; }
    }
    
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> vwmaPlot
    {
    get { return Values[0]; }
    }
    
    #endregion
    }
    }​

    #2
    Hello xs2abhishek,

    One problem is that both of your public properties reference Values[0], each public property needs to use the index for the plot you want it to target. [0] is the first plot and [1] would be the second plot.

    If you are not seeing any value plotted you may need to add a Print into OnBarUpdate to output the values you are trying to plot to see what they are.

    Additionally if you have added the AddPlot statements you will also need to re apply the strategy after doing that. remove it from the chart and then re apply it.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    89 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    135 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X