Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Losing Trades

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

    Losing Trades

    when I try this I received error message below

    if (SystemPerformance.AllTrades.LosingTrades.Count > 1)
    {
    Trade lastTrade = SystemPerformance.AllTrades.LosingTrades[SystemPerformance.AllTrades.Count - 1];


    Print("The last losing trade's profit was " + lastTrade)

    Strategy 'weisbackup': Error on calling 'OnBarUpdate' method on bar 75: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    #2
    Hello wagner4691,

    Thank you for your post.

    What else do you have within On Bar Update? It looks like you are trying to print the entire last trade object rather than the profit as well.

    Are you doing a null check for the lastTrade variable? Here's an example of how to do so as well as get the entry and exit price:

    Code:
                if (BarsSinceExitExecution() >= 0 && SystemPerformance.RealTimeTrades.Count > 0)
                { 
                    Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
                    if (lastTrade != null) 
                    {
    
                        string PnLText = "Last: " + lastTrade.Entry.MarketPosition + " " + lastTrade.Entry.Price.ToString("0.00") + ", out " + lastTrade.Exit.Price.ToString("0.00");
                        Print(PnLText);
                    }
                }

    Comment


      #3
      I’ve realized the result in Ticks and Currency are the same even when I have more then one contract . Could you help me please?

      string PnLText = "Points: " + lastTrade.ProfitPoints + ", Ticks " + lastTrade.ProfitTicks +"Currency " + lastTrade.ProfitCurrency;
      Print(PnLText);

      Result= SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency;
      Print(Result);

      Comment


        #4
        Hello wagner4691,

        Thank you for your reply.

        When you have more than one contract in a trade, are you exiting the trade all at once or do you have separate exits? Only if the trade is entered and exited as a whole would last trade reflect the entire entered position.

        Could you provide an example of what you're seeing?

        Thanks in advance; I look forward to assisting you further.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        52 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        70 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        43 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        48 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X