Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Last Trade Loss

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

    Last Trade Loss

    I'm having a problem with my Script. It works fine until I add the code

    Code:
    		//Get last Loss
    		if (Performance.AllTrades.LosingTrades.Count > 1)
       		 {
    				Trade lastTrade = Performance.AllTrades.LosingTrades[Performance.AllTrades.Count - 1];
    				Trade firstTrade = Performance.AllTrades.LosingTrades[0];
    
    				DrawText("P&L" + CurrentBar, true, "LastLost Profit: " + lastTrade.ProfitCurrency.ToString(), 0,( Close[0] + (10 * TickSize)), 1, Color.Cyan, new Font ("Arial", 11, FontStyle.Bold), StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
    
    				Print("The last losing trade's profit was " + lastTrade.ProfitPercent);
    				Print("The first losing trade's profit was " + firstTrade.ProfitPercent);
       			 }
    Then it won't load at all. All I want to know is how exactly do I get the Very last Trade's P&L. and if it Loss (Do Something)

    I attached the a simple CrossOver strategy. please check it out.

    thanks
    Attached Files

    #2
    Hello ginx10k,

    Thank you for writing in. You are simply requesting an index that does not exist, please try the following code:
    Code:
    Trade lastTrade = Performance.AllTrades.LosingTrades[[COLOR="Lime"]Performance.AllTrades.LosingTrades.Count[/COLOR] - 1];
    After adjusting that code, the strategy began drawing the text like expected. You will likely want to add some more logic to your code to prevent the text from redrawing the same thing over and over.

    Please let me know if I may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    599 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    344 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    558 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    557 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X