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

persistence of custom brush colors / settings

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

    persistence of custom brush colors / settings

    Hi, I'm trying to get custom brush colors (set from the indicator settings) to persist when the NinjaScript reloads. This appears to impact Templates as well.

    For example, the default color is Blue, but I add an indicator and change the color to Red. When I save as a template, and then load the template elsewhere, the color reverts to blue.

    Here some sample code that draws a simple line at certain times. Bolded parts are the likely important lines. Can someone help me here or point to some documentation which would lead me in the right direction? Thanks.



    region Using declarations
    using NinjaTrader.Data;
    using NinjaTrader.Gui;
    using SharpDX.Direct2D1;
    using System;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Windows.Media;
    using System.Xml.Serialization;
    #endregion

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

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"PriceDraw";
    Name = "PriceDraw";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    PaintPriceMarkers = true;
    IsSuspendedWhileInactive = true;

    MyBrush = Brushes.Blue;


    }
    else if (State == State.Configure)
    {
    AddPlot(new Stroke(MyBrush, DashStyleHelper.Solid, 1), PlotStyle.Dot, "D_draw");
    AddDataSeries(BarsPeriodType.Minute, 1);
    }
    }

    private double _plotValue = 0;

    protected override void OnBarUpdate()
    {

    if (CurrentBars[1] < 1000)
    { return; }

    if (BarsPeriod.BarsPeriodType == BarsPeriodType.Minute && BarsPeriod.Value == 1) //Only look at 1Min bars regardless of chart
    {
    int BarMinute = Time[0].Minute;
    int BarHour = Time[0].Hour;
    int BarDay = Time[0].Day;
    int BarMonth = Time[0].Month;
    int BarYear = Time[0].Year;
    int open = CurrentBar - Bars.GetBar(new DateTime(BarYear, BarMonth, BarDay, PlotHour, 0, 0)); //Open Time example 800 cst

    // check to see if matches
    if (PlotHour == BarHour & PlotMinute == BarMinute)
    {
    _plotValue = Closes[1][0];
    Print("Plotvalue: " + BarDay.ToString() + " day & value: " + _plotValue.ToString());

    }

    if(_plotValue > 0)
    {
    Values[0][0] = _plotValue;
    }

    }

    }


    region Properties

    [Range(0, int.MaxValue)]
    [NinjaScriptProperty]
    [Display(Name = "EventHour", Description = "Hour of Event", Order = 1, GroupName = "Parameters")]
    public int PlotHour
    { get; set; }

    [Range(0, int.MaxValue)]
    [NinjaScriptProperty]
    [Display(Name = "EventMinute", Description = "Minute of Event", Order = 2, GroupName = "Parameters")]
    public int PlotMinute
    { get; set; }




    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public double TheOpen
    {
    get; set;
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public double o
    {
    get; set;
    }
    [XmlIgnore]
    [Display(Name = "MyBrush", Description = "Color of the Event Marker", Order = 1, GroupName = "Parameters")]
    public System.Windows.Media.Brush MyBrush
    { get; set; }




    #endregion

    }

    #2
    Hello mohawkTrader,


    Thank you for your post.


    In order to properly serialize the Brush, you will need to add code to convert the public "MyBrush" to a string type which can then be processed by the serialization routines, meaning it can be saved and then loaded from a template.



    Code:
    [Browsable(false)]
    
    public string MyBrushSerialize
    
    {
    
    get { return Serialize.BrushToString(MyBrush); }
    
    set { MyBrush = Serialize.StringToBrush(value); }
    
    }


    Please see the following Help Guide page.


    Working with Brushes- Using brushes defined on the user interface





    Please let me know if you have any other questions.
    Last edited by NinjaTrader_Gaby; 09-28-2023, 11:53 AM.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Thank you. This is exactly the information needed.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jxs_xrj, 01-12-2020, 09:49 AM
      6 responses
      3,290 views
      1 like
      Last Post jgualdronc  
      Started by Touch-Ups, Today, 10:36 AM
      0 responses
      8 views
      0 likes
      Last Post Touch-Ups  
      Started by geddyisodin, 04-25-2024, 05:20 AM
      8 responses
      61 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by Option Whisperer, Today, 09:55 AM
      0 responses
      8 views
      0 likes
      Last Post Option Whisperer  
      Started by halgo_boulder, 04-20-2024, 08:44 AM
      2 responses
      24 views
      0 likes
      Last Post halgo_boulder  
      Working...
      X