Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Market Analyzer - Indicator, setting plot as signal

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

    Market Analyzer - Indicator, setting plot as signal

    In NT7, I was able to

    // Initialize()
    Add(new Plot(Color.FromKnownColor(KnownColor.Transparent), PlotStyle.Line, "Plot1"));

    // OnBarUpdate()
    if (condition is hit for long)
    Plot1.Set (1);
    else if (condition is hit for short)
    Plot1.Set(2);

    // properties
    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries Plot1
    {
    get { return Values[1]; }
    }

    This allowed setting up the above indicator as a column in Market Analyzer and able to print 0, 1(long) or 2(short) as signals.

    Question: How do I set the plot as above in NT8? Is there a sample?
    In NT8 after fixing compile errors, was always printing wrong value and not 0 or 1 or 2 in Market Analyzer

    Reference: I did look at: http://ninjatrader.com/support/forum...ead.php?t=4991 but didn't help. I do understand the Plot above may need to return Series<double>, but a sample may help

    #2
    Hello jawahar04, and thank you for contacting NinjaScript support.

    First I would like to draw your attention to this page which contains all the known code breaking changes between NT7 and NT8. You will find adding plots is on this list.



    NT8 introduced the AddPlot method, which replaces some of the Plot class' methods. The simplest form uses a SolidCcolorBrush object as its first argument. I am including a link to the NT8 Help Guide's documentation on Brushes



    The AddPlot function would then be called like this

    AddPlot(Brush brush, string name)

    There is another form that is more similar to the form you have posted, that relies on a Stroke object. I listed this second because Strokes have a constructor in this form :

    Stroke(Brush brush)

    I am including a link to the NT8 help guide for Strokes



    With this in mind, the closest form to what you posted for NT7, that is

    Add(new Plot(Color.FromKnownColor(KnownColor.Transparent), PlotStyle.Line, "Plot1"));

    would be this in NT8

    AddPlot(new Stroke(Brushes.Transparent), PlotStyle.Line, "Plot1");

    For more information I am including a link to the documentation for AddPlot in NT8. Please review its subsections as well, as they contain valuable information for plotting in NT8.



    In the code breaking changes page as well, you will notice that DataSeries.Set() has been replaed with an overloaded = operator.

    I have attached a code sample in which I have applied all of the above advice for porting a plot from Ninja 7 to Ninja 8.

    I hope all of the above answers all the questions you had with regard to your code.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thank you Jessica and appreciate the response.
      Did you mean to attach sample code?

      Comment


        #4
        I did. I'll go ahead and inline it here.

        Code:
        // 
        // Copyright (C) 2015, NinjaTrader LLC <www.ninjatrader.com>.
        // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
        //
        #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.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
        {
          /// <summary>
          /// This is where you describe your indicator
          /// </summary>
          public class Example1456422 : Indicator
          {
            private double exampleProperty;
        
            /**
              Set these to true one at a time to test your strategy,
              replace these with your actual condition logic when you know they work
             */
            private bool shortHit = false, longHit = false;
        
            protected override void OnStateChange()
            {
              if (State == State.SetDefaults)
              {
                Description               = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionSMA;
                Name                      = "Example1456422";
                IsOverlay                 = true;
                IsSuspendedWhileInactive  = true;
        
                /*
                   This is how we create a plot in NT8.
                   Try setting the color to Auqa for testing.
                 */
                AddPlot(new Stroke(Brushes.Transparent), PlotStyle.Line, "Plot1");
        
              }
              else if (State == State.Configure)
              {
                /** We set our properties here now */
                exampleProperty = 0.0;
              }
            }
        
            protected override void OnBarUpdate()
            {
              
              /*
                Here we send a 0 by default,
                a 1 if your short condition is met,
                and a 2 if your long condition is met
              */
              Value[0] = 0.0;
              if (shortHit)
              {
                Value[0] = 1.0;
              }
              else if (longHit)
              {
                Value[0] = 2.0;
              }
            }
        
            #region Properties
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display (
                ResourceType = typeof(Custom.Resource),
                Name = "Period",
                GroupName = "NinjaScriptParameters",
                Order = 0
                )]
            public int Period { get; set; }
            #endregion
          }
        }
        
        #region NinjaScript generated code. Neither change nor remove.
        
        namespace NinjaTrader.NinjaScript.Indicators
        {
          public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
          {
            private Example1456422[] cacheExample1456422;
            public Example1456422 Example1456422(int period)
            {
              return Example1456422(Input, period);
            }
        
            public Example1456422 Example1456422(ISeries<double> input, int period)
            {
              if (cacheExample1456422 != null)
                for (int idx = 0; idx < cacheExample1456422.Length; idx++)
                  if (cacheExample1456422[idx] != null && cacheExample1456422[idx].Period == period && cacheExample1456422[idx].EqualsInput(input))
                    return cacheExample1456422[idx];
              return CacheIndicator<Example1456422>(new Example1456422(){ Period = period }, input, ref cacheExample1456422);
            }
          }
        }
        
        namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
        {
          public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
          {
            public Indicators.Example1456422 Example1456422(int period)
            {
              return indicator.Example1456422(Input, period);
            }
        
            public Indicators.Example1456422 Example1456422(ISeries<double> input , int period)
            {
              return indicator.Example1456422(input, period);
            }
          }
        }
        
        namespace NinjaTrader.NinjaScript.Strategies
        {
          public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
          {
            public Indicators.Example1456422 Example1456422(int period)
            {
              return indicator.Example1456422(Input, period);
            }
        
            public Indicators.Example1456422 Example1456422(ISeries<double> input , int period)
            {
              return indicator.Example1456422(input, period);
            }
          }
        }
        
        #endregion
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Thanks, Jessica. I had some issues with the sample not populating the period column in Market Analyzer. I will post later today my slightly tweaked sample which adjusts 'shortHit' and 'longHit'

          Comment


            #6
            Please see below tweaked sample.
            1) The 'OnBarUpdate' string isn't getting printed in the output log
            2) Since OnBarUpdate doesn't get triggered when I use this indicator in Market Analyzer the Column isn't populated. Note standard column like 'Last Price' do get updated.

            #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.Data;
            using NinjaTrader.NinjaScript;
            using NinjaTrader.Core.FloatingPoint;
            using NinjaTrader.NinjaScript.DrawingTools;
            #endregion

            //
            // Copyright (C) 2015, NinjaTrader LLC <www.ninjatrader.com>.
            // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
            //
            #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.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
            {
            /// <summary>
            /// This is where you describe your indicator
            /// </summary>
            public class Example1456422 : Indicator
            {
            private double exampleProperty;

            /**
            Set these to true one at a time to test your strategy,
            replace these with your actual condition logic when you know they work
            */
            private bool shortHit = false, longHit = false;

            protected override void OnStateChange()
            {
            Print("OnStateChange");
            if (State == State.SetDefaults)
            {
            Print ("State.SetDefaults");
            Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionSMA;
            Name = "Example1456422";
            IsOverlay = true;
            IsSuspendedWhileInactive = true;

            /*
            This is how we create a plot in NT8.
            Try setting the color to Auqa for testing.
            */
            AddPlot(new Stroke(Brushes.Transparent), PlotStyle.Line, "Plot1");

            }
            else if (State == State.Configure)
            {
            Print ("State.Configure");
            /** We set our properties here now */
            exampleProperty = 0.0;
            }
            }

            protected override void OnBarUpdate()
            {
            Print ("onbarupdate");
            /*
            Here we send a 0 by default,
            a 1 if your short condition is met,
            and a 2 if your long condition is met
            */
            Random r = new Random();
            int x = r.Next(1, 10);
            Value[0] = 5.0;
            if (x <5)
            {
            Value[0] = 1.0;
            }
            else if (x>5)
            {
            Value[0] = 2.0;
            }
            }

            #region Properties
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display (
            ResourceType = typeof(Custom.Resource),
            Name = "Period",
            GroupName = "NinjaScriptParameters",
            Order = 0
            )]
            public int Period { get; set; }
            #endregion
            }
            }

            #region NinjaScript generated code. Neither change nor remove.

            namespace NinjaTrader.NinjaScript.Indicators
            {
            public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
            {
            private Example1456422[] cacheExample1456422;
            public Example1456422 Example1456422(int period)
            {
            return Example1456422(Input, period);
            }

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

            namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
            {
            public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
            {
            public Indicators.Example1456422 Example1456422(int period)
            {
            return indicator.Example1456422(Input, period);
            }

            public Indicators.Example1456422 Example1456422(ISeries<double> input , int period)
            {
            return indicator.Example1456422(input, period);
            }
            }
            }

            namespace NinjaTrader.NinjaScript.Strategies
            {
            public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
            {
            public Indicators.Example1456422 Example1456422(int period)
            {
            return indicator.Example1456422(Input, period);
            }

            public Indicators.Example1456422 Example1456422(ISeries<double> input , int period)
            {
            return indicator.Example1456422(input, period);
            }
            }
            }

            #endregion

            Comment


              #7
              Hello jawahar04,

              May I ask for your current Market Analyzer configuration? Please, when setting up your configuration, refrain from using custom indicators and columns other than the example code under test in this thread.

              If you could send me your template files, and a screenshot of your Columns configuration, it would be appreciated.

              I would like you to save your current Market Analyzer template as ExampleTemplate1455829 . You can do so by right-clicking in the Market Analyzer window -> Templates -> Save As. Please check "save instruments". Name your template ExampleTemplate1455829 and click Save. Once you save your Market Analyzer template, you will find it in your filesystem in (My) Documents\NinjaTrader 8\templates\MarketAnalyzer\ExampleTemplate1455829. xml .

              You can bring up your columns configuration by right clicking in the Market Analyzer window -> Columns... . To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool. Instructions here, http://windows.microsoft.com/en-us/w...#1TC=windows-8 .

              Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment. Detailed instructions here, http://take-a-screenshot.org/ .
              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                Hi Jessica,
                Thanks for the guidance. I will post the template and screen-shot as soon as I get a chance to try it.

                Comment


                  #9
                  Hello Jessica,
                  I have attached the screen-shots as requested. I couldn't upload the template file as-is, so I have added a '.txt' extension.

                  Note the 'onbarupdate' is not being printed because OnBarUpdate isn't triggered.
                  Attached Files

                  Comment


                    #10
                    Hello again jawahar04,

                    When I create a new indicator called Example1456422 , paste your code in, create a new chart with this indicator tracking the EURUSD instrument, and connect to the simulated data feed, the output from New -> NinjaScript Output is as follows :

                    ...
                    onbarupdate
                    X: 33698
                    onbarupdate
                    X: 85356
                    onbarupdate
                    X: 45532
                    ...

                    I would like to ask, could you repeat this test, with the same indicator, instrument, and data feed, and let me know if you see the same behavior?
                    Jessica P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Jessica,
                      Thanks. Can you please confirm you tried through Market Analyzer and got the OnBarUpdate() triggered? I will confirm via Chart (and adding the Example Indicator). For me going thru Market Analyzer does not trigger OnBarUpdate(). I connected Ameritrade, Google as data feeds. Also tried CQG and adding ES-03-16 to Market Analyzer.
                      (See also my screen-shots for the Market Analyzer and Output windows)

                      Comment


                        #12
                        Hi Jessica,
                        Just confirming
                        1) Using the Example1456422 indicator - works via Chart (i.e. adding the indicator to the chart). The OnBarUpdate() is triggered.
                        2) Using the same symbol as above in Market Analyzer does NOT trigger OnBarUpdate
                        Screen-shots of Market Analyzer is already attached in my post from 2/6/16.

                        Comment


                          #13
                          Hello jawahar04,

                          I created a video to show it is working on Kinetick. You can view the video here: http://screencast.com/t/zGuAYvNqSOgy

                          I noticed you are using the Daily bars and calculating on the bar close. Try using minute or tick bars, or changing the Calculate to OnPriceChange or OnEachTick.

                          Comment


                            #14
                            Hello Patrick,
                            Thanks for the screen-cast. So the indicator works for you (and Jessica) in Market Analyzer.
                            However it doesn't work for me.

                            What can I do to troubleshoot?
                            I do have the following in the attached MyCustomIndicator.cs
                            Calculate = Calculate.OnEachTick;

                            Comment


                              #15
                              Hello jawahar04,

                              One strategy I can recommend for debugging, is to start off with your indicator in a newly created market analyzer, set to analyze the ES <currently traded month> instrument. In my case this is the ES 03-16 instrument. The only new column should be your indicator. I have verified this works on my end on the simulated data feed.

                              Once you have this known good configuration, you can then reintroduce settings and configurations one at a time from the market analyzer template you sent us, until you are able to verify which setting or configuration is causing your indicator column to not update.
                              Jessica P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by carnitron, Today, 08:42 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Today, 07:51 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post strategist007  
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,974 views
                              3 likes
                              Last Post jhudas88  
                              Started by rbeckmann05, Today, 06:48 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post rbeckmann05  
                              Started by rhyminkevin, Today, 04:58 PM
                              4 responses
                              58 views
                              0 likes
                              Last Post dp8282
                              by dp8282
                               
                              Working...
                              X