Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator loses settings upon restart

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

    Indicator loses settings upon restart

    Hello everyone

    I have an indicator that loses settings each time I chose down NT8

    Is there a way to fix this

    I save workspaces every time I close too

    Thankyou in advance

    #2
    Hello NISNOS69,

    Thank you for your post.

    The most common reason is improperly serialized public objects. Make sure any public inputs properly implement XmlIgnore().



    http://www.ninjatrader.com/support/f...t.php?p=124724

    Are you seeing any errors appear in the Log tab of the Control Center when attempting to save the template or workspace?​
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      im unsure as its not an indicator thst i have made.

      Can i drop the code here and you look over it?

      Comment


        #4
        There were no errors in the log tab

        Comment


          #5
          If you would like to fix the errors yourself, you can share the code. We can't fix the errors for you, however. I would recommend reaching out to the developer if you are not able to fix the code errors yourself.
          Gaby V.NinjaTrader Customer Service

          Comment


            #6
            thankyou ..

            here it is


            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.eFe
            {
            public class vHL : Indicator
            {

            private double highestHigh;
            private double lowestLow;
            private double validationPrice;
            private List<int> swingHighs { get; set; }
            private List<int> bullishHighs { get; set; }
            private List<int> swingLows { get; set; }
            private List<int> bearishLows { get; set; }
            private List<int> validHighs { get; set; }
            private List<int> validLows { get; set; }

            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            Description = "Valid High Low with Validation Line";
            Name = "vHL";
            Calculate = Calculate.OnBarClose;
            IsOverlay = true;
            DisplayInDataBox = true;
            DrawOnPricePanel = true;
            DrawHorizontalGridLines = true;
            DrawVerticalGridLines = true;
            PaintPriceMarkers = true;
            ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
            IsSuspendedWhileInactive = true;

            this.ValidHighColor = Brushes.Green;
            this.ValidLowColor = Brushes.Red;
            this.MarkSwingPeaks = false;
            this.PrintCandleIndices = false;
            this.DebugMode = false;
            this.ShowSwings = true;
            this.ShowFractals = true;

            this.ValidLineWidth = 2;
            this.ValidLineColor = Brushes.Blue;
            this.ShowValidationLine = true;
            }
            else if (State == State.Configure)
            {
            this.swingHighs = new List<int>();
            this.swingLows = new List<int>();
            this.bullishHighs = new List<int>();
            this.bearishLows = new List<int>();
            this.validHighs = new List<int>();
            this.validLows = new List<int>();
            }
            }

            Comment


              #7
              protected override void OnBarUpdate()
              {
              if (CurrentBar == 1)
              this.Initialize(CurrentBar);
              if (CurrentBar < 3)
              return;

              this.MarkBarIndex();
              this.ValidateHighs(CurrentBar);
              this.ValidateLows(CurrentBar);
              this.UpdateHighs(CurrentBar);
              this.UpdateLows(CurrentBar);
              if (ShowValidationLine)
              UpdateValidationLine(CurrentBar, validationPrice);
              }

              private void Initialize(int barIndex)
              {
              this.validLows.Add(barIndex);
              Draw.TriangleUp(this, "NewBearishLow" + barIndex.ToString(), true, CurrentBar - barIndex, Low.GetValueAt(barIndex) - 0.3, Brushes.Orange);
              }

              private void MarkBarIndex()
              {
              if (!this.PrintCandleIndices)
              return;
              if (CurrentBar % 5 == 0)
              Draw.Text(this, "bar" + CurrentBar.ToString(), string.Format("{0}", CurrentBar), 0, High[0] + 2.0, Brushes.DimGray);
              Print("--------------------");
              Print(string.Format("Bar {0} out of {1}", CurrentBar, Bars.Count));
              }

              private void UpdateValidationLine(int barIndex, double price)
              {
              if(this.DebugMode) Print(string.Format("Updating Validation Line @ Bar {0} Price {1}", barIndex, price));

              if (DrawObjects["validationLine"] != null && DrawObjects["validationLine"] is DrawingTools.Line)
              {
              var x = DrawObjects["validationLine"] as NinjaTrader.NinjaScript.DrawingTools.Line;
              if(x.EndAnchor.Price != price)
              {
              if(this.DebugMode) Print(string.Format("Diff Price - Validation Line @ Bar {0} Price {1} - CurrentBar {2}", barIndex, price, CurrentBar));
              // Draw.Line(this, "validationLine", false, 0, price, barIndex, price, Brushes.Blue, DashStyleHelper.Solid, 2);
              // x.StartAnchor.BarsAgo = 0;
              // x.StartAnchor.SlotIndex = barIndex;
              // x.StartAnchor.Price = price;
              // x.EndAnchor.BarsAgo = 0;
              // x.EndAnchor.SlotIndex = barIndex;
              // x.EndAnchor.Price = price;
              Draw.Ray(this, "validationLine", false, 1, price, 0, price, ValidLineColor, DashStyleHelper.Solid, ValidLineWidth);
              }
              else
              {
              x.EndAnchor.BarsAgo = 0;
              x.EndAnchor.SlotIndex = barIndex;
              x.EndAnchor.Price = price;
              }
              }
              else
              {
              if(this.DebugMode) Print(string.Format("New Line - Validation Line @ Bar {0} Price {1} - CurrentBar {2}", barIndex, price, CurrentBar));
              // Draw.Line(this, "validationLine", false, 0, price, barIndex, price, ValidLineColor, DashStyleHelper.Solid, ValidLineWidth);
              Draw.Ray(this, "validationLine", false, 0, price, barIndex, price, ValidLineColor, DashStyleHelper.Solid, ValidLineWidth);
              }
              }

              private void UpdateHighs(int barIndex)
              {
              if(this.DebugMode) Print("Updating highs");
              double valueAt1 = High.GetValueAt(barIndex);
              double valueAt2 = Close.GetValueAt(barIndex);
              if (!this.IsBullishCandle(barIndex))
              return;
              if(this.DebugMode) Print(string.Format("Candle @{0} is a bullish candle.", barIndex));
              if (valueAt2 <= this.highestHigh)
              return;
              if(this.DebugMode) Print(string.Format("Candle @{0} put in a new high of {1} above previous highs of {2}.", barIndex, valueAt1, this.highestHigh));
              this.highestHigh = valueAt1;
              this.bullishHighs.Add(barIndex);
              this.validationPrice = Low.GetValueAt(barIndex);
              }

              private void UpdateLows(int barIndex)
              {
              if(this.DebugMode) Print("Updating lows");
              double valueAt1 = Low.GetValueAt(barIndex);
              double valueAt2 = Close.GetValueAt(barIndex);
              if (!this.IsBearishCandle(barIndex))
              return;
              if(this.DebugMode) Print(string.Format("Candle @{0} is a bearish candle.", barIndex));
              if (valueAt2 >= this.lowestLow)
              return;
              if(this.DebugMode) Print(string.Format("Candle @{0} put in a new low of {1} below previous lows of {2}.", barIndex, valueAt1, this.lowestLow));
              this.lowestLow = valueAt1;
              this.bearishLows.Add(barIndex);
              this.validationPrice = High.GetValueAt(barIndex);

              }

              private void ValidateHighs(int barIndex)
              {
              if(this.DebugMode) Print("Validating highs");
              if (!this.IsSearchingHigh())
              return;
              int startIndex = this.bullishHighs.LastOrDefault<int>();
              double valueAt = Low.GetValueAt(startIndex);
              if(this.DebugMode) Print(string.Format("Did we close below the low @{0} of the bullish candle that put in the high @{1}?", valueAt, startIndex));
              this.validationPrice = valueAt;
              if (Close.GetValueAt(barIndex) >= valueAt)
              {
              if(this.DebugMode) Print("No. continue.");
              }
              else
              {
              int num1 = this.LowestBarFromRange(startIndex, barIndex);
              this.bearishLows.Add(num1);
              this.validHighs.Add(startIndex);
              this.lowestLow = Low.GetValueAt(num1);
              if(this.DebugMode) Print(string.Format("Yes, validated high @{0}", startIndex));
              if(this.DebugMode) Print(string.Format("Resetting lowest low to {0}", this.lowestLow));
              int num2 = this.HighestBarFromRange(this.validLows.LastOrDefa ult<int>(), barIndex);
              int num3 = this.MarkSwingPeaks ? num2 : startIndex;
              this.swingHighs.Add(num3);
              if (this.ShowFractals)
              Draw.TriangleDown(this, "valid-high-" + barIndex.ToString(), true, CurrentBar - num3, High.GetValueAt(num3) + 0.3, this.ValidHighColor);
              if (!this.ShowSwings)
              return;
              Draw.Line(this, "swing-high-" + barIndex.ToString(), CurrentBar - num3, High.GetValueAt(num3), CurrentBar - this.swingLows.LastOrDefault<int>(), Low.GetValueAt(this.swingLows.LastOrDefault<int>() ), Brushes.DimGray);
              }
              }

              private void ValidateLows(int barIndex)
              {
              if(this.DebugMode) Print("Validating lows");
              if (!this.IsSearchingLow())
              return;
              int startIndex = this.bearishLows.LastOrDefault<int>();
              double valueAt = High.GetValueAt(startIndex);
              if(this.DebugMode) Print(string.Format("Did we close above the high @{0} of the bearish candle that put in the low @{1}?", valueAt, startIndex));
              this.validationPrice = valueAt;
              if (Close.GetValueAt(barIndex) <= valueAt)
              {
              if(this.DebugMode) Print("No. continue.");
              }
              else
              {
              int num1 = this.HighestBarFromRange(startIndex, barIndex);
              this.bullishHighs.Add(num1);
              this.validLows.Add(startIndex);
              this.highestHigh = High.GetValueAt(num1);
              if(this.DebugMode) Print(string.Format("Yes, validated low @{0}", startIndex));
              if(this.DebugMode) Print(string.Format("Resetting highest high to {0}", this.highestHigh));
              int num2 = this.LowestBarFromRange(this.validHighs.LastOrDefa ult<int>(), barIndex);
              int num3 = this.MarkSwingPeaks ? num2 : startIndex;
              this.swingLows.Add(num3);
              if (this.ShowFractals)
              Draw.TriangleUp(this, "valid-low-" + barIndex.ToString(), true, CurrentBar - num3, Low.GetValueAt(num3) - 0.3, this.ValidLowColor);
              if (!this.ShowSwings)
              return;
              Draw.Line(this, "swing-low-" + barIndex.ToString(), CurrentBar - num3, Low.GetValueAt(num3), CurrentBar - this.swingHighs.LastOrDefault<int>(), High.GetValueAt(this.swingHighs.LastOrDefault<int> ()), Brushes.DimGray);
              }
              }

              private int LowestBarFromRange(int startIndex, int endIndex)
              {
              double num1 = double.MaxValue;
              int num2 = 0;
              for (int index = startIndex; index <= endIndex; ++index)
              {
              if (Low.GetValueAt(index) < num1)
              {
              num1 = Low.GetValueAt(index);
              num2 = index;
              }
              }
              return num2;
              }

              private int HighestBarFromRange(int startIndex, int endIndex)
              {
              double num1 = double.MinValue;
              int num2 = 0;
              for (int index = startIndex; index <= endIndex; ++index)
              {
              if (High.GetValueAt(index) > num1)
              {
              num1 = High.GetValueAt(index);
              num2 = index;
              }
              }
              return num2;
              }

              private bool IsSearchingHigh()
              {
              if(this.DebugMode) Print("Are we searching for valid highs?");
              if (this.validLows.Count == 0 || this.validHighs.Count == 0)
              {
              if(this.DebugMode) Print("Yes valid lows or highs are 0.");
              return true;
              }
              if (this.validLows.LastOrDefault<int>() > this.validHighs.LastOrDefault<int>())
              {
              if(this.DebugMode) Print(("Yes the last one was a valid low @" + this.validLows.LastOrDefault<int>().ToString()));
              return true;
              }
              if(this.DebugMode) Print(("No. The last one was a valid high @" + this.validHighs.LastOrDefault<int>().ToString()));
              return false;
              }

              private bool IsSearchingLow()
              {
              if(this.DebugMode) Print("Are we searching for valid lows?");
              if (this.validLows.Count == 0 || this.validHighs.Count == 0)
              {
              if(this.DebugMode) Print("Yes valid lows or highs are 0.");
              return true;
              }
              if (this.validHighs.LastOrDefault<int>() > this.validLows.LastOrDefault<int>())
              {
              if(this.DebugMode) Print(("Yes the last one was a valid high @" + this.validHighs.LastOrDefault<int>().ToString()));
              return true;
              }
              if(this.DebugMode) Print(("No. The last one was a valid low @" + this.validLows.LastOrDefault<int>().ToString()));
              return false;
              }

              private bool IsBullishCandle(int barIndex)
              {
              return this.GetDirection(barIndex) == NinjaTrader.NinjaScript.Indicators.eFe.vHL.Directi on.Long;
              }

              private bool IsBearishCandle(int barIndex)
              {
              return this.GetDirection(barIndex) == NinjaTrader.NinjaScript.Indicators.eFe.vHL.Directi on.Short;
              }

              private NinjaTrader.NinjaScript.Indicators.eFe.vHL.Directi on GetDirection(int barIndex)
              {
              return Close.GetValueAt(barIndex) <= Open.GetValueAt(barIndex) ? NinjaTrader.NinjaScript.Indicators.eFe.vHL.Directi on.Short : NinjaTrader.NinjaScript.Indicators.eFe.vHL.Directi on.Long;
              }

              [XmlIgnore]
              [Display(Name = "Mark Swing High/Low", GroupName = "Options", Order = 1)]
              public bool MarkSwingPeaks { get; set; }

              [XmlIgnore]
              [Display(Name = "Print Candle Indices", GroupName = "Debug Options", Order = 20)]
              public bool PrintCandleIndices { get; set; }

              [XmlIgnore]
              [Display(Name = "Print Debug Output Messages", GroupName = "Debug Options", Order = 21)]
              public bool DebugMode { get; set; }

              [XmlIgnore]
              [Display(Name = "Valid Highs", GroupName = "Display", Order = 1)]
              public Brush ValidHighColor { get; set; }

              [XmlIgnore]
              [Display(Name = "Valid Lows", GroupName = "Display", Order = 2)]
              public Brush ValidLowColor { get; set; }

              [XmlIgnore]
              [Display(Name = "Show Swings", GroupName = "Display", Order = 3)]
              public bool ShowSwings { get; set; }

              [XmlIgnore]
              [Display(Name = "Show Fractals", GroupName = "Display", Order = 4)]
              public bool ShowFractals { get; set; }

              [XmlIgnore]
              [Display(Name = "Show Validation Line", GroupName = "Display", Order = 5)]
              public bool ShowValidationLine { get; set; }

              [XmlIgnore]
              [Display(Name = "Validation Line width", GroupName = "Display", Order = 5)]
              public int ValidLineWidth { get; set; }

              [XmlIgnore]
              [Display(Name = "Validation Line", GroupName = "Display", Order = 6)]
              public Brush ValidLineColor { get; set; }

              private enum Direction
              {
              Long,
              Short,
              }
              }
              }

              Comment


                #8
                region NinjaScript generated code. Neither change nor remove.

                namespace NinjaTrader.NinjaScript.Indicators
                {
                public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
                {
                private eFe.vHL[] cachevHL;
                public eFe.vHL vHL()
                {
                return vHL(Input);
                }

                public eFe.vHL vHL(ISeries<double> input)
                {
                if (cachevHL != null)
                for (int idx = 0; idx < cachevHL.Length; idx++)
                if (cachevHL[idx] != null && cachevHL[idx].EqualsInput(input))
                return cachevHL[idx];
                return CacheIndicator<eFe.vHL>(new eFe.vHL(), input, ref cachevHL);
                }
                }
                }

                namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
                {
                public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
                {
                public Indicators.eFe.vHL vHL()
                {
                return indicator.vHL(Input);
                }

                public Indicators.eFe.vHL vHL(ISeries<double> input )
                {
                return indicator.vHL(input);
                }
                }
                }

                namespace NinjaTrader.NinjaScript.Strategies
                {
                public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
                {
                public Indicators.eFe.vHL vHL()
                {
                return indicator.vHL(Input);
                }

                public Indicators.eFe.vHL vHL(ISeries<double> input )
                {
                return indicator.vHL(input);
                }
                }
                }

                #endregion​

                Comment


                  #9
                  Hello,

                  Can you please post the .zip file of the code.

                  To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
                  1. Click Tools -> Export -> NinjaScript Add-on...
                  2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
                  3. Click the 'Export' button
                  4. Enter a unique name for the file in the value for 'File name:'
                  5. Choose a save location -> click Save
                  6. Click OK to clear the export location message
                  By default your exported file will be in the following location:
                  • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
                  Below is a link to the help guide on Exporting NinjaScripts.


                  Once exported, please attach the file as an attachment to your reply.

                  I look forward to receiving the export.​
                  Gaby V.NinjaTrader Customer Service

                  Comment


                    #10
                    Certainly



                    thankyou

                    VLH FOR CHECKING.zip

                    Comment


                      #11
                      Hello,

                      The code to serialize the brush inputs is missing. Serialization is necessary to save the settings.

                      Please see this Help Guide page which goes over how to serialize brush inputs.

                      Gaby V.NinjaTrader Customer Service

                      Comment


                        #12
                        thankyou... but im new to this.
                        is there a way you could insert it into the zip for me please so the colours & properties i set are saved.

                        thankyou

                        Comment


                          #13
                          Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one on one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.


                          That said, through email or on the forum we are happy to answer any questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.


                          You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services.


                          Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.​
                          Gaby V.NinjaTrader Customer Service

                          Comment


                            #14
                            ok thankyou

                            so canyou show me the code i need to add and then i can add it myself to the file - is that possible?

                            Comment


                              #15
                              You need to serialize the brushes as shown in this Help Guide page:



                              For example, for the ValidHighBrush:

                              [XmlIgnore]
                              [Display(Name = "Valid Highs", GroupName = "Display", Order = 1)]
                              public Brush ValidHighColor { get; set; }​

                              [Browsable(false)]
                              public string ValidHighColorSerialize
                              {
                              get { return Serialize.BrushToString(ValidHighColor); }
                              set { ValidHighColor = Serialize.StringToBrush(value); }
                              }

                              You need to do the same for all brushes in the script. ​
                              Gaby V.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jeb1000, Yesterday, 02:36 PM
                              5 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by birdog, Yesterday, 06:25 AM
                              4 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by owen5819, Today, 09:48 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by owen5819, Today, 09:35 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by gyilaoliver, Today, 07:25 AM
                              1 response
                              17 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X