Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add ATM Strat to existing order help

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

    Add ATM Strat to existing order help

    Before I say what I would like to do I would like to say that Ninjatrader support already told me that it was not possible.

    I have an existing order with no ATM strategy attached to it. I would like to now add an ATM strategy to my existing order so that I can have a stop that can trail a winning trade. I know about adding an OCO order to my existing order but I want to trail after a certain amount of profit.

    Is there anything that any others have for me that may help? Can this be coded with a ninja script? For example.

    Add trail to existing order:
    (Trail Stop order)
    IF profit = 3 then move stop to desired location

    This seems like something that could be useful so that I do not need to monitor my trade after initially not having an ATM strategy.

    Dan

    #2
    Hi bengalvfan,

    Theoretically it would be possible to make a strategy that will throw on a stop loss and profit target for an existing order.

    This would require unsupported methods to complete.

    The following unsupported code can assist in finding a position to protect.

    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);
    }
    }

    Also, I am attaching a sample where I have made a button. This may help you as well if you want to click a button and create the orders.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the help but I am not even sure what I should be doing with that code and button to make it usable. I would like to learn how to do this though.

      I have some experience in visual basic but am unsure on what I need to do with the code and button given to me.

      Comment


        #4
        bengalvfan,

        The best way to begin learning NinjaScript is to use the Strategy Wizard. With the Strategy Wizard you can setup conditions and variables and then see the generated code in the NinjaScript Editor by clicking the View Code button.

        I'm also proving a link to a recently recorded 'Automated Strategy Development Webinar' video for you to view at your own convenience: Automated Strategy Development Level 1 - NinjaTrader Training - 3/26/2013

        We also have great resources in relation to Strategy Development on our Support Forum. There is a very active developer community in our support forum that supplements the responses provided by NinjaTrader support staff providing all users with an exceptional support experience.
        Take me to your support forum!

        There are a few Sample Automated Strategies which come pre-configured in NinjaTrader that you can use as a starting point. These are found under Tools--> Edit NinjaScript--> Strategy. You will see locked strategies where you can see the details of the code, but you will not be able to edit (you can though always create copies you can later edit via right click > Save as)

        We also have some Reference samples online as well as ‘Tips and Tricks’ for both indicators and strategies:
        Click here to see our NinjaScript Reference Samples
        Click here to see our NinjaScript Tips

        These samples can be downloaded, installed and modified from NinjaTrader and hopefully serve as a good base for your custom works.
        Last, if you would like to have this strategy coded for you, you may contact one of our professional NinjaScript consultants.
        Click here to see our Consultants page
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Chelsea,
          Regarding the ToolBar Button. I get an Object reference error when trying this. See attached file.
          Ideas?
          Attached Files

          Comment


            #6
            Hi tquinn,

            Are you compiling this in the NinjaScript Editor that is part of NinjaTrader?

            If not, do you get the same error in NinjaTrader?

            Also, are you using the same using calls at the top of the file as I am in the example?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I used NT Utilities to Import your zip file which was downloaded from this thread.

              I added the AToolBarButtonTriggerCustomEventTest strategy to a blank chart.

              Used VisualStudio in Debug Mode, the Using declaration from your code follow;

              #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

              Comment


                #8
                Hi tquinn,

                Do you get the same error if you compile the script I supplied in NinjaTrader and not in Visual Studio?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks for your patience:

                  I don't understand what I did wrong. It is working now.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by WHICKED, Today, 12:45 PM
                  2 responses
                  18 views
                  0 likes
                  Last Post WHICKED
                  by WHICKED
                   
                  Started by GussJ, 03-04-2020, 03:11 PM
                  15 responses
                  3,274 views
                  0 likes
                  Last Post xiinteractive  
                  Started by Tim-c, Today, 02:10 PM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by Taddypole, Today, 02:47 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post Taddypole  
                  Started by chbruno, 04-24-2024, 04:10 PM
                  4 responses
                  51 views
                  0 likes
                  Last Post chbruno
                  by chbruno
                   
                  Working...
                  X