Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnExecution syntax

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

    OnExecution syntax

    Can you please give me an example of the proper syntax using the OnExecution properties: MarketPosition and Price?
    Thanks

    #2
    Hello kenb2004,
    Please refer to these sample codes which implements the OnExecution event and the MarketPosition
    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()



    By price if you mean the last traded price then please refer to our help guide which further discusses it.


    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      I'm sorry Joydeep, but not one of the 3 samples you pointed me to demonstrate the proper syntax using the properties: MarketPosition and Price in the OnExecution() method.

      These are properties listed in NinjaTrader User guide, but I have no way of knowing how they are to be used without some sort of example.

      Thanks

      Comment


        #4
        Maybe this will help?

        Comment


          #5
          No, Joydeep, this does not help. These are properties listed in NinjaTrader User guide that I just mentioned and there are no examples of how to use them. The properties MarketPosition and Price, as used in OnExecution().

          All I'm looking for is any example syntax for these 2 properties.

          Thanks
          Last edited by kenb2004; 08-08-2012, 12:50 PM.

          Comment


            #6
            Example:

            if (execution.MarketPosition == MarketPosition.Long)
            Print(execution.Price.ToString());

            Comment


              #7
              Thanks

              How about Price?

              Comment


                #8
                Hello kenb2004,
                Can you describe a bit more about your exact requirement. Are you looking for the description for IExecution interface as Radical pointed out or is it something different


                @ Radical - Thanks for your input.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by kenb2004 View Post
                  Thanks

                  How about Price?
                  That example showed how to use the Price property.

                  Comment


                    #10
                    Hello kenb2004,
                    To find out the price you can use the below codes

                    Code:
                    double exPrice = execution.Price;
                    To get the price of the order
                    Code:
                    execution.Order.LimitPrice;
                    execution.Order.StopPrice;
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      Sure, after an execution of a buy entry IOrder, I am looking for the Position status of the execution. Ideally I would like to set a bool that says Long1 = true; when the buy entry is executed and I would like to set the execution Price to a double that can be used in a calculation.

                      Comment


                        #12
                        This is what I had in mind. Will this code work? Will the Buy1Long bool work in OnBarUpdate as Position status for Buy_1?
                        Code:
                        [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
                        [SIZE=2][FONT=Courier New][COLOR=#0000ff]protected[/COLOR][/FONT][/SIZE][/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] OnExecution(IExecution execution)[/COLOR][/SIZE][/FONT]
                        [SIZE=2][FONT=Courier New]{ [/FONT][/SIZE]
                        [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#region[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] buy1entry [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// *****************************************[/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]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (buy1entry != [/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] && buy1entry == execution.Order){ [/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]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (execution.Order.OrderState == OrderState.Filled){[/SIZE][/FONT]
                        [SIZE=2][FONT=Courier New]Buy1Long = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
                        [SIZE=2][FONT=Courier New]PrintWithTimeStamp([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]" - Buy_1 is Long"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/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]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] buy1entryPrice = execution.Price; [/SIZE][/FONT][/SIZE][/FONT]
                        [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Print(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]+[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]" - buy1entryPrice is "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]+buy1entryPrice);
                        [/SIZE][/FONT][/SIZE][/FONT][SIZE=2][FONT=Courier New]} [/FONT][/SIZE]
                        [/SIZE][/FONT][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] (execution.Order.OrderState == OrderState.PartFilled || [/SIZE][/FONT]
                        [SIZE=2][FONT=Courier New](execution.Order.OrderState == OrderState.Cancelled && [/FONT][/SIZE]
                        [SIZE=2][FONT=Courier New]execution.Order.Filled > [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])){ [/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]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (execution.Order.OrderState != OrderState.PartFilled){[/SIZE][/FONT]
                        [SIZE=2][FONT=Courier New]buy1entry = [/FONT][/SIZE][/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];[/SIZE][/FONT]
                        [SIZE=2][FONT=Courier New]} } }[/FONT][/SIZE]
                        [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#endregion[/COLOR][/SIZE][/FONT]
                        [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
                        Last edited by kenb2004; 08-08-2012, 01:38 PM.

                        Comment


                          #13
                          Hello,

                          Looks like it should work, however it would require testing to make sure everything works as you expect.

                          -Brett

                          Comment


                            #14
                            Thanks, I just needed to know if I was on the right track.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by funk10101, Today, 12:02 AM
                            0 responses
                            1 view
                            0 likes
                            Last Post funk10101  
                            Started by gravdigaz6, Yesterday, 11:40 PM
                            1 response
                            7 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by MarianApalaghiei, Yesterday, 10:49 PM
                            3 responses
                            10 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by XXtrader, Yesterday, 11:30 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post XXtrader  
                            Started by love2code2trade, 04-17-2024, 01:45 PM
                            4 responses
                            28 views
                            0 likes
                            Last Post love2code2trade  
                            Working...
                            X