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 set up stop loss with Daily number of losing trades

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

    How to set up stop loss with Daily number of losing trades

    Hi,

    I want to set up a stop loss when I have one losing trade with the strategy. I know that Ninja provides System performance class to handle this but when I use SystemPerformance.AllTrades.LosingTrades.Count it does not perform as I expect. Here is the code I use:

    if (SystemPerformance.AllTrades.LosingTrades.Count - CumulativeLosingTrade >= DailyStoplossLimit)
    {
    return;
    }

    if (Times[0][0].TimeOfDay > Times[0][1].TimeOfDay)
    {
    CumulativeLosingTrade = SystemPerformance.AllTrades.LosingTrades.Count; //This is to get total number of stop loss before today.
    }

    When I tested # of losing trade with the following code in Onbarclose function:

    Print("Current total number of losing trades: " + SystemPerformance.AllTrades.LosingTrades.Count);
    Print("Current cumulative historical number of losing trades:" + CumulativeLosingTrade.ToString());

    I see 0 only, and even there is a losing trade already during the test, the number does not update. So I want to ask how I should use the class correctly for my stop loss condition.

    I look forward to your assistance.

    Thanks!

    #2
    Hello RandomTrader,

    How are you submitting orders? The strategy performance collection only works with managed/unmanaged strategy orders. Also this specific strategy needs to submit those orders, if you are working with multiple scripts that would explain the 0.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      I am testing my strategies using playback and sim accounts. I don't know if they are managed or unmanaged orders. Could you suggest how I should use the class correctly?

      Thanks!

      Comment


        #4
        Hello RandomTrader,

        You would be using managed or unmanaged as long as you are not using ATM strategies or the Addon framework. If you used the strategy builder its managed. If you manually coded it then you will have to refer to your code to see which approach you are using.

        Alternatively try using the AllTrades count to see if any trades are seen at all. SystemPerformance.AllTrades.Count
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi Jesse,

          I found that when I load my strategy from the main control window, I do not see any update of the number, I tried all trades, losing and winning trades. However, if I load the strategy from the chart, I can see the update of the number. Is there any difference in the two ways of enabling strategies?

          Plus, when I am actually running the strategy, I found that there is always one losing trade at the beginning, even though on the chart I do not see one, and my restriction using losing count < 1 does not work. I wonder why.

          Thanks!

          Comment


            #6
            Just an FYI ... the EKlecticCoreV4 package provides the functionality you're asking for.

            Comment


              #7
              Hello,

              With that detail you need to either use a chart which includes backtestable data or toggle IncludeTradeHistoryInBacktest to true.



              JesseNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Stanfillirenfro, Today, 07:23 AM
              4 responses
              20 views
              0 likes
              Last Post Stanfillirenfro  
              Started by DayTradingDEMON, Today, 09:28 AM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by cmtjoancolmenero, Yesterday, 03:58 PM
              8 responses
              31 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by helpwanted, Today, 03:06 AM
              2 responses
              22 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by navyguy06, Today, 09:28 AM
              0 responses
              6 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Working...
              X