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

If last trade was a loosing trade stop trading for today

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

    If last trade was a loosing trade stop trading for today

    hello

    i would like to stop (not terminate) my automated strategy for today if the last trade was a loosing one, but when i add this code from the help section i get an INDEX OUT OF RANGE error

    other parts of my strategy require this to be set:
    if (CurrentBar < 6)
    return;

    here is the code i am using from the help section:

    Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];

    if (lastTrade != null && lastTrade.ProfitPercent <= 0)
    allowtrading == false;

    on firstbarofsession is set "allowtrading" to true

    on every entry i check if allowtrading == true then enterlong

    #2
    This is likely your line in error: Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];

    Where in the help guide does it use Performance.AllTrades.Count - 1? If you want the last trade you would want to use an index of 0.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      thx

      about the performance.alltrades
      is there a function to print the largest loosing trade from my trade history?

      Originally posted by NinjaTrader_Josh View Post
      This is likely your line in error: Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];

      Where in the help guide does it use Performance.AllTrades.Count - 1? If you want the last trade you would want to use an index of 0.

      Comment


        #4
        You will want to loop through the TradeCollection class and determine it through your own code.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          tradereight,

          Are you still getting the "index out of range" issue? It has been brought to my attention that Performance.AllTrades[Performance.AllTrades.Count - 1] is actually the last trade. A reason you may have hit the "index out of range" is if there are no trades at the point in time when you access it.
          Josh P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NRITV, Today, 01:15 PM
          2 responses
          9 views
          0 likes
          Last Post NRITV
          by NRITV
           
          Started by frankthearm, Today, 09:08 AM
          7 responses
          31 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by maybeimnotrader, Yesterday, 05:46 PM
          5 responses
          26 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by quantismo, Yesterday, 05:13 PM
          2 responses
          20 views
          0 likes
          Last Post quantismo  
          Started by adeelshahzad, Today, 03:54 AM
          5 responses
          33 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X