Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Break Even & Average Price calculation

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

    Break Even & Average Price calculation

    Greetings,

    The NT Break Even & Average Price, in a Strategy and on Chart Trader do not seem to be able to give me what I need.
    The problems being:
    Entry & Exit orders are not matched (in NT's Break Even & Average Price). It appears only FIFO & LIFO methods are available, which is not my situation.
    Manual quantity changes (using Chart Trader) to Strategy Orders are not available in the Strategy, so I can't calculate Average Price in the Strategy.

    So, my questions are:
    Is my understanding of NT correct ?
    How can I access Order/Execution information, from both Chart Trader and Strategy Orders, to calculate Break Even & Average Price, in a non LIFO/FIFO situation ?
    Is it possible using an Add On ?
    I tried subscribing to order updates, in a Strategy, and using
    " private void OnOrderUpdate(object sender, OrderEventArgs e)
    {
    }"
    Then entering an order with Chart Trader, resulting in "Unhandled exception: Object reference ...".

    Thanks,

    Bruce

    #2
    PS:

    This is for live trading, not Back Testing.

    BGW

    Comment


      #3
      Hello Bruce,

      Thanks for your question.

      Strategies are only able to manage their own virtual positions out-of-box. They are not aware of manual orders or positions. The Strategy OnOrderUpdate and OnExecutionUpdate methods in a strategy work for that strategy alone. If you would like to monitor account level order and execution updates, you can subscribe to the account OrderUpdate and ExecutionUpdate events. I have attached an example NinjaScript that subscribes these events.

      Please let us know if you have any questions.
      Attached Files
      JimNinjaTrader Customer Service

      Comment


        #4
        Thanks Jim, that's exactly what I needed. Even the Chart Trader quantity increases are included in the executions, great !
        Could you explain these 2 lines ?
        lock (Account.All)
        account = Account.All.FirstOrDefault(a => a.Name == "Sim101");

        Thanks again,

        Bruce

        Comment


          #5
          Hello Bruce,

          The account collection gets locked so we can read the collection without creating a threading error.

          The other line finds the Account named "Sim101" and assigns it to the account object.

          Please let us know if we can be of further assistance.
          JimNinjaTrader Customer Service

          Comment


            #6
            Thanks Jim,

            "The other line finds the Account named "Sim101" and assigns it to the account object." Seems like a long way around to find what we already know . . . thanks for the explanation.

            I'm considering changing my Strategy into an indicator, what advantages would I lose ? I'd gain Account access, which is a big advantage to me. I'm already using "SubmitOrderUnmanaged( ", so I'm thinking there won't be too much to change.

            Thanks,

            Bruce

            Comment


              #7
              Hello Bruce,

              From an indicator you will need to use the Addon approach. SubmitOrderUnmanaged is no longer going to work as this is a NinjaScript Strategy method.

              Below is a link to an example.
              https://ninjatrader.com/support/foru...082#post536082

              As well as a link to the help guide.
              https://ninjatrader.com/support/help...reateorder.htm
              https://ninjatrader.com/support/help...-us/submit.htm

              The Addon approach to get an account that Jim has provided works with any script type.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Anthony_0709, Today, 01:29 PM
              2 responses
              7 views
              0 likes
              Last Post Anthony_0709  
              Started by kenbun, Today, 12:21 PM
              0 responses
              9 views
              0 likes
              Last Post kenbun
              by kenbun
               
              Started by WNorton, Today, 11:23 AM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_Spencer  
              Started by stafe, Today, 10:43 AM
              0 responses
              12 views
              0 likes
              Last Post stafe
              by stafe
               
              Started by UltraNIX, Today, 09:13 AM
              3 responses
              18 views
              0 likes
              Last Post UltraNIX  
              Working...
              X