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 Limitation setting

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

    DrawDown Limitation setting

    Dear Sir or Madam,

    Max Drawdown need to be limited to 200 ticks.

    I want to inform you that I want to create a limitation to my Max Daily Drawdown so I will exit my strategy when my strategy hits my input Daily drawdown input per ticks

    I found this code, but I do not know if it is working well.

    private double averageDrawDown = 199;




    protected override void OnBarUpdate()
    {
    if (! Historical)
    {
    averageDrawDown =
    0 == averageDrawDown
    ? Performance.AllTrades.TradesPerformance.Currency.D rawDown
    : (Performance.AllTrades.TradesPerformance.Currency. DrawDown + averageDrawDown) / 2
    ;
    DrawHorizontalLine("AverageDrawDown", averageDrawDown, Color.RoyalBlue);
    //}
    // code here
    }


    Can you help me with the subject, Please.

    I really need a clear example if possible as I am a basic coder.
    The drawdown is calculated at the end of each trading day, So How can I call the past data and link it to my average DrawDown input?
    Thank you

    #2
    Hello Yassine.Chetouani,

    I have provided three links below you can use as reference samples for achieving what you’re looking to do,

    Strategy: Stopping a strategy after consecutive losers


    Strategy: Halting a Strategy Once User Defined Conditions Are Met


    Strategy: Using trade performance statistics for money management


    In regards to see how you could set up a user input parameter to pass in a draw down figure, please see the SampleMACrossOver strategy preloaded on Ninja, which lets the user define the fast and slow period.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hi Alan
      Thank you for your answer.
      Sorry for this late feedback. I just got the chance to try some solution and answer you back
      I did the code below to limit my Daily DD.

      if ((Performance.AllTrades.TradesPerformance.Currency .DrawDown - priorTradesDrawDown (a double called from the first bar session) +Position.GetProfitLoss(Close[0], PerformanceUnit.Currency)) <= - maxDrawDown (Double input))

      {
      Do something.... Stop strategy or close all, Draw line .....
      }

      Thank you for your assistance.
      I add that I want to post it here so if someone is looking to limit his DD he can find it in this post. since I struggeled so much to solve this section.

      Best Regards,
      Last edited by Yassine.Chetouani; 08-08-2017, 05:01 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by aa731, Today, 02:54 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by BarzTrading, Today, 07:25 AM
      0 responses
      3 views
      0 likes
      Last Post BarzTrading  
      Started by i019945nj, 12-14-2023, 06:41 AM
      6 responses
      65 views
      0 likes
      Last Post i019945nj  
      Started by ruudawakening, Today, 12:58 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by thread, Yesterday, 11:58 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X