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

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 pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    149 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Started by mattbsea, Today, 05:44 PM
    0 responses
    5 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    33 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    5 views
    0 likes
    Last Post tkaboris  
    Started by GussJ, 03-04-2020, 03:11 PM
    16 responses
    3,283 views
    0 likes
    Last Post Leafcutter  
    Working...
    X