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 gentlebenthebear, Today, 01:30 AM
    3 responses
    14 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by PhillT, Today, 02:16 PM
    2 responses
    6 views
    0 likes
    Last Post PhillT
    by PhillT
     
    Started by Kaledus, Today, 01:29 PM
    3 responses
    10 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by frankthearm, Yesterday, 09:08 AM
    14 responses
    47 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by PaulMohn, Today, 12:36 PM
    2 responses
    17 views
    0 likes
    Last Post PaulMohn  
    Working...
    X