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

DrawDown question

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

    DrawDown question

    Hello Ninjatrader support team,
    I'm trying to develope a limitation to my Max Drawdown so my strategy should Halt when the Drowdown overcome a specific value.


    Print("Draw down of all trades is: " + SystemPerformance.AllTrades.TradesPerformance.Curr ency.Drawdown);

    this code works very well when I use a single strategy but i'm not sure it works very well whne several strategies are working. In this code
    I'll excpect to see the Drawdown of all strategies and not the DD of a single specific strategy.

    For that reason I tried :

    TradeCollection myTrades = SystemPerformance.AllTrades.GetTrades("ES 12-17","Long1",1);
    Print(myTrades.TradesPerformance.Currency.Drawdown );

    but it gives me just the loss of the Long1 trades and not the Drawdown of this strategy.
    How can get the Historical Drawdown of a specific strategy that is working with other X strategies?

    #2
    Hello zteck,

    Thanks for opening the thread.

    You could loop through each Strategy (type StrategyBase) in Account.Strategies and create multiple Trade Collections for those strategies or for each entry signal you want to track. You would then need to loop through each Trade in each collection to add it to a master TradeCollection.

    For example:

    Code:
    TradeCollection myTradesA 	= null;  
    TradeCollection myTradesB 	= null;
    TradeCollection myTradesAB 	= null;
    
    foreach(StrategyBase strat in Account.Strategies)
    {
    	if(strat.Name == "Strategy1")
    		myTradesA = strat.SystemPerformance.AllTrades;
    	if(strat.Name == "Strategy2")
    		myTradesB = strat.SystemPerformance.AllTrades;
    }
    
    if(myTradesA != null)
    	foreach(Trade trade in myTradesA)
    		myTradesAB.Add(trade);
    
    if(myTradesB != null)	
    	foreach(Trade trade in myTradesB)
    		myTradesAB.Add(trade);
    
    if(myTradesAB != null)
    	Print("Total Drawndown for select strategies: " + myTradesAB.TradesPerformance.Currency.Drawdown);
    For the thread's reference, I've included links to publicly available documentation on the items discussed.

    Account.Strategies - https://ninjatrader.com/support/help...es_account.htm

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

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

    Please let us know if you have any questions.
    Last edited by NinjaTrader_Jim; 11-28-2017, 11:20 AM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you so much Jim. like always your answer is clear and usefull. I'll it try tomorrow.
      have a good day

      Comment


        #4
        Hello,
        I tried the code below but I got this error:
        "Error on CAlling 'OnBarUpdate'method on bar 0: Object reference not se to an instance of an object"
        what am i missing?

        Comment


          #5
          Hello zteck,

          In my example, I probably should have added a null check for myTradesA and myTradesB before they are accessed in the their foreach loops. I've updated the example provided above.
          JimNinjaTrader Customer Service

          Comment


            #6
            Hello Jim,
            thank you for your reply.
            I tried it:

            Code:
            		protected override void OnBarUpdate()
            		{
            TradeCollection myTradesA 	= null;  
            TradeCollection myTradesB 	= null;
            TradeCollection myTradesAB 	= null;
            
            foreach(StrategyBase strat in Account.Strategies)
            {
            	if(strat.Name == "Strategy1")
            		myTradesA = strat.SystemPerformance.AllTrades;
            	if(strat.Name == "Strategy2")
            		myTradesB = strat.SystemPerformance.AllTrades;
            }
            
            if(myTradesA != null)
            	foreach(Trade trade in myTradesA)
            		myTradesAB.Add(trade);
            
            if(myTradesB != null)	
            	foreach(Trade trade in myTradesB)
            		myTradesAB.Add(trade);
            
            Print("Total Drawndown for select strategies: " + myTradesAB.TradesPerformance.Currency.Drawdown);
            		}
            but I got the same error. I spent some hours to study some sample but I couldn't found a solution

            Comment


              #7
              Sorry zteck,

              I modified the example twice and got sloppy. I should probably up my coffee intake.

              My first change I put in a return statement when either myTradesA or myTradesB were null.

              Code:
              if(myTradesA == null || myTradesB == null)
              	return;
              Execution would then stop there. This would not be as ideal as still building the collection if one strategy were missing so I edited again and added separate null checks for each loop.

              However, myTradesAB would still be null when being accessed for the print. A null check for myTradesAB will be necessary.

              Code:
              if(myTradesAB != null)
              	Print("Total Drawndown for select strategies: " + myTradesAB.TradesPerformance.Currency.Drawdown);
              Here is some further detail on null references - https://ninjatrader.com/support/foru...ead.php?t=4226

              I'll be sure to make sure each sample I provide can be executed rather than simply communicating an idea.
              JimNinjaTrader Customer Service

              Comment


                #8
                Thank you so much again!!! I'll try it later...

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by algospoke, Yesterday, 06:40 PM
                2 responses
                23 views
                0 likes
                Last Post algospoke  
                Started by ghoul, Today, 06:02 PM
                3 responses
                15 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                46 views
                0 likes
                Last Post jeronymite  
                Started by Barry Milan, Yesterday, 10:35 PM
                7 responses
                23 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by AttiM, 02-14-2024, 05:20 PM
                10 responses
                181 views
                0 likes
                Last Post jeronymite  
                Working...
                X