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

Maximum Daily Loss

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

    Maximum Daily Loss

    I know there's a similar thread where it was said that there was no way for NT to do this automatically. So, I've tried to achieve this through scripting but it doesn't seem to work. Any thoughts?

    protected override void OnBarUpdate()
    {

    if (Bars.FirstBarOfSession)
    {
    disable = 0;
    dayscapital = initialcapital + Performance.AllTrades.TradesPerformance.Currency.C umProfit;
    }

    if (initialcapital + Performance.AllTrades.TradesPerformance.Currency.C umProfit > daycapital * 0.97
    && disable == 0)
    {
    <<<continuetrading>>>
    }
    else
    {
    disable = 1;
    }

    What I'd expect is that as long as the daily loss is less than 3%, the script should <<<continuetrading>>>. But it doesn't seem to work. I have a stop loss of 1% on all trades so the max daily drawdown should be 4%. However, I have some with 6+%.

    I tried to troubleshoot this by adding a
    Print (dayscapital);
    on the last line of the first if clause, after the dayscapital has been calculated for the day.

    However, checking the output window, the dayscapital is never printed as 10000, which it should be at least once, on the first day before any trades have been completed (since initialcapital = 10000). Also, for some reason, other Print() commands on the first day have been outputted before the Print (dayscapital) even though they come later on in the script.

    Any help would be much appreciated. Thanks!

    -------
    EDIT:

    I tried this in another script where and it does seem to work. Could this by any chance be due to a problem this has with SetTrailStop?
    Last edited by wuileng; 08-30-2009, 11:24 AM.

    #2
    Hi wuileng, have you seen the sample titled Halting a Strategy Once User Defined Conditions Are Met?
    AustinNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Austin View Post
      Hi wuileng, have you seen the sample titled Halting a Strategy Once User Defined Conditions Are Met?

      Austin,

      Does the check against the maximum drawdown below consider both OPEN and CLOSED values?

      if (Performance.AllTrades.TradesPerformance.Currency. CumProfit > 1000
      || Performance.AllTrades.TradesPerformance.Currency.C umProfit < -400)

      I'd like to have a check that stops my strategy once my drawdown hits a certain amount. I want my drawdown calculated based off of open positions as well.

      thanks-

      Comment


        #4
        jonmoron, this would only include closed trades. You could work with the closed trades performance along with GetProfitLoss() to check open + closed PnL.
        AustinNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        382 views
        1 like
        Last Post Gavini
        by Gavini
         
        Started by oviejo, Today, 12:28 AM
        0 responses
        1 view
        0 likes
        Last Post oviejo
        by oviejo
         
        Started by pechtri, 06-22-2023, 02:31 AM
        10 responses
        125 views
        0 likes
        Last Post Leeroy_Jenkins  
        Started by judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        59 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Yesterday, 06:52 PM
        4 responses
        36 views
        0 likes
        Last Post ScottWalsh  
        Working...
        X