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

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);
                    }
                }
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by elirion, Today, 09:48 PM
        0 responses
        1 view
        0 likes
        Last Post elirion
        by elirion
         
        Started by set2win, 08-04-2021, 09:23 AM
        39 responses
        1,001 views
        0 likes
        Last Post WaleeTheRobot  
        Started by md4866, Today, 08:15 PM
        0 responses
        8 views
        0 likes
        Last Post md4866
        by md4866
         
        Started by mjbatts91, Yesterday, 04:48 PM
        2 responses
        23 views
        0 likes
        Last Post mjbatts91  
        Started by pibrew, Today, 06:10 PM
        1 response
        22 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X