Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unique Entries?

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

    #46
    Thank you for your expertise. You have answered my question.

    In the OnOrderUpdate()
    under the buy1entry ="Filled" property goes
    Buy_1MarketPosition = MarketPosition.Long;

    and

    under the buy1target or buy1stop ="Filled" property goes
    Buy_1MarketPosition = MarketPosition.Flat;

    "We advise monitoring OnExecution() to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
    which ensures your strategy has received the execution which is used for internal signal tracking.
    "

    Question
    3. Why not the same "Filled" properties in OnExecution() instead of OnOrderUpdate?

    Comment


      #47
      Hello,

      No problem.

      You do have the same Filled properties in both. Essentially I recommend only working in OnOrderUpdate(). Only submitting orders for stops and targets in OnExecution().

      -Brett

      Comment


        #48
        Thank you Brett, I'll give this a shot

        By the way Joydeep mentioned:
        Also, OrderState.Cancelled or OrderState.Rejected is not updated in OnExection event. They are triggered in OnOrderUpdate event.
        http://www.ninjatrader.com/support/h...rderupdate.htm

        If this is true why are you using the cancel property in OnExecution?
        Last edited by kenb2004; 04-03-2012, 11:30 AM.

        Comment


          #49
          We reviewed the sample and decided to make no changes as its simply filtering in the case that it did occur. It is technically possible that it could happen however in almost 100% of the time that sequence of events would not occur as Joydeep found and mentioned on. Its better to code to protect yourself and be ready for an unknown event as this is code coding practice with event driven code, bottom line is use OnOrderUpdate() for order state information.

          -Brett

          Comment


            #50
            Brett
            Thanks again for your expertise and the sample. I've incorporated your principles for "Position Tracking" and everything tracks well with one exception, "ClosePosition". If I have a circumstance where Sell_1 is Short and Buy_2 is true, then the Sell_1 position is "Closed" (Flat) and the Buy_2 position becomes long. The strategy performs properly but the "tracking" does not because this "reverse" was performed "Internally" in the Managed Approach" and the state of the Sell_1 is still "Short".

            In every case but "ClosePosition" I have "stop" and "target" IOrders that when "Filled" can generate a "Flat" position from OnOrderUpdate as you have shown. But because this "ClosePosition" is generated "Internally" I need a way to accurately track that the Sell_1, in this case, is "Flat".

            4. How do you Externally generate the equivilant market postion state for a "ClosePosition", for Flat order positions from limit orders?

            Thanks for your help.

            Comment


              #51
              Hello,

              No problem, glad you were able to work with the sample I provided.

              You could try finding that order in OnOrderUpdate by filtering by the name Close Position. However I would not recommend this I would recommend instead simply not using the internally generated close position and instead generating your own.

              Do this by when you are ready to reverse, if you have a profit target modify it down to be filled. This will close current position and set you back to flat.

              Then when flat submit the Entry to reverse.

              -Brett

              Comment


                #52
                Code:
                [FONT=Courier New]#region Varibles[/FONT][SIZE=2]
                [SIZE=2][FONT=Courier New]MarketPosition Position1 = MarketPosition.Flat; [/FONT][/SIZE]
                [SIZE=2][FONT=Courier New]MarketPosition Position2 = MarketPosition.Flat;[/FONT][/SIZE]
                [SIZE=2][FONT=Courier New]MarketPosition Position3 = MarketPosition.Flat;[/FONT][/SIZE]
                [SIZE=2][FONT=Courier New]#endregion[/FONT][/SIZE]
                 
                [SIZE=2][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] OnOrderUpdate(IOrder order){[/COLOR][/SIZE][/FONT]
                [/SIZE][/FONT][FONT=Courier New][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (buy1entry != [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] && buy1entry == order){ [/COLOR][/SIZE][/FONT][/SIZE][/FONT]
                [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (order.OrderState == OrderState.Filled){[/SIZE][/FONT][/SIZE][/FONT]
                [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Position1 = MarketPosition.Long; [/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]}}}[/FONT][/SIZE]
                [/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/SIZE][/FONT][/FONT][/SIZE][/SIZE]
                If I declare
                MarketPosition Position1 = MarketPosition.Flat;

                Is "Position1 = MarketPosition.Long;" Correct?
                Or does it need to be
                MarketPosition Position1 = MarketPosition.Long;

                Thanks

                Comment


                  #53
                  If your code is laid out like the code you quoted, it would be 'Position1 = MarketPosition.Long'

                  Comment


                    #54
                    Thanks, Radical

                    In the SamplePositionTracking.cs in this forum, it uses "private" in the variables where mine does not. Is this significant? The reason I ask is that my strategy is running fine in replay, but not in live demo. In the output window it Prints that Position1 is flat when it is long.

                    Comment


                      #55
                      I'm going to guess that the private keyword isn't causing your problem, especially because I think the default access level for a MarketPosition would be private anyway.

                      Edit: Actually I'm wrong about that, MarketPosition is public by default, but I would still be surprised if that was your problem....can you post the part of your code where you're having the problem?
                      Last edited by Radical; 08-02-2012, 10:10 AM.

                      Comment


                        #56
                        Private would matter if you had other indicators using the same name there could be collision. Suggest making these private for good measure as it only applies to that indicator anyways.

                        Also, insure you are not using position1 as if you use MarketPosition position1 this would create a new MarketPosition object that wouldn't be the same as the original one.

                        Comment


                          #57
                          So Brett

                          Back to post #52, which would be the best way to update position status in OnOrderUpdate?

                          "Position1 = MarketPosition.Long;"
                          or
                          "MarketPosition Position1 = MarketPosition.Long;"

                          Thanks

                          Comment


                            #58
                            "Position1 = MarketPosition.Long;"

                            Comment


                              #59
                              From post #51
                              You could try finding that order in OnOrderUpdate by filtering by the name Close Position.

                              How exactly would you do this?

                              Thanks

                              Comment


                                #60
                                Hello,

                                You can access this via this property in OnOrderUpdate()



                                Name
                                A string representing the name of an order which can be provided by the entry or exit signal name


                                iOrder.Name then check this against what you are looking for.



                                Let me know if I can be of further assistance.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by lightsun47, Today, 03:51 PM
                                0 responses
                                2 views
                                0 likes
                                Last Post lightsun47  
                                Started by 00nevest, Today, 02:27 PM
                                1 response
                                8 views
                                0 likes
                                Last Post 00nevest  
                                Started by futtrader, 04-21-2024, 01:50 AM
                                4 responses
                                41 views
                                0 likes
                                Last Post futtrader  
                                Started by Option Whisperer, Today, 09:55 AM
                                1 response
                                12 views
                                0 likes
                                Last Post bltdavid  
                                Started by port119, Today, 02:43 PM
                                0 responses
                                8 views
                                0 likes
                                Last Post port119
                                by port119
                                 
                                Working...
                                X