Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

On Chart Custom menu and toolbar button..can we help each other

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

    On Chart Custom menu and toolbar button..can we help each other

    Hello,
    I have seen the other postings and know that NT support cannot help us. I know it's possible to add buttons to the chart toolbar and also customize the context menus on the chart. I would like to know which bar the right click menu was invoked on.

    Is there anybody interested in working with me on this. I am an experienced programmer but new to the C# and .NET world. With just a little bit of guidance I am sure I can figure this out. When we work together on this we can share the code we develop for this.

    If you are interested please send me a private message.

    thanks,
    PK

    #2
    Can somebody PLEEASE give me a hint on where I would start looking for a solution to achive my above goals? Thanks in advance.

    Comment


      #3
      Hi pkatta,
      There is a site that sells a very reasonable NT Toolbar button. I am going to download it myself and try it -



      Regards,

      Gordon

      Comment


        #4
        Any luck folks on figuring out how to add that button?


        Originally posted by grose View Post
        Hi pkatta,
        There is a site that sells a very reasonable NT Toolbar button. I am going to download it myself and try it -



        Regards,

        Gordon

        Comment


          #5
          You need to look at the MSDN class ToolStripButton

          You can modify the NT toolstrip by getting the chart toolstrip in code.
          Code:
          ToolStrip toolStrip = (ToolStrip)ChartControl.Controls["tsrTool"];
          then adding buttons to that toolstrip.

          Don't forget to add click events, as well as remove them when the strategy / indicator is disposed.

          hope this helps.
          mrlogik
          NinjaTrader Ecosystem Vendor - Purelogik Trading

          Comment


            #6
            Here's code that will add buttons you can use to place orders - so, it has to be in a strategy. You can add similar code to an indicator, but you won't be able to place orders from that code. I found the start of this on another site - I'll have to find the link to give credit where credit is due.

            Please note - I found that in the button click events, the standard NT Open[0], etc. were not available. I had to cache values by updating private variables in OnBarUpdate() that I wanted to reference in the button click event code.

            I stripped out my own logic from the code in notepad. You may find a line of code or two that needs tweaking to get it to compile.

            #region Using declarations
            using System;
            using System.ComponentModel;
            using System.Diagnostics;
            using System.Drawing;
            using System.Drawing.Drawing2D;
            using System.Xml.Serialization;
            using NinjaTrader.Cbi;
            using NinjaTrader.Data;
            using NinjaTrader.Indicator;
            using NinjaTrader.Gui.Chart;
            using NinjaTrader.Strategy;
            using System.IO;
            using System.Collections;
            using System.Windows.Forms;
            #endregion
            // This namespace holds all strategies and is required. Do not change it.
            namespace NinjaTrader.Strategy
            {
            /// <summary>
            ///
            /// </summary>
            [Description("")]
            public class ToolBarButtons : Strategy
            {
            #region Variables
            // Wizard generated variables
            // User defined variables (add any user defined variables below)
            #endregion

            private System.Windows.Forms.ToolStrip strip = null;
            private System.Windows.Forms.ToolStripButton btnLong = null;

            bool isInitialized = false;

            private string defaultATM = "My favorite ATM";
            private int defaultQuantity = 1;
            private string atmStrategyId = null;

            private double open_0;
            private double open_1;
            private double open_2;
            private double high_0;
            private double high_1;
            private double high_2;
            private double low_0;
            private double low_1;
            private double low_2;
            private double close_0;
            private double close_1;
            private double close_2;
            private DateTime date_time_0;
            private DateTime date_time_1;
            private DateTime date_time_2;

            private string symbol = null;
            private string chartInstrument = null;
            private string intervalType = null;
            private Period period = null;
            private PeriodType periodType = 0;
            private int intervalValue = 0;
            private int numTicksPerPoint = 0;

            private Font boldFont = null;
            private Font regularFont = null;

            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
            CalculateOnBarClose = false;

            }
            public override void Dispose() {

            if (isInitialized) {
            isInitialized = false;
            strip.Items.Remove(btnLong);
            }

            }

            private void btnLong_Click(object sender, EventArgs e)
            {
            // -- if going long, the current or immediately prior
            // bar low must be l...

            // -- note, have to make sure is range chart, know range, etc.
            switch (Position.MarketPosition) {
            case MarketPosition.Flat:
            log("Currently flat");
            break;
            case MarketPosition.Long:
            log("Currently long");
            break;
            case MarketPosition.Short:
            log("Currently short");
            break;
            }

            logBarInfo("long");

            if (Position.MarketPosition != MarketPosition.Flat) {
            log("Position currently open - not placing new order.");
            return;
            }

            btnLong.Font = regularFont;
            btnLong.Enabled = false;

            bool placeBuyOrder = true;

            if (!placeBuyOrder) {

            string message = "Order not placed for reason(s): ";

            log(message);

            btnLong.Font = boldFont;
            btnLong.Enabled = true;
            return;

            }




            // -- first number, limit, second number, stop
            atmStrategyId = GetAtmStrategyUniqueId();

            bool atmResult = false;
            atmResult = AtmStrategyCreate(Action.Buy, OrderType.Limit, limitPrice, 0,
            TimeInForce.Day, entryOrderId, defaultATM,
            atmStrategyId);

            // -- log info
            log("Preparing buy limit at " + limitPrice + " using atm " + defaultATM);

            if (!atmResult) log("Error placing order");

            btnLong.Font = boldFont;
            btnLong.Enabled = true;

            }

            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {

            open_0 = Open[0];
            open_1 = Open[1];
            open_2 = Open[2];
            high_0 = High[0];
            high_1 = High[1];
            high_2 = High[2];
            low_0 = Low[0];
            low_1 = Low[1];
            low_2 = Low[2];
            close_0 = Close[0];
            close_1 = Close[1];
            close_2 = Close[2];
            date_time_0 = Time[0];
            date_time_1 = Time[1];
            date_time_2 = Time[2];


            // -- paint buttons
            if (!isInitialized) {

            isInitialized = true;

            symbol = Instrument.MasterInstrument.Name;
            chartInstrument = Instrument.FullName;
            period = Bars.Period;
            periodType = period.Id;
            intervalValue = period.Value;
            numTicksPerPoint = Convert.ToInt32(Convert.ToDouble(1) / TickSize);

            switch (periodType) {
            case PeriodType.Minute:
            intervalType = "M";
            break;
            case PeriodType.Tick:
            intervalType = "T";
            break;
            case PeriodType.Volume:
            intervalType = "V";
            break;
            case PeriodType.Day:
            intervalType = "D";
            break;
            case PeriodType.Range:
            intervalType = "R";
            break;
            default:
            intervalType = "UK";
            break;
            }


            System.Windows.Forms.Control[] controls =
            ChartControl.Controls.Find("tsrTool", false);

            if (controls.Length > 0) {

            ToolStripButton btnTemp = new System.Windows.Forms.ToolStripButton("temp");
            boldFont = new Font(btnTemp.Font, FontStyle.Bold);
            regularFont = new Font(btnTemp.Font, FontStyle.Regular);
            btnTemp = null;

            btnLong = new System.Windows.Forms.ToolStripButton("btnLong");
            btnLong.Font = boldFont;
            btnLong.ForeColor = Color.Green;
            btnLong.Text = "Long";


            strip = (System.Windows.Forms.ToolStrip)controls[0];

            strip.Items.Add(btnLong);
            btnLong.Click += btnLong_Click;

            }

            log("Initialized ToolBarButtons.");

            } // -- if (!isInitialized)

            }

            private void log(string message) {

            DirectoryInfo Di =
            new DirectoryInfo(System.Environment.GetFolderPath(Env ironment.SpecialFolder.MyDocuments));
            string FileName = Di.FullName + "\\NinjaTrader 6.5\\" +
            symbol + "-" + Convert.ToString(intervalValue) + intervalType + "-orderinfo.txt";

            // -- Subfolder would be "NinjaTrader 6.5"
            StreamWriter Writer = new StreamWriter(FileName, true);


            Writer.WriteLine(Convert.ToString(DateTime.Now) + " " + message);
            Writer.WriteLine("");
            Writer.Close();

            }

            #region Properties
            #endregion
            }
            }

            Comment


              #7
              Thanks mrlogik and grose. I took a look at the MSDN website and got a little info on the ToolStripButton. Grose- I may try that code you gave me, but I'm starting to think that I'm in a little over my head here. I may just go with paying someone for the work. We'll see.

              Comment


                #8
                I have modified The code that was pasted in this topic to use the appropriate initialize events and work cleaner. You can easily check the status of the buttons from the OnBarUpdate() event and then execute the strategy code you want without using temporary variables that were proposed in the original code sample. You can find the modified code posted at emini-fools.

                Comment


                  #9
                  Buttons

                  Originally posted by mjc4118 View Post
                  I have modified The code that was pasted in this topic to use the appropriate initialize events and work cleaner. You can easily check the status of the buttons from the OnBarUpdate() event and then execute the strategy code you want without using temporary variables that were proposed in the original code sample. You can find the modified code posted at emini-fools.
                  mjc4118,

                  I tried out the code you posted at emini-fools and it works, but I'm getting the following error in the Ninja Log,

                  Failed to call method 'Initialize' for strategy 'ToolBarButtons'. Object reference not set to an instance of an object."

                  Do you experience the same message when using your button code?

                  Comment


                    #10
                    I copied the code from my post and pasted it overwriting all code in a new ninja script code window and hit compile ...and yes there was that error.. to fix it ...

                    Remove all the code from
                    protected override void Initialize()
                    (
                    .....
                    )
                    And put it inside:
                    protected override void OnStartUp()
                    {

                    }

                    It cannot initialize properly in the initialize event. It needs to be executed in the OnStartup event. After you have compiled and the strategy to a chart ... click on control panel Strategy tab and enable your strategy ... You will see the buttons on your chart

                    Comment


                      #11
                      Awesome MJC4118. That worked. Thank you.

                      You sound like you know a little about coding... you wouldn't happen to know how to start/stop a strategy with code that I could put behind one of these buttons, would you?

                      fosch

                      Comment


                        #12
                        no I have not looked into it..but I am almost done with a code library that I will be licensing that allows you to add strategies on the strategy tab and enable/disable it there (basically you leave it enabled) and then it will execute or not execute orders based on about 20 different parameters including start and stop time, as well as manage your exits, targets and stops based on different parameters. Additionally you can even modify the "parameters" visually without having to "disable" the strategy on the strategy tab. I will send you a link in about a week or two.
                        Last edited by mjc4118; 10-21-2010, 08:00 PM. Reason: spelling

                        Comment


                          #13
                          Sounds good. Look forward to seeing what you have come up with.

                          Comment


                            #14
                            Hello, I would like to know if you still offer the code library you were working on that allows you to enable/disable strategies in the strategy tab among other features. My email is [email protected] if you can contact me with any information regarding it. Thank you

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by maybeimnotrader, Yesterday, 05:46 PM
                            1 response
                            18 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by Perr0Grande, Yesterday, 08:16 PM
                            1 response
                            7 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by f.saeidi, Yesterday, 08:12 AM
                            3 responses
                            25 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by algospoke, Yesterday, 06:40 PM
                            1 response
                            15 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by quantismo, Yesterday, 05:13 PM
                            1 response
                            14 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Working...
                            X