Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get stop and target levels for an order

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

    Get stop and target levels for an order

    At the moment, I do a screenshot after every trade has completed.
    As I enter a trade, I mark my entry, stop and target levels with a line.
    This helps my post analysis.

    I want to automate this so that when the trade is over all I have to do is quickly type in a brief analysis and then save the chart (and then manually delete the target and stop levels).

    At execution time, how do I retrieve these 3 levels so that I can then (via c#) mark the levels with lines or use the risk reward method to mark my chart?

    I have tried so many different things but just not getting this right. Last one I tried was GetAtmStrategyStopTargetOrderStatus() but the usual message of "The name xyz does not exist in the current context" (in fact I get this error message for most of the samples I find in the support guide)

    Any help would be appreciated.
    Last edited by Grantx; 04-10-2017, 03:49 AM.

    #2
    Hello Grantx, and thank you for your question. Since you are using ATM strategy methods, I would like us to first examine exactly how you are calling methods such as GetAtmStrategyStopTargetOrderStatus. Do you also have an ATM strategy template whose name matches your second argument into this method?

    If so, then names matching the following regular expression (linked documentation publicly available) should work as the first "order name" argument :

    Code:
    [FONT=Courier New]
    "^([sS][tT][oO][pP]|[tT][aA][rR][gG][eE][tT])[1-9][0-9]*$"[/FONT]
    The case insensitive word "stop" or "target" comprises the name part, and the numbers at the end comprise the index part, with 1 as the first index. The index will refer to the numbered profit target / stop loss / quantity / stop strategy set in your ATM strategy. If we take the name, convert it to lowercase, and it is exactly the word "stop", your stop target order status at that index will be retrieved, otherwise, if the lowercase converted name is the word "target", your profit target order status will be retrieved.

    As an example, let's imagine you have the ATM strategy in the attached picture. if you wanted to retrieve the 2-tick stop loss, that would be

    Code:
    [FONT=Courier New]
    string[,] orders = GetAtmStrategyStopTargetOrderStatus("STOP1", "Example1690467");[/FONT]
    If I wanted to retrieve the 9-tick profit target, that would be

    Code:
    [FONT=Courier New]
    string[,] orders = GetAtmStrategyStopTargetOrderStatus("TARGET3", "Example1690467");[/FONT]
    If you are able to set up the pictured ATM strategy and neither of the above calls works for retrieving order status, or the above works but the code sample from the strategy guide (attached for convenience) does not work, or if there are any other questions we could answer, please let us know.

    Code:
    [FONT=Courier New]
    // http://ninjatrader.com/support/helpGuides/nt8/en-us/getatmstrategystoptargetorders.htm
    protected override void OnBarUpdate()
    {
        string[,] orders = GetAtmStrategyStopTargetOrderStatus("TARGET1", "[/FONT][FONT=Courier New][FONT=Courier New]Example1690467[/FONT]");
     
        // Check length to ensure that returned array holds order information
        if (orders.Length > 0)
        {
            for (int i = 0; i < orders.GetLength(0); i++)
            {
                  Print("Average fill price is " + orders[i, 0].ToString());
                  Print("Filled amount is " + orders[i, 1].ToString());
                  Print("Current state is " + orders[i, 2].ToString());
            }
        }
    }[/FONT]
    Attached Files
    Last edited by NinjaTrader_JessicaP; 04-10-2017, 07:34 AM.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JessicaP View Post
      Hello Grantx, and thank you for your question. Since you are using ATM strategy methods, I would like us to first examine exactly how you are calling methods such as GetAtmStrategyStopTargetOrderStatus. Do you also have an ATM strategy template whose name matches your second argument into this method?

      If so, then names matching the following regular expression (linked documentation publicly available) should work as the first "order name" argument :

      Code:
      [FONT=Courier New]
      "^([sS][tT][oO][pP]|[tT][aA][rR][gG][eE][tT])[1-9][0-9]*$"[/FONT]
      The case insensitive word "stop" or "target" comprises the name part, and the numbers at the end comprise the index part, with 1 as the first index. The index will refer to the numbered profit target / stop loss / quantity / stop strategy set in your ATM strategy. If we take the name, convert it to lowercase, and it is exactly the word "stop", your stop target order status at that index will be retrieved, otherwise, if the lowercase converted name is the word "target", your profit target order status will be retrieved.

      As an example, let's imagine you have the ATM strategy in the attached picture. if you wanted to retrieve the 2-tick stop loss, that would be

      Code:
      [FONT=Courier New]
      string[,] orders = GetAtmStrategyStopTargetOrderStatus("STOP1", "Example1690467");[/FONT]
      If I wanted to retrieve the 9-tick profit target, that would be

      Code:
      [FONT=Courier New]
      string[,] orders = GetAtmStrategyStopTargetOrderStatus("TARGET3", "Example1690467");[/FONT]
      If you are able to set up the pictured ATM strategy and neither of the above calls works for retrieving order status, or the above works but the code sample from the strategy guide (attached for convenience) does not work, or if there are any other questions we could answer, please let us know.

      Code:
      [FONT=Courier New]
      // http://ninjatrader.com/support/helpGuides/nt8/en-us/getatmstrategystoptargetorders.htm
      protected override void OnBarUpdate()
      {
          string[,] orders = GetAtmStrategyStopTargetOrderStatus("TARGET1", "[/FONT][FONT=Courier New][FONT=Courier New]Example1690467[/FONT]");
       
          // Check length to ensure that returned array holds order information
          if (orders.Length > 0)
          {
              for (int i = 0; i < orders.GetLength(0); i++)
              {
                    Print("Average fill price is " + orders[i, 0].ToString());
                    Print("Filled amount is " + orders[i, 1].ToString());
                    Print("Current state is " + orders[i, 2].ToString());
              }
          }
      }[/FONT]

      Excellent thank you Jessica. That all makes perfect sense. I wasn't using the template name when executing the method so that was my first mistake. The only thing is if I have a few different ATM strategies which I apply as circumstance permits, how do I find out the name of the current strategy being used, which I can then use to execute the code sample you provided?

      Comment


        #4
        I am glad were able to make progress toward a working strategy. The functionality you're describing would need to be done from an add-on. Essentially you would need to

        • Find an Automation ID for the ATM Strategy Selector pull-down menu
        • Retrieve the currently selected ATM strategy from this pull-down
        • Repeat this process from every window type that can have an ATM strategy, that you intend on using, such as
          • Basic Entry
          • Chart Trader
          • SuperDOM


        Due to the code work involved in all of the above, and the fact that your strategy will be managing its own instance of a hidden ATM strategy that is completely independent of any user accessible ATM strategies, it is encouraged that you select a hard-coded name for your ATM strategy that your NinjaScript code uses and that you, as a user, do not.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_JessicaP View Post
          Due to the code work involved in all of the above, and the fact that your strategy will be managing its own instance of a hidden ATM strategy that is completely independent of any user accessible ATM strategies, it is encouraged that you select a hard-coded name for your ATM strategy that your NinjaScript code uses and that you, as a user, do not.
          I think you misunderstand me. I dont want to execute am ATM strategy from code. I have ATM strategies pre-defined already. The thing is that there a few different strategies. So depending on the circumstances, I will manually enter a trade, and a predefined ATM is executed. When this happens, I just want to put lines in where my stop and target are. So Im not doing any ATM stuff fro code, simply retreiving the settings of whatever the currently executed ATM strategy is.

          Comment


            #6
            Thank you for this added information and for helping me get on the same page.

            As you will need to specify an ATM strategy template when you first create your strategy, with AtmStrategyCreate, the only way you will have available is to retain a reference to the template name you passed in.

            There is currently not a way to get a list of available templates from NinjaScript code.

            In the code sample @SampleATMStrategy.cs , you will see that we have selected a unique name, "AtmStrategyTemplate", and have simply hard-coded this everywhere the template name is required. We also include this comment in our sample,

            Code:
            [FONT=Courier New]
                        // **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'AtmStrategyTemplate' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK ****[/FONT]
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_JessicaP View Post
              Thank you for this added information and for helping me get on the same page.

              As you will need to specify an ATM strategy template when you first create your strategy, with AtmStrategyCreate, the only way you will have available is to retain a reference to the template name you passed in.

              There is currently not a way to get a list of available templates from NinjaScript code.

              In the code sample @SampleATMStrategy.cs , you will see that we have selected a unique name, "AtmStrategyTemplate", and have simply hard-coded this everywhere the template name is required. We also include this comment in our sample,

              Code:
              [FONT=Courier New]
                          // **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'AtmStrategyTemplate' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK ****[/FONT]
              Cool.
              Thanks for your help Jessica. Ill play around with this. I will just have to have a naming convention for my ATM strategies and at execution time, loop through until I find the matching one.

              Comment


                #8
                See attached error Jessica
                The name getatmstoptrategy does not exist in the current context.
                Attached Files

                Comment


                  #9
                  Thank you for this added information Grantx. If we review the documentation for GetAtmStrategyStopTargetOrderStatus, we find that this is a strategy method. Please see the circled sections in the attached image to understand the way the help guide is organized. Items in the Common section are available to both Indicators and Strategies. Items under Strategies are only available to Strategies.



                  I believe since I understand now that we are doing this from an indicator that is not managing ATM strategy orders that I may not fully understand our goals as well as I thought I did. Could I ask for a brief explanation as to what this indicator is designed to do? I'll be happy to assist further, and I feel the answer to this question will allow me to provide better help.
                  Attached Files
                  Jessica P.NinjaTrader Customer Service

                  Comment


                    #10
                    Oh I see now. Apologies for the slow start Im starting to understand.


                    Basically, I am a discretionary trader. I have ATM strategys that I have setup from chart trader.
                    When I enter a trade, whichever ATM I have selected fires. As per the screenshot.
                    When that happens, there are stops and target lines which the ATM strategy draws on the chart.
                    I want to draw similar lines at those exact positions, so that when the trade is finished, the lines remain. Then, I enter a brief explanation text, and save the chart for my records.

                    I realise I can do this manually but this is an introductory project for me to learn the ways of ninjascript, I understand this must be frustrating for you.
                    Attached Files

                    Comment


                      #11
                      It is not frustrating at all, and I do appreciate your taking the time to explain our goal. I believe there are some parts of the way NinjaScript managed ATM strategy methods work that I can better explain.

                      The methods such as GetAtmStrategyStopTargetOrderStatus are designed for ATM strategies your script launches "behind the scenes". When your script turns on, rather than using SetProfitTarget and SetStopLoss calls to manage its profit target and stop loss orders, respectively, it will instead use the logic in your ATM strategy to manage its profit target and stop loss orders. These orders are completely invisible to you as a user except through the Orders and Positions tabs in the Control Center. They are placed by your strategy, managed by your strategy, and if you modify them outside your strategy through the Orders and Positions tabs, your strategy will automatically be disabled.

                      The kind of orders you are referring to - for example, when you are using chart trader, you place a trade, and have an ATM strategy template selected - are not related in any way to methods such as GetAtmStrategyStopTargetOrderStatus . Strategies can only use GetAtmStrategyStopTargetOrderStatus to look at its own managed ATM strategy orders, not ones you as a user are managing through something like Chart Trader.

                      This is the thrust of the advice I gave in post #4. If you'd like to know where a user managed ATM strategy's orders are at, you'll have to use our add-on framework to get this information. This can be done through an indicator, but this is an advanced coding challenge. Every element visible to you as a user is an element that can be accessed through code through the WPF framework. For example, in Chart Trader, if I want to know what the green (or red, if short) position indicator is showing, its unique WPF ID is ChartTraderControlPositionQuantityText . In your case, the advice my colleague Jesse gave in the earlier link would have led you to learn that the menu which shows which ATM strategy is selected currently is called
                      ChartTraderControlATMStrategySelector . Playing around with the IntelliSense feature in the NinjaScript editor, you would also eventually learn that the class associated with this is called
                      NinjaTrader.Gui.NinjaScript.AtmStrategy.AtmStrateg ySelector . Learning which ATM strategy you have open, you could then review your open orders using the add-on Account.Orders object,



                      And finally you'd be able to match up which orders were attached to your currently selected ATM strategy.

                      I regret that the above is very dense, and that there is a lot of jargon. I will be happy to further explain any part of that that I may.

                      However, essentially, the situation is that some of the information in the help guide was not presented in a way that was obvious to you as a customer, and you have a valid use case in wanting to get information regarding an ATM strategy from an indicator. I prefer resolving queries like this with a feature request, so that a more obvious and simple path is available to you. With this in mind, I have requested the following feature from the product management team.

                      This customer would like NinjaTrader.Gui.NinjaScript.AtmStrategy.AtmStrateg ySelector information available from a direct property of NinjaTrader.NinjaScript.Indicators.Indicator

                      Where this feature available, there would be a simple method such as the method you attempted to call initially, which would give you information about the selected ATM strategy from an indicator, that would work exactly the way you were attempting to use it.

                      Please let us know if there are any other ways we can help.
                      Jessica P.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello Grantx,

                        This feature is being reviewed by the product management team and has been assigned the following unique tracking ID


                        SFT-2152


                        Please let us know if there is any other way we can help.
                        Jessica P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by rajendrasubedi2023, Today, 09:50 AM
                        2 responses
                        13 views
                        0 likes
                        Last Post rajendrasubedi2023  
                        Started by geddyisodin, Today, 05:20 AM
                        4 responses
                        28 views
                        0 likes
                        Last Post geddyisodin  
                        Started by geotrades1, Today, 10:02 AM
                        2 responses
                        8 views
                        0 likes
                        Last Post geotrades1  
                        Started by ender_wiggum, Today, 09:50 AM
                        1 response
                        5 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by bmartz, Today, 09:30 AM
                        1 response
                        10 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Working...
                        X