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

Market Open Price Line

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

    Market Open Price Line

    I'm new to coding and Ive been using ChatGPT to help me fix the errors in this code but I think we are both stumped.
    I am trying to code a indicator that will plot and show the value of the opening price for the day. Here is what I got but I'm getting the error that System.Window.Media.Color does not contain a definition for blue. I'm getting the same error message for Solid in the dashStyles. Thanks for the help

    Here is what I have...

    using System;
    using System.Linq;
    using System.Drawing;
    using System.Windows.Media;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class OpeningPriceLine : Indicator
    {
    private double openingPrice;
    private Brush lineColor = Brushes.Blue;
    private DashStyle lineStyle = DashStyle.Solid;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Draws a horizontal line at the opening price of the 8:30am CST bar.";
    Name = "OpeningPriceLine";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    }
    }

    protected override void OnBarUpdate()
    {
    if (Time[0].TimeOfDay == new TimeSpan(8, 30, 0))
    {
    openingPrice = Open[0];
    }

    Draw.Line(this, "Opening Price Line", false, 0, openingPrice, -1, openingPrice, Color.Blue, DashStyle.Solid, 2);
    }
    }
    }


    #2
    A lot of things have changed between NT7 and NT8.

    The cause of your error is the use of Color.Blue, try using
    Brushes.Blue instead.

    In addition, use of DashStyle.Solid is also an error for NT8,
    use DashStyleHelper.Solid instead.

    -=o=-

    Why not just use CurrentDayOHL indicator provided by NinjaTrader?

    It has features to show the current Open of the session only,
    effectively ignoring the current session High and Low.

    Have you tried it?

    If you want to study how the code, the source code is open and
    available ...

    Goto folder 'Documents\NinjaTrader 8\bin\Custom\Indicators', and
    edit file '@CurrentDayOHL.cs'.

    Or just look at the code using the NinjaScript Editor.

    Comment


      #3
      Ah okay thanks for that.

      I have no idea why I wouldn't use the CurrentDayOHL indicator. Didn't even cross my mind lol
      I was deep in a coding rabbit hole when I had the idea and was like this should be easy enough to code lol

      Thanks for your wisdom

      Comment


        #4
        Hello ROZELA99,

        Thanks for your post.

        bltdavid is correct. You could get the current Open price of the session using the CurrentDayOHL indicator that comes default with NinjaTrader.

        This help guide page details how to access the Open price from this indicator: https://ninjatrader.com/support/help...nt_day_ohl.htm

        "System.Window.Media.Color does not contain a definition for blue."

        As bltdavid mentioned, NinjaTrader 8 uses Brushes instead of Color seen in NinjaTrader 7. Brushes.Blue should be used instead of Color.Blue to resolve this error.

        "I'm getting the same error message for Solid in the dashStyles."

        You could change your script to use DashStyleHelper.Solid instead of DashStyle.Solid to resolve this error.

        Draw.Line(NinjaScriptBase owner, string tag, bool isAutoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush, DashStyleHelper dashStyle, int width)

        See this help guide page about Draw.Line and it's available syntax properties in NinjaTrader 8: https://ninjatrader.com/support/help.../draw_line.htm

        Below I am including a link to a list of the code-breaking changes from NinjaTrader 7 to NinjaTrader 8. Thiis help guide will be the best way to see how things have changed from NinjaTrader 7 to NinjaTrader 8.

        http://ninjatrader.com/support/helpG...ng_changes.htm

        Let me know if I may assist further.​
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, Yesterday, 06:40 PM
        2 responses
        19 views
        0 likes
        Last Post algospoke  
        Started by ghoul, Today, 06:02 PM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        45 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        20 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        181 views
        0 likes
        Last Post jeronymite  
        Working...
        X