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

How to code for if last trade was a win/ loss w count

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

    How to code for if last trade was a win/ loss w count

    Hi nt8 support,

    How do I code for if the last trade was a win or loss and can I get a count of the no of trades in a row that are wins/losses in a similar way?

    #2
    Hello Austiner87,

    Thanks for opening the thread.

    You can get the last trade from SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1]

    The trade before that would be SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 2]

    From here you can reference Trade.ProfitCurrency to see if that trade was a win or loss. If the last three trade's ProfitCurrency are positive then the last three trades are winners.

    SystemPerformance - https://ninjatrader.com/support/help...erformance.htm

    TradeCollections - https://ninjatrader.com/support/help...collection.htm

    Trade objects - https://ninjatrader.com/support/help.../nt8/trade.htm

    One of our examples demonstrates halting a strategy after consecutive losses which may be useful for what you are trying to accomplish. I have linked it below.



    We look forward to assisting.

    JimNinjaTrader Customer Service

    Comment


      #3
      Hi, is it possible to get the PnL for Historical Trades or this is just for Real Time trades?

      Comment


        #4
        Hello omermirza,

        Live trades that are made from the strategy are recorded in the NinjaTrader database and can be reviewed in a Trade Performance window.

        Using Trade Performance - https://ninjatrader.com/support/help...erformance.htm

        Historical trades that are calculated when the strategy processes historical data can be reviewed from a historical strategy performance report. Programmatically, these historically calculated trades can be read from the SystemPerformance.AllTrades collection.

        Please let us know if you have any additional questions.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by funk10101, Today, 12:02 AM
        0 responses
        3 views
        0 likes
        Last Post funk10101  
        Started by gravdigaz6, Yesterday, 11:40 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by MarianApalaghiei, Yesterday, 10:49 PM
        3 responses
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by XXtrader, Yesterday, 11:30 PM
        0 responses
        4 views
        0 likes
        Last Post XXtrader  
        Started by love2code2trade, 04-17-2024, 01:45 PM
        4 responses
        28 views
        0 likes
        Last Post love2code2trade  
        Working...
        X