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 poplagelu, Today, 05:00 AM
        0 responses
        3 views
        0 likes
        Last Post poplagelu  
        Started by fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,407 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by Shai Samuel, 07-02-2022, 02:46 PM
        4 responses
        98 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        8 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        160 views
        0 likes
        Last Post loganjarosz123  
        Working...
        X