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

How to find the last orders EXIT position SIZE?

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

    How to find the last orders EXIT position SIZE?

    First off, I've been using the platform for years to develop many different ideas and I love it. While I haven't been successful, that's not fault of the platform! So thank you.

    I've scoured the forums to try and find an answer to this question and there are many similar ones out there, but I seem to be overlooking the answer to my particular problem...

    The Question: In short, I want to grab the exit size of my last order and on my next order that's placed, increase the size based on the previous exit.

    I know you can just "Enter Short" on a losing Long Trade easily enough using the editor and code, but I don't want to do it within the same bar. I want to be able to wait until another defined entry point and use the previous orders exit size to size my new position.

    I hope that makes sense and thank you for your time!

    #2
    Hello boolwinkle,

    Thank you for your post.

    You could do this by querying the trades collection and getting the quantity of the last trade:

    Code:
    protected override void OnBarUpdate()
    {
      if (SystemPerformance.AllTrades.Count > 0)
      {
          // Check to make sure there is at least one trade in the collection
          Trade lastTrade = SystemPerformance.RealTimeTrad es[SystemPerformance.RealTimeTrades.Count - 1];
    
          // Store the quantity of the last completed real-time trade
          double lastTradeQty = lastTrade.Quantity;
    
         // Print the quantity of the last trade
         Print("The last trade was for " + lastTradeQty + " contracts");
      }
    }


    You can then use the lastTradeQty to calculate the size of your subsequenty entries.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by geddyisodin, Today, 05:20 AM
    0 responses
    1 view
    0 likes
    Last Post geddyisodin  
    Started by JonesJoker, 04-22-2024, 12:23 PM
    6 responses
    32 views
    0 likes
    Last Post JonesJoker  
    Started by GussJ, 03-04-2020, 03:11 PM
    12 responses
    3,239 views
    0 likes
    Last Post Leafcutter  
    Started by AveryFlynn, Today, 04:57 AM
    0 responses
    5 views
    0 likes
    Last Post AveryFlynn  
    Started by RubenCazorla, 08-30-2022, 06:36 AM
    3 responses
    79 views
    0 likes
    Last Post PaulMohn  
    Working...
    X