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

Can't find what is causing an error when saving to Workspace (error reflecting type)

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

    Can't find what is causing an error when saving to Workspace (error reflecting type)

    Hi,

    Even after dealing with such an error in the past, I can't figure out what is causing the error now. Every properties seems to be defaulted and only the brushes are serialized,

    I get the error:
    Default,Could not save indicator 'BWMarketStructure:' There was an error reflecting type 'NinjaTrader.NinjaScript.Indicators.BW4U.BWMarketS tructure'
    When saving or Save as the indicator to a Workspace.

    Code:
    #region #### OnStateChange ####
    protected override void OnStateChange()
    {
    base.OnStateChange();
    switch (State)
    {
    #region State.SetDefault
    case State.SetDefaults:
    Description = @"BWMarketStructure";
    Name = "BWMarketStructure";
    Calculate = Calculate.OnBarClose;
    // NT8 Standard
    MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
    DrawOnPricePanel = true;
    IsOverlay = true;
    DisplayInDataBox = true;
    IsSuspendedWhileInactive = true;
    PaintPriceMarkers = false;
    // PropertiesDefaults
    PropertiesDefaults();
    break;
    #endregion
    
    #region #### Properties ####
    private void PropertiesDefaults()
    {
    #region #< Structure Setup >#
    MaxLookbackObjects = 128;
    HTFTypeAsSTF = true;
    HTFBarType = BarsPeriodType.Minute;
    HTFValue = 15;
    HTFValue2 = 11;
    HTFBaseBarsPeriodValue = 30;
    BiasLength = 3;
    #endregion
    
    #region #< Swing Setup Params >#
    SwingStrength = 4;
    UseHighLowSwings = true;
    #endregion
    
    #region #< Swing Visual >#
    ShowSwingLegs = true;
    ShowSwingLabels = true;
    SwingsUpStroke = new Stroke(Brushes.RoyalBlue,DashStyleHelper.Solid,2);
    SwingsDownStroke = new Stroke(Brushes.Red,DashStyleHelper.Solid,2);
    #endregion
    
    #region #< Signals Visual >#
    SignalLongBrush = Brushes.Green;
    SignalShortBrush = Brushes.Red;
    #if DEBUG
    ShowSignalLabel = true;
    #endif
    ShowPriceSignalMark = true;
    PriceSignalBrush = Brushes.Yellow;
    ShowSetup = true;
    SetupLongBrush = Brushes.Aqua;
    SetupShortBrush = Brushes.Gold;
    SetupNaturalBrush = Brushes.White;
    #endregion
    }
    
    #region ##<< Input Params >>##
    #region #< Structure Setup >#
    [NinjaScriptProperty, Range(10, int.MaxValue)]
    [Display(Name = "Max Lookback Objects", Description = "Max Lookback objects. The system will automaticly remove all unused historical swings over this number", GroupName = "Structure Setup", Order = 2)]
    public int MaxLookbackObjects { get; set; }
    
    [NinjaScriptProperty]
    [RefreshProperties(RefreshProperties.All)] // Needed to refresh the property grid when the value changes
    [Display(Name = "HTF BarType like STF", Description = "Higher Timeframe BarType similar to STF", GroupName = "Structure Setup", Order = 6)]
    public bool HTFTypeAsSTF { get; set; }
    
    [NinjaScriptProperty]
    [Display(Name = "HTF BarType", Description = "Higher Timeframe BarType", GroupName = "Structure Setup", Order = 8)]
    public BarsPeriodType HTFBarType { get; set; }
    
    [NinjaScriptProperty, Range(1, int.MaxValue)]
    [Display(Name = "HTF Period Value", Description = "Higher Timeframe Period Value", GroupName = "Structure Setup", Order = 10)]
    public int HTFValue { get; set; }
    
    [NinjaScriptProperty, Range(1, int.MaxValue)]
    [Display(Name = "HTF Value2(Offset)", Description = "Higher Timeframe Period Value2 (Offset...)", GroupName = "Structure Setup", Order = 12)]
    public int HTFValue2 { get; set; }
    
    [NinjaScriptProperty, Range(1, int.MaxValue)]
    [Display(Name = "HTF BBPValue(Reversal)", Description = "Higher Timeframe Base Bars Period Value (Reversal...)", GroupName = "Structure Setup", Order = 14)]
    public int HTFBaseBarsPeriodValue { get; set; }
    
    [NinjaScriptProperty, Range(2, 50)]
    [Display(Name = "Bias Length", Description = "Bias Length", GroupName = "Structure Setup", Order = 22)]
    public int BiasLength { get; set; }
    #endregion
    
    #region #< Swing Setup Params >#
    [NinjaScriptProperty, Range(1, int.MaxValue)]
    [Display(Name = "Swing Strength", Description = "Strength of the Swings. Highier values will reduce noise", GroupName = "Swing Setup", Order = 4)]
    public int SwingStrength { get; set; }
    
    [NinjaScriptProperty]
    [Display(Name = "Use High/Low Swings", Description = "Base the Swings on the High/Low values. Otherwise the Open and Close are used", GroupName = "Swing Setup", Order = 6)]
    public bool UseHighLowSwings { get; set; }
    #endregion
    
    #region #< Swing Visual >#
    [RefreshProperties(RefreshProperties.All)] // Needed to refresh the property grid when the value changes
    [Display(Name = "Show Swing Legs", Description = "Display the Swing Structure", GroupName = "Swing Visual", Order = 2)]
    public bool ShowSwingLegs { get; set; }
    
    [RefreshProperties(RefreshProperties.All)] // Needed to refresh the property grid when the value changes
    [Display(Name = "Show Swing Labels", Description = "Display the Swing Labels", GroupName = "Swing Visual", Order = 4)]
    public bool ShowSwingLabels { get; set; }
    
    [Display(Name = "Swings Up Line", Description = "The Swings Leg UP stroke (color,shape,color)", GroupName = "Swing Visual", Order = 6)]
    public Stroke SwingsUpStroke { get; set; }
    
    [Display(Name = "Swings Down Line", Description = "The Swings Leg DONE stroke (color,shape,color)", GroupName = "Swing Visual", Order = 8)]
    public Stroke SwingsDownStroke { get; set; }
    #endregion
    
    #region #< Signals Visual >#
    [XmlIgnore()]
    [Display(Name = "Long Signal Color", Description = "Long Signal and Zones Color", GroupName = "Signals Visual", Order = 2)]
    public Brush SignalLongBrush { get; set; }
    
    [XmlIgnore()]
    [Display(Name = "Short Signal Color", Description = "Short Signal and Zones Color", GroupName = "Signals Visual", Order = 4)]
    public Brush SignalShortBrush { get; set; }
    
    #if DEBUG
    [RefreshProperties(RefreshProperties.All)] // Needed to refresh the property grid when the value changes
    [Display(Name = "Show Signal Label", Description = "Show Signal Label", GroupName = "Signals Visual", Order = 20)]
    public bool ShowSignalLabel { get; set; }
    #endif
    
    [RefreshProperties(RefreshProperties.All)] // Needed to refresh the property grid when the value changes
    [Display(Name = "Show Signal Entry Price Mark", Description = "Show Signal Entry Price Mark", GroupName = "Signals Visual", Order = 22)]
    public bool ShowPriceSignalMark { get; set; }
    
    [XmlIgnore()]
    [Display(Name = "Price Mark Color", Description = "Price Mark Color", GroupName = "Signals Visual", Order = 26)]
    public Brush PriceSignalBrush { get; set; }
    
    [RefreshProperties(RefreshProperties.All)] // Needed to refresh the property grid when the value changes
    [Display(Name = "Show Setup Markers", Description = "Show Setup Markers", GroupName = "Signals Visual", Order = 40)]
    public bool ShowSetup { get; set; }
    
    [XmlIgnore()]
    [Display(Name = "Setup Long Color", Description = "Setup Long Color", GroupName = "Signals Visual", Order = 42)]
    public Brush SetupLongBrush { get; set; }
    
    [XmlIgnore()]
    [Display(Name = "Setup Short Color", Description = "Setup Short Color", GroupName = "Signals Visual", Order = 44)]
    public Brush SetupShortBrush { get; set; }
    
    [XmlIgnore()]
    [Display(Name = "Setup Nutural Color", Description = "Setup Nutural Color", GroupName = "Signals Visual", Order = 46)]
    public Brush SetupNaturalBrush { get; set; }
    
    #endregion
    
    #region #< Serialize >#
    // Serialize our Color object
    
    [Browsable(false)]
    public string SignalLongBrushSerialize
    {
    get { return Serialize.BrushToString(SignalLongBrush); }
    set { SignalLongBrush = Serialize.StringToBrush(value); }
    }
    
    [Browsable(false)]
    public string SignalShortBrushSerialize
    {
    get { return Serialize.BrushToString(SignalShortBrush); }
    set { SignalShortBrush = Serialize.StringToBrush(value); }
    }
    
    [Browsable(false)]
    public string PriceSignalMarkBrushSerialize
    {
    get { return Serialize.BrushToString(PriceSignalBrush); }
    set { PriceSignalBrush = Serialize.StringToBrush(value); }
    }
    
    [Browsable(false)]
    public string SetupLongBrushSerialize
    {
    get { return Serialize.BrushToString(SetupLongBrush); }
    set { SetupLongBrush = Serialize.StringToBrush(value); }
    }
    
    [Browsable(false)]
    public string SetupShortBrushSerialize
    {
    get { return Serialize.BrushToString(SetupShortBrush); }
    set { SetupShortBrush = Serialize.StringToBrush(value); }
    }
    
    [Browsable(false)]
    public string SetupNaturalBrushSerialize
    {
    get { return Serialize.BrushToString(SetupNaturalBrush); }
    set { SetupNaturalBrush = Serialize.StringToBrush(value); }
    }
    
    #endregion
    
    #endregion
    
    #region ##<< Output Params >>##
    #if DEBUG
    [Browsable(false)][XmlIgnore()] public Series<double> CurBar0 { get { return Values[plotCurBar0]; } }
    [Browsable(false)][XmlIgnore()] public Series<double> CurBar1 { get { return Values[plotCurBar1]; } }
    #endif
    [Browsable(false)][XmlIgnore()] public Series<double> SwingPoints0 { get { return Values[plotSwings0]; } }
    [Browsable(false)][XmlIgnore()] public Series<double> SwingLen0 { get { return Values[plotSwingLen0]; } }
    [Browsable(false)][XmlIgnore()] public Series<double> Bias0 { get { return Values[plotBias0]; } }
    [Browsable(false)][XmlIgnore()] public Series<double> SwingPoints1 { get { return Values[plotSwings1]; } }
    [Browsable(false)][XmlIgnore()] public Series<double> SwingLen1 { get { return Values[plotSwingLen1]; } }
    [Browsable(false)][XmlIgnore()] public Series<double> Bias1 { get { return Values[plotBias1]; } }
    #endregion
    
    #endregion
    
    
    //...****
    
    #region #### enums ####
    public enum SwingPointType {LL,LH,HH,HL,NA, }
    public enum MomentumType {None,AroonOscillator,CCI,ROC,RSI,Stochastics,MACD ,MFI,}
    public enum MovingAverageType {None,DEMA,EMA,HMA,SMA,TMA,VOLMA,WMA,}
    public enum BarCheckType {OnHold, Continue, NewSwing, Recalc}
    public enum Relation {Greater,GreaterEq,Eq,Lesser,LesserEq,NotEq,CrossA bove,CrossBelow,ValueIs,InRange, }
    #endregion

    #2
    Hello Shai Samuel,

    Thank you for your reply.

    The above isn't compilable - I'm seeing a number of compile errors when trying to add the above logic to a blank script. Could you provide a reduced, compilable example? Since we're really just looking at property issues, any code in OnBarUpdate may be omitted.

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate, thank you for your kind reply.

      Following your request, I did create a new Indicator and transfer to it the OnStateChange() with everything I have in it. The only difference is I have nothing in OnBarUpdate(), nor in OnRender().

      Eventually I found the issue. It was one of the indicator variables, that was declared as public. Once it was switch to private, the error disappeared. Another lesson learned.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by helpwanted, Today, 03:06 AM
      1 response
      11 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      9 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      5 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      242 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      387 views
      1 like
      Last Post Gavini
      by Gavini
       
      Working...
      X