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

Draw objects in OnExecution() during manual trading

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

    Draw objects in OnExecution() during manual trading

    Hello,

    I'm developing a strategy that plot arrow line and text while I am trading by hands. The strategy should plot the objects each time when my orders are executed. I place limit orders through SuperDom.

    I know that I can use Plot Execution in data series, but I'd like to use my strategy.

    In my strategy I use OnExecution() method to draw the objects. I used the same code in my other strategies which placed orders and they draw objects during testing in Strategy Analizer. But this code doesn't work when I attached it to chart and trade by hand.

    Please, help me with my strategy.

    below the code of my strategy

    #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;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class Screens : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0

    private int n=0;
    private int k=0;



    // User defined variables (add any user defined variables below)
    #endregion

    /// <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;
    AllowRemovalOfDrawObjects = true;
    }

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

    }

    protected override void OnExecution(IExecution execution)
    {

    foreach (IDrawObject draw in DrawObjects)
    {
    draw.Locked = false;
    }

    double price = execution.Price;
    double ts = TickSize;

    DrawArrowLine("k"+n,false,10,price+10*ts,0,price,C olor.Red,DashStyle.Solid, 2);
    DrawText("n"+k,false, ""+price, 10,price+10*ts,10,Color.Black,new Font("Calibri",14,FontStyle.Bold),StringAlignment. Center,Color.Transparent ,Color.Transparent,1);
    n=n+1;
    k=k+1;

    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    Hello,

    The strategy is only going to be aware of trades that were made by itself. It it is not aware of any trades that occur outside of the strategy, and there is not a supported method to obtain the executions that occurred for manual trades at this time.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Matthew, thank you for your reply.

      Then, how I can develop scripts which help me trade manually except ATM strategies?

      Are there any methods which connect/call account position?

      How can I capture any changes in account position, not strategy position?

      Which changes of my account position can I capture via strategy development?

      May I use any Indicator scrip methods to capture any manual changes? what are they?

      There should be a way to work with Account Position.

      Thank you in advance.

      Comment


        #4
        Originally posted by alex_bbfg View Post
        ... Then, how I can develop scripts which help me trade manually except ATM strategies?
        Is that not a contradiction in terms? Scripts, by definition are for automated trading, so you cannot use scripts to trade manually. No?

        Comment


          #5
          well, I'm just trying to trade, I am not good in terms. I need strategy/script/EA whatever that will help me to trade. I need something that will draw, calculate, alert and other support stuff. I guess that it is pretty clear.

          I am really appreciate if you have any ideas to help me.

          Comment


            #6
            Originally posted by alex_bbfg View Post
            well, I'm just trying to trade, I am not good in terms. I need strategy/script/EA whatever that will help me to trade. I need something that will draw, calculate, alert and other support stuff. I guess that it is pretty clear.

            I am really appreciate if you have any ideas to help me.
            All of those are simply indicators. You decide what you want to see/hear, and then you code it.

            NT indicators will not react to what you are doing manually. NT will give you the indication of the conditions that you have coded. You can then act on those indications from your coded indicator.

            Comment


              #7
              Hello alex_bbfg;339283,

              Thank you for your response.
              Originally posted by alex_bbfg View Post
              Then, how I can develop scripts which help me trade manually except ATM strategies?
              NinjaScript strategies are designed as automated strategies with no input. However, there are unsupported methods to do this. You can find an example of this at the following link: http://www.ninjatrader.com/support/f...d=5&linkid=490
              Originally posted by alex_bbfg View Post
              Are there any methods which connect/call account position?
              How can I capture any changes in account position, not strategy position?
              Which changes of my account position can I capture via strategy development?
              There are no supported methods to do this but an example of unsupported code for this is the following:
              Code:
              foreach (Account acct in Cbi.Globals.Accounts)
              {
              if (acct.Positions != null)
              {
              PositionCollection positions = acct.Positions;
              foreach (Position pos in positions)
              {
              Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice);
              }
              }
              Originally posted by alex_bbfg View Post
              May I use any Indicator scrip methods to capture any manual changes? what are they?
              Indicators are generally not used to check account or strategy positions. However, this may be possible with unsupported methods. You can also create strategies that do not take positions as well.

              Please let me know if I may be of further assistance.
              Last edited by NinjaTrader_PatrickH; 07-28-2013, 05:37 PM.

              Comment


                #8
                Hello PatrickH,

                thank you very much for your respornse it is very usefull. I will study exampels that you gave. Could you please give me the link to any information about unsupported NTScripts methods, libraries, interfaces, APIs...

                Traders, I'll realy appreciate any help.

                Comment


                  #9
                  Hello alex_bbfg,

                  Thank you for your response.

                  We do not have a resource on such information as it is unsupported/undocumented.

                  However, our users here on the Forum do have a thread dedicated to unsupported items. You can find it at the following link: http://www.ninjatrader.com/support/f...ad.php?t=22435

                  Comment


                    #10
                    Hell to all !

                    I did it! My script draws objects while I trade!

                    But the problem is that the script is removed all time I delete the object it drew and I have to launch the script again.

                    How to fix it? I'd like to delete objects which is drawn by the script and do not to rerun the script.

                    Comment


                      #11
                      Hello alex_bbfg,

                      Thank you for your post.

                      You can use AllowRemovalOfDrawObjects in order to manually remove objects that are drawn without disabling the strategy.

                      For information on AllowRemovalOfDrawObjects please visit the following link: http://www.ninjatrader.com/support/h...rawobjects.htm

                      Please let me know if I may be of further assistance.

                      Comment


                        #12
                        Hello PatrickH,

                        You helped me each time i had a problem, thank you very much. Could you please help me with my another issue.

                        My script draws all I want and I can delete it without rulounch the script. I use AllowRemovalOfDrawObjects as you adviced. But the script's drawn objects are deleted each time when I change the Instrument of a chart. At the same time objects drawn manualy are not deleted while I change the Instrument of a chart.

                        Is there any way to delete script's drawn objects without relounch the script and the objects are not deleted while change the Instrument of the chart?

                        Thank you in advance.

                        Comment


                          #13
                          Hello,

                          I'm not able to think of a way to preserve drawn objects on a reload off the top of my head. At least not any direct/supported way. This is because when you change the chart settings the scrip reloads itself. Upon the reload the drawn lines will have to be recalculated.

                          Only routes that come to mind for doing this would be writing the data to an external file and pulling it upon reload.

                          To delete drawn objects from the script you can use

                          or


                          Let me know if I can be of further assistance.
                          LanceNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by kaywai, Today, 07:09 AM
                          1 response
                          4 views
                          0 likes
                          Last Post NinjaTrader_ChristopherJ  
                          Started by SoCalFuturesFX, 11-06-2023, 11:08 AM
                          3 responses
                          218 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by HiddenPhilosopher, 05-22-2020, 01:09 AM
                          26 responses
                          2,713 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by Uregon, Today, 03:44 AM
                          1 response
                          5 views
                          0 likes
                          Last Post NinjaTrader_ChristopherJ  
                          Started by sofortune, 05-16-2024, 11:45 PM
                          6 responses
                          44 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Working...
                          X