Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I cannot save an indicator in my template

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

    I cannot save an indicator in my template

    Hi there!

    I have a problem with an indicator, I can put it on my chart but when I save the template the next time I open NT8 the template does not have the indicator, so every time I open a chart I have to add this indicator.

    Code:
    #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.SSTEA M
    {
        public class EWO_SSTEAM3 : Indicator
        {
            private Series<double>  MP;
            private int             Lens;
            private double          Pr;
            private double          OscAG;
            public Series<double> UprLine;
            public Series<double> LwrLine;
                    public double mihl2;
            protected override void OnStateChange()
            {
                if (State == State.DataLoaded)
                {
                    // "this" refers to the NinjaScript object itself. T his syncs the Series object to historical data bar s
                    // MaximumBarsLookBack determines how many values th e Series<double> will have access to
                    MP      = new Series<double>(this,  MaximumBarsLookBack.Infinite);
                    //HL2     = float;
                    UprLine = new Series<double>(this) ;
                    LwrLine = new Series<double>(this) ;
                }
    
                if (State == State.SetDefaults)
                {
                    Description                                  = @"Elliot Wave Oscilator - SSTEAM";
                    Name                                         = "EWO3 - SSTEAM";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = false;
                    DisplayInDataBox                             = true;
                    DrawOnPricePanel                             = true;
                    DrawHorizontalGridLines                      = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                           = NinjaTrader.Gui.Chart.ScaleJustificati on.Right;
                    OscFast                                      = 5;
                    OscSlow                                      = 35;
                    BOBStrength                                  = 100;
                    //Disable this property if your indicator requires c ustom values that cumulate with each new market da ta event. 
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                     = true;
                    AddPlot(new Stroke(Brushes.Green,  9), PlotStyle.Bar, "OscAGUpr");
                    AddPlot(new Stroke(Brushes.Red, 9) , PlotStyle.Bar, "OscAGLwr");
                    AddPlot(Brushes.White, "LineEWOUpr ");
                    AddPlot(Brushes.White, "LineEWOLwr ");
                    AddPlot(new Stroke(Brushes.Lime, 9 ), PlotStyle.Bar, "OscAGUprDiv");
                    AddPlot(new Stroke(Brushes.Maroon,  9), PlotStyle.Bar, "OscAGLwrDiv");
                }
                else if (State == State.Configure)
                {
                }
            }
            protected override void OnBarUpdate()
            {
    
                MP[0]       =   ( High[0] + Low[0] ) / 2;
    
                UprLine[0]  =   0;
                LwrLine[0]  =   0;
                Lens        =   OscFast + OscSlow;
                Pr = 2.0/Lens; 
                if( CurrentBar < OscSlow){
                    OscAG = 0;
                    if (OscAG > 0){
                        OscAGUpr[0] = OscAG;
                        if (OscAGUpr[0] > OscAGUpr[1]){
                            OscAGUprDiv[0] = OscAG;
                        }
    
    
                    }
                    else{
                        OscAGLwr[0] = OscAG;
                        OscAGLwrDiv[0] = OscAG;
                        /*if (OscAGLwr[0] < OscAGLwr[1]){
                            OscAGLwrDiv[0] = OscAG;
                        }   */              
                    }
                }else{
                    OscAG       =   SMA(MP,OscFast)[0] - SMA(MP,OscSlow)[0];
                    if (OscAG > 0){
                        UprLine[0]  = (OscAG*Pr) + (UprLine[1]*(1-Pr));
                        Print( (OscAG*Pr) + (UprLine[1]*(1-Pr)) );
                        LwrLine[0]  = LwrLine[1];
                        OscAGUpr[0] = OscAG;
                            if (OscAGUpr[0] > OscAGUpr[1]){
                            OscAGUprDiv[0] = OscAG;
                        }
                    }else{
                        UprLine[0]      = UprLine[1];
                        LwrLine[0]      = (OscAG*Pr) + (LwrLine[1]*(1-Pr));
                        OscAGLwr[0] = OscAG;
                        if (OscAGLwr[0] > OscAGLwr[1]){
                            OscAGLwrDiv[0] = OscAG;
                        }
                        /*if (OscAGLwr[0] > OscAGLwr[1]){
                            OscAGLwrDiv[0] = OscAG;
                        }   */                  
                    }
                }
    
                LineEWOUpr[0]   =   BOBStrength / 100 * UprLine[0];
                LineEWOLwr[0]   =   BOBStrength / 100 * LwrLine[0];
    
            }
    
    
            #region Properties
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Na me = "Fast", GroupName = "NinjaScriptParameters",  Order = 0)]
            public int OscFast
            { get; set; }
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Na me = "Slow", GroupName = "NinjaScriptParameters",  Order = 1)]
            public int OscSlow
            { get; set; }
    
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Na me = "Strength", GroupName = "NinjaScriptParameter s", Order = 2)]
            public int BOBStrength
            { get; set; }
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> OscAG
            {
                get { return Values[0]; }
            }
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> OscAGUpr
            {
                get { return Values[0]; }
            }
    
    
    
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> OscAGLwr
            {
                get { return Values[1]; }
            }
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> LineEWOUpr
            {
                get { return Values[2]; }
            }
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> LineEWOLwr
            {
                get { return Values[3]; }
            }
    
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> OscAGUprDiv
            {
                get { return Values[4]; }
            }   
    
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> OscAGLwrDiv
            {
                get { return Values[5]; }
            }           
    
            #endregion
        }
    }
    #region NinjaScript generated code. Neither change  nor remove.
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.G ui.NinjaScript.IndicatorRenderBase
        {
            private SSTEAM.EWO_SSTEAM3[] cacheEWO_SSTEAM3;
            public SSTEAM.EWO_SSTEAM3 EWO_SSTEAM3(int  oscFast, int oscSlow, int bOBStrength)
            {
                return EWO_SSTEAM3(Input, oscFast, osc Slow, bOBStrength);
            }
            public SSTEAM.EWO_SSTEAM3 EWO_SSTEAM3(ISer ies<double> input, int oscFast, int oscSlow, int b OBStrength)
            {
                if (cacheEWO_SSTEAM3 != null)
                    for (int idx = 0; idx < cacheEWO_S STEAM3.Length; idx++)
                        if (cacheEWO_SSTEAM3[idx] != null && cacheEWO_SSTEAM3[idx].OscFast == oscFast && cacheEWO_SSTEAM3[idx].OscSlow == oscSlow && cacheEWO_SSTEAM3[idx].BOBStrength == bOBStrength && cacheEWO_SSTEAM3[idx].EqualsInput(input))
                            return cacheEWO_SSTEAM3[idx];
                return CacheIndicator<SSTEAM.EWO_SSTEA M3>(new SSTEAM.EWO_SSTEAM3(){ OscFast = oscFast, O scSlow = oscSlow, BOBStrength = bOBStrength }, inp ut, ref cacheEWO_SSTEAM3);
            }
        }
    }
    namespace NinjaTrader.NinjaScript.MarketAnalyzerCo lumns
    {
        public partial class MarketAnalyzerColumn : Ma rketAnalyzerColumnBase
        {
            public Indicators.SSTEAM.EWO_SSTEAM3 EWO_S STEAM3(int oscFast, int oscSlow, int bOBStrength)
            {
                return indicator.EWO_SSTEAM3(Input, os cFast, oscSlow, bOBStrength);
            }
            public Indicators.SSTEAM.EWO_SSTEAM3 EWO_S STEAM3(ISeries<double> input , int oscFast, int os cSlow, int bOBStrength)
            {
                return indicator.EWO_SSTEAM3(input, os cFast, oscSlow, bOBStrength);
            }
        }
    }
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gu i.NinjaScript.StrategyRenderBase
        {
            public Indicators.SSTEAM.EWO_SSTEAM3 EWO_S STEAM3(int oscFast, int oscSlow, int bOBStrength)
            {
                return indicator.EWO_SSTEAM3(Input, os cFast, oscSlow, bOBStrength);
            }
            public Indicators.SSTEAM.EWO_SSTEAM3 EWO_S STEAM3(ISeries<double> input , int oscFast, int os cSlow, int bOBStrength)
            {
                return indicator.EWO_SSTEAM3(input, os cFast, oscSlow, bOBStrength);
            }
        }
    }
    #endregion
    thanks in advance if you can help me!

    #2
    Hello TheCatTrader,
    Please find below my observations:-
    1. You're using public series - public Series<double> UprLine; public Series<double> LwrLine; public double mihl2; (above onstatechange) I think these can be private public not required.
    2. In #region properties, you've 2 definitions for Values[0], should remove public Series<double> OscAG as its already double as defined earlier.
    With these changes, I've compiled it & is working fine for me. I can save it to template & load that template in a diff chart.
    Hope it helps!

    Comment


      #3
      Originally posted by s.kinra View Post
      Hello TheCatTrader,
      Please find below my observations:-
      1. You're using public series - public Series<double> UprLine; public Series<double> LwrLine; public double mihl2; (above onstatechange) I think these can be private public not required.
      2. In #region properties, you've 2 definitions for Values[0], should remove public Series<double> OscAG as its already double as defined earlier.
      With these changes, I've compiled it & is working fine for me. I can save it to template & load that template in a diff chart.
      Hope it helps!
      It worked!

      Many thanks

      Comment


        #4
        Hello TheCatTrader,

        s.kinra is providing correct information.

        A few details.

        Objects that are using the public access modifier are generally something that needs to show in the user interface (meaning the Indicators properties window), or needs to be available outside of the indicator class, such as properties made available to a strategy that may be calling the indicator.
        https://ninjatrader.com/support/help...nt8/update.htm
        https://ninjatrader.com/support/help...urceManagement

        Anything that will just be used within the indicator class and is not part of the UI, such as any variables to store values internally like series, bools, and integers used for logic, should be private.

        Things that are public and are intended to be part of the UI (or need to be public to be accessible outside the class) will be attempted to be saved in any xml files such as templates and workspaces.

        Object types that are easily converted to strings (string, int, double, bool) will automatically be saved.
        Any object types that are not easily converted to strings (series, brushes, custom classes), will need to have the XmlIgnore attribute applied to prevent an error from appearing on the Log tab of the Control Center when attempting to save an xml file such as a template or workspace.
        https://ninjatrader.com/support/help...eattribute.htm

        A second public variable can be made to convert the value of variable using XmlIgnore to a string if this needs to be saved as well.
        Below is a link to the help guide example that does this with a brush.
        https://ninjatrader.com/support/help...definedbrushes
        https://ninjatrader.com/support/help...lor_inputs.htm

        As well as an example that does this with a TimeSpan.
        https://ninjatrader.com/support/help...tsub=XmlIgnore
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Scotty33, Today, 06:23 AM
        0 responses
        7 views
        0 likes
        Last Post Scotty33  
        Started by Johnny90, Today, 04:19 AM
        0 responses
        16 views
        0 likes
        Last Post Johnny90  
        Started by jeanne, Today, 03:43 AM
        0 responses
        13 views
        0 likes
        Last Post jeanne
        by jeanne
         
        Started by constituyente, Today, 02:37 AM
        0 responses
        6 views
        0 likes
        Last Post constituyente  
        Started by HinduMVP, Yesterday, 09:50 PM
        0 responses
        10 views
        0 likes
        Last Post HinduMVP  
        Working...
        X