Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to use trades collection in an optimizer fitness

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

    How to use trades collection in an optimizer fitness

    Hello,

    I would like to use this piece of code in an optimizer fitness:

    foreach (Trade myTrade in strategy.SystemPerformance.AllTrades)
    {
    if (myTrade.MaePercent < 0.015 )
    //Do Something;
    }

    I am getting the error: "An object reference is required for the non-static field, method, or property 'NinjaTrader.Cbi.SystemPerformance.AllTrades.get'"

    What would be the right code?


    #2
    Hello guillembm,

    Thanks for your post.

    You would need to exclude "strategy" in "strategy.SystemPerformance.AllTrades" in your loop. The code might read something like this.

    Code:
    protected override void OnBarUpdate()
    {
    
        if (SystemPerformance.AllTrades.Count == 20)
        {
            foreach (Trade myTrade in SystemPerformance.AllTrades)
            {
                if (myTrade.MaePercent < 0.015 )
                    //Do something
            }
        }
    }
    See this help guide documentation for more information and sample code: https://ninjatrader.com/support/help...collection.htm

    Let us know if we may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    477 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    317 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    255 views
    1 like
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    340 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    306 views
    0 likes
    Last Post CarlTrading  
    Working...
    X