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

Dumb Question

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

    Dumb Question



    Hello all, this is probably a newb question, so I apologize for that. In addition, I want to thank you for all the support you provide, I see almost every thread that is started has a reply.


    How do I grab the exit size of my last order, and then use that information to increase the size of my next position?


    I know this is elementary ,so I apologize again in advance. I'm a blacksmith by trade - see more here - not a programmer : )
    Last edited by KarlieBoe; 02-17-2021, 06:42 PM.

    #2
    Hello KarlieBoe,

    Thank you for your post.

    Welcome to the NinjaTrader forums! Don't worry, it's not a stupid question at all.

    To check the exit size of the last order, you would need to check the TradeCollection, get the last trade, then get the quantity of that trade. You could then save this to a variable and use that to adjust the position size of your next entry:



    For example:

    Code:
    private int LastTradeQuantity;
    
    protected override void OnBarUpdate()
    {
      // Accesses the last trade in the strategy (oldest trade is at index 0)
      // and assigns the quanity to a variable
      if (SystemPerformance.AllTrades.Count > 1)
      {
          Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
    
          LastTradeQuantity = lastTrade.Quantity;
    
      }
    
    }
    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 judysamnt7, 03-13-2023, 09:11 AM
    4 responses
    59 views
    0 likes
    Last Post DynamicTest  
    Started by ScottWalsh, Today, 06:52 PM
    4 responses
    36 views
    0 likes
    Last Post ScottWalsh  
    Started by olisav57, Today, 07:39 PM
    0 responses
    7 views
    0 likes
    Last Post olisav57  
    Started by trilliantrader, Today, 03:01 PM
    2 responses
    21 views
    0 likes
    Last Post helpwanted  
    Started by cre8able, Today, 07:24 PM
    0 responses
    10 views
    0 likes
    Last Post cre8able  
    Working...
    X