Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.


              As well as a link to the help guide.



              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 CortexZenUSA, Today, 12:53 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by CortexZenUSA, Today, 12:46 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by usazencortex, Today, 12:43 AM
              0 responses
              5 views
              0 likes
              Last Post usazencortex  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              168 responses
              2,265 views
              0 likes
              Last Post sidlercom80  
              Started by Barry Milan, Yesterday, 10:35 PM
              3 responses
              11 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X