Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to Plot Line in Strategy

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

    Trying to Plot Line in Strategy

    I have a multiple instrument Strategy that is supposed to plot a line on the price chart. I use a Strategy for this because I cannot add multiple instruments to an Indicator.

    This is the code for it which is compilable:

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Strategy;
    #endregion

    namespace NinjaTrader.Strategy
    {
    [Description("Plots the Value of the Dow 30 over the DJIA in real time.")]
    publicclass Dow30Price : Strategy
    {

    #region Variables
    private DateTime activeBar;
    private DateTime startTime;
    privatedouble SymbolClose;
    #endregion

    protectedoverridevoid Initialize()
    {
    CalculateOnBarClose = false;
    startTime = DateTime.Now;

    Add("AA", PeriodType.Tick, 1);
    Add("AXP", PeriodType.Tick, 1);
    Add("BA", PeriodType.Tick, 1);
    Add("BAC", PeriodType.Tick, 1);
    Add("C", PeriodType.Tick, 1);
    Add("CAT", PeriodType.Tick, 1);
    Add("CVX", PeriodType.Tick, 1);
    Add("DD", PeriodType.Tick, 1);
    Add("DIS", PeriodType.Tick, 1);
    Add("GE", PeriodType.Tick, 1);
    Add("GM", PeriodType.Tick, 1);
    Add("HD", PeriodType.Tick, 1);
    Add("HPQ", PeriodType.Tick, 1);
    Add("IBM", PeriodType.Tick, 1);
    Add("INTC", PeriodType.Tick, 1);
    Add("JNJ", PeriodType.Tick, 1);
    Add("JPM", PeriodType.Tick, 1);
    Add("KFT", PeriodType.Tick, 1);
    Add("KO", PeriodType.Tick, 1);
    Add("MCD", PeriodType.Tick, 1);
    Add("MMM", PeriodType.Tick, 1);
    Add("MRK", PeriodType.Tick, 1);
    Add("MSFT", PeriodType.Tick, 1);
    Add("PFE", PeriodType.Tick, 1);
    Add("PG", PeriodType.Tick, 1);
    Add("T", PeriodType.Tick, 1);
    Add("UTX", PeriodType.Tick, 1);
    Add("VZ", PeriodType.Tick, 1);
    Add("VZ", PeriodType.Tick, 1);
    Add("WMT", PeriodType.Tick, 1);
    Add("XOM", PeriodType.Tick, 1);

    StrategyPlot(0).Plots[0].Pen.Color = Color.DarkBlue;
    //StrategyPlot(0).Plots[0].PlotStyle = PlotStyle.Line;
    Add(StrategyPlot(0));
    StrategyPlot(0).PanelUI = 1;
    }

    protectedoverridevoid OnBarUpdate()
    {
    SymbolClose = 0;
    for(int SymbolNumber=1;SymbolNumber<31;SymbolNumber++)
    {
    //Print("SymbolNumber "+SymbolNumber+" Close "+Closes[SymbolNumber][0]);
    SymbolClose = SymbolClose + Closes[SymbolNumber][0];
    }
    SymbolClose = SymbolClose / 0.125552709;
    StrategyPlot(0).Value.Set(SymbolClose);
    }

    #region Properties
    #endregion
    }
    }


    Instead of drawing a line on the price chart, it draws a histogram. I've tried adding:

    StrategyPlot(0).Plots[0].PlotStyle = PlotStyle.Line;

    to the Initialize section (you'll see it commented out above), but when I try to compile it, it give me the following error message:

    The name 'PlotStyle' does not exist in the current context CS0103-click for info. I clicked for the info, but the help section doesn't seem to give me anything relevant.

    What am I doing wrong here?

    #2
    Not sure why you can't compile. It compiles fine on my end. Please ensure you are on NT6.5.1000.10.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I got it to work

      Here's what I did:

      I cut and paste the code into MS Notepad

      Deleted the old Strategy

      Created and new strategy

      put the old code and compiled it line-by-line

      And it works the way I want it to now....Don't ask me why.

      Thanks for your help.

      Yam Digger

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      630 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      565 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X