Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

converting indicator to strategy

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

    #46
    roland, orderId and atmStrategyId are available and in place until you reset them to be emtpy and therefore cleared. You can change all stops and targets of your ATM programmatically, STOP1, STOP2 and STOP3 would be the 3 stop value for the targets defined in the template, TARGET1, TARGET2 and TARGET 3 the corresponding exits / targets - those need to be used exactly like this, as the method requires this as string parameter.

    Comment


      #47
      converting indicator to strategy - reversing

      Bertrand:
      Thanks for the clarification about the meaning of the digits in STOP2 etc.
      The help documentation does not explicitly mention your facts about the digits
      Ok - I now can control my targets and stops.

      Per your instructions I am not setting the originating trade's orderId to empty.
      But the order status obtained by
      GetAtmStrategyEntryOrderStatus(orderId) is only showing the price of the
      very first trade of the series of reverses it never changes
      The GetATMStrategyStopTargetOrderStatus will show the fill price at the
      reversed target. Should I assume that target fill price is the equivalent
      of the fill price for the entry on the new (reversed) position?
      Or is there a different way to get the fill prices of the successive reverses?

      Comment


        #48
        converting indicator to strategy - reversing

        Very strange things are happening. Bottom line is that is that control of this process is till elusive and I cannot verify control is possible.
        Here is a debug printout at the moment a reverse is hit:with Reverse at Target set in the ATM strategy in the superdom. First is the sample debug print out followed by an explanation followed by the code.

        A) 9702 ATM STATE LONG Indicator State SHORT
        B) 9702 Target Status fill price is 0 Qty 0 Target state is Working

        (next tick)

        C) 9702 Order State avg fill price is: 1178.5 qty: 1 status: Filled Indicator State SHORT
        D) 9702 ATM STATE Flat Indicator State SHORT

        (many ticks later)

        E) 9702 Order State avg fill price is: 1178.5 qty: 1 status: Filled Indicator State SHORT
        9702 ATM STATE Flat Indicator State SHORT
        F) 9702 Order State avg fill price is: 1178.5 qty: 1 status: Filled Indicator State SHORT

        Explanation:
        Line A: at bar 9702 the indicator reads price correctly as being short
        ATM state has not yet changed form the first LONG entry - all OK so far
        Line B The target status is shown as working, which is correct as target order has not been filled yet
        Line C Order state shows first leg LONG entry price 1178.5 which is not correct because we are now short according to the SuperDom
        Line D Shows ATM strategy as Flat which is not what the SuperDom says
        Line E (many ticks or bars later) Still shows ATM strategy Flat although reverse is well in progress.. No target status is printing because the return from GetAtmStrategyStopTargetOrderStatus("TARGET1", atmStrategyId); is empty.
        Line F still showing orderId incorrectly reporting first LONG entry price.

        Here is the code called on every tick that prints the above:
        protected void checkOrderStatus() {
        MarketPosition mPos;
        if (orderId.Length > 0)
        {
        string[] status = GetAtmStrategyEntryOrderStatus(orderId);

        // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
        if (status.GetLength(0) > 0)
        {
        ordState = status[2];
        ordFill = status[1];
        ordEntPrice = status[0];
        // Print out some information about the order to the output window
        Print(CurrentBar + " Order State " +
        " avg fill price is: " + status[0] +
        " qty: " + status[1] + " status: " + status[2] +
        " Indicator State " +
        (trade[1] == LONG ? "LONG " : (trade[1] == SHORT ? "SHORT" :"Flat")) +
        " ");

        // If the order state is terminal, reset the order id value
        // if (status[2] == "Filled" || status[2] == "Cancelled" ||
        // status[2] == "Rejected")
        // orderId = string.Empty;
        // for mirroring
        if (status[2] == "Cancelled" || status[2] == "Rejected")
        orderId = string.Empty;
        }
        } // If the strategy has terminated reset the strategy id
        else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
        {
        atmStrategyId = string.Empty;
        ordState = "Flat";
        }
        if (atmStrategyId.Length > 0) {
        mPos = GetAtmStrategyMarketPosition(atmStrategyId);

        if (mPos == MarketPosition.Flat) ordState = "Flat";
        if (mPos == MarketPosition.Long) ordState = "LONG";
        if (mPos == MarketPosition.Short) ordState = "SHORT";

        Print(CurrentBar + " ATM STATE " + ordState + " Indicator State " +
        (trade[1] == LONG ? "LONG " : (trade[1] == SHORT ? "SHORT" :"Flat")) +
        " ");
        string[,] orders = GetAtmStrategyStopTargetOrderStatus("TARGET1", atmStrategyId);

        // Check length to ensure that returned array holds order information
        if (orders.Length > 0)
        {
        for (int i = 0; i < orders.GetLength(0); i++)
        {
        Print(CurrentBar + " Target Status fill price is " + orders[i, 0].ToString() +
        " Qty " + orders[i, 1].ToString() +
        " Target state is " + orders[i, 2].ToString());
        }
        }
        }

        }

        Comment


          #49
          Hi Roland, could you please send the strategy and ATM strategy template saved you test with so I can give it a run on my end here? You can reach me at support at ninjatrader dot com Attn Bertrand -

          Thanks,

          Comment


            #50
            converting indicator to strategy - reversing

            Bertrand:
            how do I save the ATMstrategy template in a form that can be e-mailed. Where do I look in the normal MyDocuments files.

            Comment


              #51
              Hi Roland, you could unfortunately not export them, they are part of your database, if you just take a screenshot of the setup that would do as well to reproduce here.

              Thanks,

              Comment


                #52
                converting indicator to strategy - enum name collisions

                Both the indicator and the converted strategy use an enum.
                When i save the indicator under a new name (actually a new version. for example, TrenIndiactor23 saved as TrendIndicator24) I get a compile error about dupe name in the global name space. That means that every new version has to have a new enum name in order to avoid the collision. It is doable, but a bit of a bookkeeping chore.
                However when I save the equivalent strategy as a new version, (TrendIndicatorATM23 saved as TrendindicatorATM24) I get no such message. The enum name never has o be changed.

                What;s going on? Am I placing the the enum in the wrong physical place? (I followed the reference sample).

                Comment


                  #53
                  Hi Roland, yes if the enums are employed as in the reference sample, they need to be uniquely named per script as they are residing in the global namespace. The strategy just calls the indicators, correct?

                  Comment


                    #54
                    converting indicator to strategy - enum name collisions

                    Bertrand:
                    No, the strategy does NOT call the indicator. The strategy duplicates, line for line, all functions of the indicator (for a variety of reasons). Essentially it is the complete indicator code PLUS some calls to GetAtmStrategyUniqueId() and related stuff.

                    When saving under a new name.and then compiled, the strategy never complains about the need to rename the enum. This asymmetry is puzzling.

                    Comment


                      #55
                      Originally posted by roland_nt View Post
                      Bertrand:
                      No, the strategy does NOT call the indicator. The strategy duplicates, line for line, all functions of the indicator (for a variety of reasons). Essentially it is the complete indicator code PLUS some calls to GetAtmStrategyUniqueId() and related stuff.

                      When saving under a new name.and then compiled, the strategy never complains about the need to rename the enum. This asymmetry is puzzling.
                      Which would lead me to believe that your indicator has the enum defined in it, while the enum is not defined in your strategy. That is the problem with defining the enum in the global namespace: it MUST be defined once and only once, and in only ONE file.

                      As it is in the global namespace, it will then be always available, but ONLY on the installation where it was defined. In other words, basically, as long as the file in which you define the enum is in a given NT installation, all files that need the enum will find it: if that definition file is missing (as in you did not give the file to someone to whom you gave any file that depends on the enum), you will get a message about the missing definition.

                      Comment


                        #56
                        converting indicator to strategy - enum name collisions

                        koganam.

                        Thanks for you comments which illuminated the way out.

                        Indeed, the enum values were defined (identically) in both indicator and startegy, a situation whose consequences I was unaware of. As soon as I commented out one of the definitions (in this case in the strategy) but not the usage, the collisions went away and solved my problem.

                        I was following the reference sample, which is a global organization.. I don't NEED the enum to be global though. I just couldn't figure out how to modify the reference sample to make it local. - where to place the definition lines in the code in such a way to make it local in either the indicator and strategy. All the combinations I tried got reference failures. Is there some magic to make a local enum definition?

                        Again, many thanks.

                        Comment


                          #57
                          Originally posted by roland_nt View Post
                          koganam.

                          Thanks for you comments which illuminated the way out.

                          Indeed, the enum values were defined (identically) in both indicator and startegy, a situation whose consequences I was unaware of. As soon as I commented out one of the definitions (in this case in the strategy) but not the usage, the collisions went away and solved my problem.

                          I was following the reference sample, which is a global organization.. I don't NEED the enum to be global though. I just couldn't figure out how to modify the reference sample to make it local. - where to place the definition lines in the code in such a way to make it local in either the indicator and strategy. All the combinations I tried got reference failures. Is there some magic to make a local enum definition?

                          Again, many thanks.
                          • Define a local namespace in the indicator file
                          • Place the enum in that namespace
                          • Write a "using" directive to use the namespace.

                          To make it easy to track, here is how I do it. Assume my indicator is called Rex. Then this code goes right under the "Using declarations" region and before the NinjaTrader.Indicator namespace.

                          Code:
                          using _nsRex;
                          
                          namespace _nsRex
                          {
                          public enum ExampleEnum
                               {
                                    enum1,
                                    enum2,
                                    enum3
                               }
                          }
                          If you look here, you will find threads in which we have had a long dicussion about this. http://www.ninjatrader.com/support/f...earchid=954877
                          Last edited by koganam; 02-15-2011, 04:07 PM.

                          Comment


                            #58
                            converting indicator to strategy - enum name collisions

                            koganam
                            Thanks again for taking the time to lay this out. You're a prince.

                            It was very helpful. I set it up the definition in the indicator and just did the "using" line in the strategy. I'd guess this is tidier than cluttering up global names.

                            The link you gave doesn't give a hit when I click on it. I'd like to read it.. Is there a typo?

                            Thanks again.

                            Comment


                              #59
                              Originally posted by roland_nt View Post
                              koganam
                              Thanks again for taking the time to lay this out. You're a prince.

                              It was very helpful. I set it up the definition in the indicator and just did the "using" line in the strategy. I'd guess this is tidier than cluttering up global names.

                              The link you gave doesn't give a hit when I click on it. I'd like to read it.. Is there a typo?

                              Thanks again.
                              Do any of these work?








                              If not, then just just do a search on pollute global namespace, as a word string, not as a phrase.
                              Last edited by koganam; 02-15-2011, 09:42 PM.

                              Comment


                                #60
                                converting indicator to strategy - enum name collisions

                                The first link didn't work. The rest did.
                                Funny why some of the NT support staff seems to
                                disparage the namespace idea..
                                Maybe there is such a thing as polluting the namespace namespace?

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                647 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                368 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                108 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                571 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                573 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X