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

ChartTrader addon - how to make permanent?

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

    ChartTrader addon - how to make permanent?

    Hi there,

    Loving the platform and all its flexibility...

    I have coded an addon to chart trader (see pic). They are simple buttons to enter some custom orders. Correct me if I am wrong please but for something like this to enter orders, it needs to be a strategy (which I have done)?

    Is there a way to have this load on every chart by default and remain active if I use the other buttons like Buy Mkt, Sell Mkt, Buy Ask, Sell Ask, etc...?

    Because it is a strategy everytime I load a chart I have to go in the strategies panel and enable this and everytime one of the actual chart trader default buttons is pressed, the "strategy" is disabled and my addon goes away until I enable it again.

    Looking for a way to make this permanent by default no matter what? Thank you for the great support so far!
    Attached Files
    Last edited by focus333; 06-04-2021, 03:54 PM.

    #2
    Hello focus333,

    Scripts that are not strategies can use the Addon approach to place orders through the Account.

    Below is a link to an example indicator that demonstrates.
    I need some guidance. I need to create a script that has 3 plots that are public and they plot either a 1 or 0. But I need to create another indicator that has 3 chart buttons that sets these variables. The first indicator needs to get those values from the second indicator depending on the button clicks. Because of using


    You can save a default chart template to load the indicator with each new chart that is opened.


    Injecting code into open windows is possible with custom C#, but is not recommend.

    Indicators, which can place orders through the Addon approach, do not have to be enabled like NinjaScript Strategies.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi NinjaTrader_ChelseaB

      Thank you for the reply. When I try to enter my logic as an indicator I get several errors when attempting to use EnterLong, ExitLong, setStopLoss, setProfitTarget.

      To illustrate this, I've created a brand new blank indicator and simply added some of these commands.. here's the complete code. The lines in bold are the only ones I've added on top of the blank ninja-generated indicator.

      If I do it as a strategy it compiles but has the other drawbacks I stated on the original post.


      Incidentally, it looks like the original script I was trying to adapt was created by you ​ so hopefully you'll be able to help... I want enter an order when one the buttons (1,2,3,4) of ChartTraderCustomButtonsExample.cs is clicked (original attached) but I get the same type of errors as the above screenshot. How could ChartTraderCustomButtonsExample.cs be adapted to enter a bracket order(entry, stopLoss and profit target) upon click?



      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
      {
      public class MyCustomIndicator1 : Indicator
      {
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Indicator here.";
      Name = "MyCustomIndicator1";
      Calculate = Calculate.OnBarClose;
      IsOverlay = false;
      DisplayInDataBox = true;
      DrawOnPricePanel = true;
      DrawHorizontalGridLines = true;
      DrawVerticalGridLines = true;
      PaintPriceMarkers = true;
      ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
      //Disable this property if your indicator requires custom values that cumulate with each new market data event.
      //See Help Guide for additional information.
      IsSuspendedWhileInactive = true;
      }
      else if (State == State.Configure)
      {
      }
      }
      
      protected override void OnBarUpdate()
      {
      //Add your custom indicator logic here.
      string label = "test";
      [B]SetStopLoss(label, CalculationMode.Price, 100 , false); //Set protective orders before the entry is made.
      
      SetProfitTarget(label, CalculationMode.Price, ( 102 ), false);
      
      EnterLong(33, label );[/B]
      }
      }
      }
      
      #region NinjaScript generated code. Neither change nor remove.
      
      namespace NinjaTrader.NinjaScript.Indicators
      {
      public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
      {
      private MyCustomIndicator1[] cacheMyCustomIndicator1;
      public MyCustomIndicator1 MyCustomIndicator1()
      {
      return MyCustomIndicator1(Input);
      }
      
      public MyCustomIndicator1 MyCustomIndicator1(ISeries<double> input)
      {
      if (cacheMyCustomIndicator1 != null)
      for (int idx = 0; idx < cacheMyCustomIndicator1.Length; idx++)
      if (cacheMyCustomIndicator1[idx] != null && cacheMyCustomIndicator1[idx].EqualsInput(input))
      return cacheMyCustomIndicator1[idx];
      return CacheIndicator<MyCustomIndicator1>(new MyCustomIndicator1(), input, ref cacheMyCustomIndicator1);
      }
      }
      }
      
      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
      {
      public Indicators.MyCustomIndicator1 MyCustomIndicator1()
      {
      return indicator.MyCustomIndicator1(Input);
      }
      
      public Indicators.MyCustomIndicator1 MyCustomIndicator1(ISeries<double> input )
      {
      return indicator.MyCustomIndicator1(input);
      }
      }
      }
      
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
      {
      public Indicators.MyCustomIndicator1 MyCustomIndicator1()
      {
      return indicator.MyCustomIndicator1(Input);
      }
      
      public Indicators.MyCustomIndicator1 MyCustomIndicator1(ISeries<double> input )
      {
      return indicator.MyCustomIndicator1(input);
      }
      }
      }
      
      #endregion
      This fails compiling with these errors:





      Thank you kindly!
      Last edited by focus333; 06-04-2021, 03:54 PM.

      Comment


        #4
        Hello focus333,

        That became SampleWPFModifications.
        https://ninjatrader.com/support/foru...07#post1124507

        With placing orders through an indicator, this would have to be done using the Addon approach noted in post #2.

        I have some recent demos you might like I've attached. Something I'm working on for a larger picture project I have in the works to organize our support suggestions over the years for all the developers out there.

        These demonstrate placing orders from button clicks with 3 approaches in both strategies and indicators using the addon approach:
        1. Placing a market order immediately when clicked
        2. Submitting a limit order with limit price updated to indicator plot value
        3. Setting a trigger to submit a market order after conditions are met

        Similar to the ProfitChaseStopTrail demos, these are ideas implemented in different types of scripts to convey it's an idea and the code is how you decide to tackle it.

        The ProfitChaseStopTrail demos in case you were not familiar with these:
        https://ninjatrader.com/support/foru...269#post802269

        And Strategy Builder versions:
        https://ninjatrader.com/support/foru...596#post806596
        Attached Files
        Last edited by NinjaTrader_ChelseaB; 02-03-2021, 06:17 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi NinjaTrader_ChelseaB,

          Thanks so much for these.

          Are you able to offer a syntax example for entering a bracket order, with entry, stop, and profit Target using the account.CreateOrder approach?

          Appreciate all you do here!

          Comment


            #6
            NinjaTrader_ChelseaB WOW the Sample WPF modifications is SUPER awesome! You are amazing!

            Is there a plan to add some input fields in the future? My project kinda attempts to do this. The idea is to have an input field to capture a stop price. then I can enter a market order using the stop price entered in the input and then use this delta (of enter - stop) to calculate the desired number of shares (risking a certain $ amount) AND say a 2X reward and set a profit target based on this. So a bracket order in the end with enter, stop, profit target.

            Thanks again!

            Comment


              #7
              Hello focus333,

              Breakout - https://ninjatrader.com/support/foru...579#post770579
              Text input in Addon window - https://ninjatrader.com/support/foru...686#post492686
              Text input in indicator - https://ninjatrader.com/support/foru...756#post831756
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi NinjaTrader_ChelseaB

                I am looking at the "Breakout" link and it uses unmanagedOrder. Another post I read (https://ninjatrader.com/support/foru...der#post491174) says that unmanagedOrders are for automated strategies while CreateOrder for addOns.

                Do you have an example of creating OCO orders + entry that uses CreateOrder instead of unmanaged?

                Thanks again!

                Comment


                  #9
                  Hello focus333,

                  The ProfitChaseStopTrailIndicatorExample_NT8 I have previously linked you uses OCO with the Addon approach.

                  I am also including below a link to an example that uses OCO in the addon approach.
                  https://ninjatrader.com/support/foru...-on#post820720
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi NinjaTrader_ChelseaB

                    So, I went from super excited to super confused, LOL.... I have done a little bit with indicators and a little bit with strategies but I now realize that my post title used the word "add on" and I see that AddOn is another type of ninjatrader component. Well, I did not know that!

                    I have imported the ProfitChaseStopTrailIndicatorExample_NT8 code and went looking for it in the indicators and strategies and noticed it wasn't there but instead it shows in the "AddOn folder". EDIT.................: I found out how to use it but it brings up a new dialogue window with additional steps, so that's not what I am looking for, unfortunately.


                    In the end, all I want to accomplish is to double click on a price in the chart, which will immediately enter a market order (long) with a stopLoss set to the price where I double-clicked and then set a profit target based on multiples of the difference between the price the market order filled and the stopLoss price I clicked on - a simple 1 risk for 3 reward approach, for example.

                    I have been able to accomplish all of this inside a ninjatrader strategy that I have coded and I would be done and happy except for the fact that I cannot drag and move the stop loss and profit target orders after the entry order is filled - support has confirmed that with coded strategies this doesn't work:

                    "Orders generated with stand-alone NinjaScript methods can not be modified through Chart Trader, they would need to be changed through code. You will need to implement the strategy to submit an ATM strategy"

                    From my post here (https://ninjatrader.com/support/foru...rget-orders-ib).

                    I feel so close but so far away from entering a bracket order with a double-click where I can drag and move the orders after entry has filled.... brain is melting

                    ) but SL and PT orders cannot be moved ​. So far I don't see a way of doing what I want with the suggested ATM strategy approach as I want to grab the stop price with a double-click and then use that to calculate the other PT and size, being able to manually adjust after the fact. Makes sense?


                    Thanks SO MUCH for all the help so far!
                    Last edited by focus333; 02-08-2021, 01:07 AM.

                    Comment


                      #11
                      Hello focus333,

                      If you use Exit methods with IsLiveUntilCancelled set to true, you can move the orders frely with Chart Trader and they will not move back to their original position unless the Exit method is called again to move the order. Our SampleOnOrderUpdate strategy can demonstrate. (Note that Exit methods do not use native OCO, if this is a requirement, we recommend using the Unmanaged Approach.)

                      SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

                      If you want to add functionality to simply enter a position with a market order and protect the position, I would recommend using AddOn Framework code to enter your position with an ATM strategy attached. You would need to create a market entry order called "Entry" with CreateOrder, and then you would submit that order with StartAtmStrategy.

                      CreateOrder - https://ninjatrader.com/support/help...reateorder.htm

                      StartAtmStrategy - https://ninjatrader.com/support/help...tmstrategy.htm

                      I have an example indicator that shows how orders can be submitted with mouse clicks. AddOn Framework code is used for order submissions. This could be modified to look for double clicks. I might suggest using a timer to check if a second mouse click occurs in a short time, and if that happens ,fire your logic to submit your order. The example could also be modified to submit market entry order's called "Entry" and use StartAtmStrategy to attach an Atm strategy to that entry order.

                      We look forward to assisting.

                      Attached Files
                      JimNinjaTrader Customer Service

                      Comment


                        #12
                        Hi and thank you,

                        What are main pros & cons between managed and unmaged approaches? With unmanaged, will the orders still be shown in chart and will chart trader function normally? Also, should still be move to adjust the SL and PT orders from the chart? What functionally is lost when going unmanaged?

                        Can the unmanaged approach be added to an indicator or does it have to be of strategy type?

                        Thanks
                        Last edited by focus333; 02-05-2021, 12:48 PM.

                        Comment


                          #13
                          Hello focus333,

                          The difference is order handling rules used by the managed approach. The unmanaged approach is used when you want full control. You decide every order type, direction, and quantity.
                          With the managed approach, NinjaTrader manages the orders and will automatically reverse positions, allow you to attach exits to specific entries, and works to prevent unwanted positions.
                          https://ninjatrader.com/support/help...antedPositions
                          https://ninjatrader.com/support/help...d_approach.htm

                          Any approach, managed strategy, unmanaged strategy, or addon approach can be written to allow manual order modifications. The approach with extra considerations for manual interventions will be the managed approach as this will update order prices continuously, undoing manual changes.

                          Neither the managed or unmanaged strategy approaches can be used through the Addon approach which would be used for indicators.
                          But the unmanaged strategy approach is very similar to the Addon approach in that you would have to fully control the order type, direction, and quantity, however a completely different set of methods is used.
                          https://ninjatrader.com/support/help...reateorder.htm
                          Last edited by NinjaTrader_ChelseaB; 02-07-2021, 04:36 PM.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_Jim View Post
                            Hello focus333,

                            If you use Exit methods with IsLiveUntilCancelled set to true, you can move the orders frely with Chart Trader and they will not move back to their original position unless the Exit method is called again to move the order. Our SampleOnOrderUpdate strategy can demonstrate. (Note that Exit methods do not use native OCO, if this is a requirement, we recommend using the Unmanaged Approach.)

                            SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

                            If you want to add functionality to simply enter a position with a market order and protect the position, I would recommend using AddOn Framework code to enter your position with an ATM strategy attached. You would need to create a market entry order called "Entry" with CreateOrder, and then you would submit that order with StartAtmStrategy.

                            CreateOrder - https://ninjatrader.com/support/help...reateorder.htm

                            StartAtmStrategy - https://ninjatrader.com/support/help...tmstrategy.htm

                            I have an example indicator that shows how orders can be submitted with mouse clicks. AddOn Framework code is used for order submissions. This could be modified to look for double clicks. I might suggest using a timer to check if a second mouse click occurs in a short time, and if that happens ,fire your logic to submit your order. The example could also be modified to submit market entry order's called "Entry" and use StartAtmStrategy to attach an Atm strategy to that entry order.

                            We look forward to assisting.
                            Hi Jim,

                            Yes, I want to implement the DOUBLE clicks option. Could you please provide a guide or codes example.

                            Omololu

                            Comment


                              #15
                              Hello focus333,

                              ProfitChaseStopTrailIndicatorExample_NT8 is an indicator, is added to the Indicators window, and does not add anything to the Addons folder.
                              I think you may be confusing scripts. Check the script name again.

                              Omololu, I'm not aware of any examples that capture a double click. However, I am providing a link to the microsoft documentation.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by techgetgame, Today, 11:42 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post techgetgame  
                              Started by sephichapdson, Today, 11:36 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post sephichapdson  
                              Started by bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,612 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Today, 05:56 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post jaybedreamin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              19 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Working...
                              X