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

Add-on and other confusion

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

    Add-on and other confusion

    I'm still trying to get up to speed with Ninjascript and I am confused about a few things. My eventual goals are:
    1. To create custom trading buttons that will for example buy at the high of the last bar.
    2. To leverage ATM, or create my own Stop/Targets based on ATR or MA levels.
    I downloaded the example code for trade buttons from here: Developer Example - Chart Order Buttons (ninjatrader.com)
    The comments in the Indicator example say that it is using the Add-On approach.

    Question 1:
    What in the code makes it an Add-On and not an indicator? Or what code is the "Add On Approach"?

    For topic 2 above where I want to use my own stop and targets, how do I detect that an order was filled? For example, when I do right click on the chart and place a limit order. Normally when it is filled, the ATM will take over.

    Question 2:
    To detect that an order was filled, do I use the ExecutionUpdate and/or OrderUpdate methods under the Account Class in Add-ons? Account Class
    ​What about the OnExecutionUpdate and OnOrderUpdates under Strategies. Do those work ONLY in Strategies?

    Now with regard to my custom stop and targets, I have been looking into two options.
    1. To update the stop and targets in the ATM strategy
    2. Create and manage my own stops and targets

    Question 3:
    To leverage ATM strategy approach and use my own stop and targets, would using the AtmStrategyChangeStopTarget from ATM_Strategies be the way to do it? Or is this also only available in a Strategy?

    Question 4:
    To create my own, is the best place to put those in OnExecutionUpdate or OnOrderUpdates?
    Then it look like there are also different flavors of ExecutionUpdate and OrderUpdates depending on if this is an Add-on, Indicator, or strategy.

    Question 5:
    Is this correct and are there some guidelines which would help me decide if I should use an Add-on, Indicator or Strategy?

    Question 6:
    Lastly which is probably making me sound quite dumb, but if I create an Add-On, how to I add it to the chart? I only see an option for Indicator and Strategy. I guess this ties into my first question above, what code in that Indicator example, makes it an Add-on?

    #2
    Hello sevensa,

    Thank you for your post.

    I am glad to help clear up your confusion; please see my answers below:

    Question 1:
    What in the code makes it an Add-On and not an indicator? Or what code is the "Add On Approach"?

    For topic 2 above where I want to use my own stop and targets, how do I detect that an order was filled? For example, when I do right click on the chart and place a limit order. Normally when it is filled, the ATM will take over.

    The "Add On Approach" refers to utilizing the Account class, which is found in the Add On section of the help guide but can apply to other types of scripts (such as an indicator) as well:Using the Account class with the "Add On Approach" in a script means you would need to create logic that subscribes to Order, Execution, and Position update events (these items are listed under the Account link above). Then, you would be able to use CreateOrder(), Submit(), Change(), and Cancel() to create/submit/modify/cancel orders. You could use the execution update events to detect when an order is filled and then submit your own stops and targets with logic in the indicator.
    ​​​​​Question 2:
    To detect that an order was filled, do I use the ExecutionUpdate and/or OrderUpdate methods under the Account Class in Add-ons? Account Class
    ​What about the OnExecutionUpdate and OnOrderUpdates under Strategies. Do those work ONLY in Strategies?

    Correct, you would use the update events under the Account class. These differ slightly from the event methods in strategies, as those only work in strategies to detect strategy-generated orders.
    Now with regard to my custom stop and targets, I have been looking into two options.
    1. To update the stop and targets in the ATM strategy
    2. Create and manage my own stops and targets

    Question 3:
    To leverage ATM strategy approach and use my own stop and targets, would using the AtmStrategyChangeStopTarget from ATM_Strategies be the way to do it? Or is this also only available in a Strategy?

    You could use an ATM strategy in an addon by submitting the order via StartAtmStrategy():


    With that said, if you would like to use your own stops and targets that are not defined by an ATM strategy you are likely better off creating your own orders with CreateOrder(), submitting them wiht Submit(), and modifying them with Change() as needed based on your logic.
    Question 4:
    To create my own, is the best place to put those in OnExecutionUpdate or OnOrderUpdates?
    Then it look like there are also different flavors of ExecutionUpdate and OrderUpdates depending on if this is an Add-on, Indicator, or strategy.
    For your own stops and targets, it is typically better to put those in OnExecutionUpdate() when you see an execution to fill the entry order. Submitting stops and targets in OnExecutionUpdate() ensures quick submission of the protective orders once the entry is filled, rather than waiting for the next call to OnBarUpdate().
    Question 5:
    Is this correct and are there some guidelines which would help me decide if I should use an Add-on, Indicator or Strategy?
    There are no specific guidelines, though if you plan to interact with manual orders it is best to use the AddOn approach to subscribe to an account and update events. This could be done in any of the three script types mentioned, however.
    Question 6:
    Lastly which is probably making me sound quite dumb, but if I create an Add-On, how to I add it to the chart? I only see an option for Indicator and Strategy. I guess this ties into my first question above, what code in that Indicator example, makes it an Add-on?
    ​AddOns are enabled once you start the platform. For this use case, it is likely going to be best to go with an indicator and apply that indicator to the desired charts where you'd like the buttons and your custom stop/target logic to apply.

    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Thank you NinjaTrader_Emily. This was tremendously helpful!

      Comment


        #4
        After digging into this more, I have a couple of follow-up questions.

        I have a created an indicator with the add-on code with two simple buttons. One to buy at market and one to close at market. The market close works well and close orders placed from the Buy Market Button on ChartTrader also. However, it also close trades that I placed on another chart with another timeframe of the same symbol in the same account. Is there a way to control only the trades on the chart that I have added the indicator? Or is this Add-on approach not the best for this situation and I would be better off to use a strategy which seems to provide more control over individual trades?

        Here is the code for the Market Close.
        Close at Market Code:
        Code:
                        Order marketClose = account.CreateOrder(Instrument, OrderAction.Sell, OrderType.Market, OrderEntry.Manual, TimeInForce.Day, 1, 0, 0, string.Empty, string.Empty, new DateTime(), null);
                        account.Submit(new Order[] { marketClose} );
                        Print("Close Button Clicked");​
        ​​

        My second question:
        When I monitor the trade events in ExecutionUpdate of the Account Class so that I can place my stop and target, how do I know that the trade triggered in the event is an opening trade and not a closing trade? I thought I could use MarketPosition to determine this, but it seems like the value is Long for both Buy and BuytoCover and Short for both Sell and SellShort. I checked it with this:

        Code:
                private void OnExecutionUpdate(object sender, ExecutionEventArgs e)
                {
                 // Output the execution
                    
                    NinjaTrader.Code.Output.Process(string.Format("Instrument: {0} Quantity: {1} Price: {2} MarketPosition: {3}",
                    e.Execution.Instrument.FullName, e.Quantity, e.Price, e.MarketPosition), PrintTo.OutputTab1);
                }​

        Comment


          #5
          Hello sevensa,

          Thank you for your note.

          I have a created an indicator with the add-on code with two simple buttons. One to buy at market and one to close at market. The market close works well and close orders placed from the Buy Market Button on ChartTrader also. However, it also close trades that I placed on another chart with another timeframe of the same symbol in the same account. Is there a way to control only the trades on the chart that I have added the indicator? Or is this Add-on approach not the best for this situation and I would be better off to use a strategy which seems to provide more control over individual trades?
          The Add-On approach will be agnostic to whether an order is placed from the same chart where your buttons are being clicked or if there are working orders/an open position for the same instrument and account generated on another chart. Whether you are trading manually or automatically on two charts for the same instrument and account, the positions are not separate. If you plan to trade the same instrument separately, one position based on buttons with your add on in one timeframe, and a second position on another chart with another timeframe, then I suggest using separate accounts. Using a strategy would not be a remedy/solution for this either; it doesn't necessarily "provide more control over individual trades" in the sense that you could trade the strategy on one chart and also manually trade the instrument on another chart. Any orders placed on one chart would affect the position anywhere in the platform for the same account and instrument.
          You could consider handling order objects for orders placed on the desired chart in question, and keep track of the position whether it is long/short/flat from the orders placed on that chart only and then when you enter/exit you could base the logic off of the position you are keeping track of for that one chart, but that still does not prevent the logic from interfering with where the position is reported anywhere else in the platform.

          When I monitor the trade events in ExecutionUpdate of the Account Class so that I can place my stop and target, how do I know that the trade triggered in the event is an opening trade and not a closing trade? I thought I could use MarketPosition to determine this, but it seems like the value is Long for both Buy and BuytoCover and Short for both Sell and SellShort.
          The Execution object has a MarketPosition that reports the "position" of the execution which is either long or short depending on whether it is a buy or sell order. A position object gives MarketPosition information based on the instrument and account and whether the position is long, short or flat. Otherwise, you could also consider manually keeping track of the position in your logic by using an int to determine the sumFilled in either the long or short direction. If there is a buy execution, you could add to the int, and if there is a sell execution you could subtract from the int.

          Please let us know if we may be of further assistance.
          Emily C.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Philippe56140, Today, 02:35 PM
          0 responses
          1 view
          0 likes
          Last Post Philippe56140  
          Started by 00nevest, Today, 02:27 PM
          0 responses
          1 view
          0 likes
          Last Post 00nevest  
          Started by Jonafare, 12-06-2012, 03:48 PM
          5 responses
          3,986 views
          0 likes
          Last Post rene69851  
          Started by Fitspressorest, Today, 01:38 PM
          0 responses
          2 views
          0 likes
          Last Post Fitspressorest  
          Started by Jonker, Today, 01:19 PM
          0 responses
          2 views
          0 likes
          Last Post Jonker
          by Jonker
           
          Working...
          X