Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Market Position

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

    Market Position

    Hi,

    I am developing a strategy for backtesting and I am not certiain of the following three items:

    1. I am using OnOrderUpdate(IOrder order) function and I am using the fololowing code in OnBarUpdate()

    if(null == entryOrder && actualStatus >= minP)
    EnterLong(
    0, 1, Instrument.FullName);
    elseif(null == entryOrder && actualStatus <= -minP)
    EnterShort(
    0, 1, Instrument.FullName);

    My question is: Is this correct usage?

    2. I am NOT using OnPositionUpdate(...)
    but I have the following code in OnBarUpdate()

    if(Position.MarketPosition == MarketPosition.Long)
    {
    ... custom trailing stop calculation
    // Exit position condition
    ExitLongStop(trailStop);
    }
    elseif(Position.MarketPosition == MarketPosition.Short)
    {
    ... custom trailing stop calculation
    // Exit position condition
    ExitShortStop(trailStop);
    }

    Here is the weird thing for me. I am constantly getting MarketPosition as Flat even though backtesting shows that I am entering positions. Can anyone please suggest how I can get MarketPosition to show Long or Short when an order is entered? Dop I need to use OnPositionUpdate() method?

    3. I wish to use a custom trailing stop. I understand that in Backtesting the only price available is the Price.Average. Any suggestions as how I could actually get and use the fill (entry) price?

    Thank you very much for any advice you may be able to offer.
    P

    #2
    HI Zeos6,

    Your first block of code does not look right.
    null == entryOrder - You want to check the other way around entryOrder == null, but:
    You're not using IOrders so not sure what you are doing with the null check.

    Yes, you can access market position from OnBarUpdate().

    You can access the specific execution price by exposing that IOrder object's properties in IExecution.


    A guide that uses IOrders and can help with the structure is available here:
    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()
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      HI Ryan,

      Thank you for your email.
      The first block is OK.... it is same as what you wrote. However, the reference to executions you provided leads me to an error stating that the page I am looking for is no longer available. Can you please send me an alternative link? Thank you very much.
      P

      Comment


        #4
        Both links work OK here. Which one are you having trouble with?
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Hi Ryan,

          The following link is not working for me:


          Thanks for your help.

          Comment


            #6
            Try this one instead.

            The forum shortens urls but should still be good if you click on it. You just can't copy paste the text only into a browser.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Hi Ryan,

              Unfortunately none of the URLs in the forum work for me. I am on Windows XP Pro Service Pack 3. The URLs generally work for me on my Mac. I am using OnExecution and need to figure out how to get Price at execution. Also, if I am calculating my own trailing stop, where do I implement it: in OnBarUpdate() or OnExecution()? Please let me know. Thank you.

              Comment


                #8
                I would try using a different web browser or PC. If none is available, click F1 in NinjaTrader and search for IExecution.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Ryan,

                  I have tried Firefox, Chrome, as well as IE and they also do not work. I will search for IExecution on the forum. Thank you. I was hoping to get a code snippet showing how to access the fill price but I will figure it out.

                  Comment


                    #10
                    The web links go to our help guide. As far as we know they're working for everyone else. If you need access to the help guide though, your NinjaTrader installation has the same one. F1 or Help > Help
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Ryan,
                      Thank you.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      649 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      370 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      109 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      574 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      576 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X