Announcement

Collapse
No announcement yet.

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, 10: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 b16_aln, Today, 01:52 AM
                1 response
                17 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by rfsettling, Today, 07:17 AM
                0 responses
                2 views
                0 likes
                Last Post rfsettling  
                Started by vantojo, Today, 06:46 AM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Jim  
                Started by sidlercom80, Today, 02:40 AM
                3 responses
                16 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Started by junkone, Yesterday, 08:55 PM
                2 responses
                13 views
                0 likes
                Last Post junkone
                by junkone
                 
                Working...
                X