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

Developing a Risk Manager

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

    Developing a Risk Manager

    Hello everyone. I want to code something on NT8 that Im not sure is even possible. Let me elaborate:

    Is there any property or method in NinjaScript that my strategy can use to keep me from placing any more trades for the rest of the day?

    Ive found several examples of trade limiters and stuff. But thing is, I dont want my strategy to place trades, I only want it to 'disable' the ability of placing trades, so to speak. For instance:

    *Rule 1 = 2 losing trades per day (150usd each)
    *Rule 2 = 1 winning trade per day

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    int dailyLoss = 300
    int dailyTarget = 175


    if (RealizedPnL || UnrealizedPnL == dailyLoss || dailyTarget)
    {
    //some expression to prevent the trader from taking any more trades for the day
    // something that when the trader clicks buy or sell, the order gets rejected by the strategy
    // as if the buy and sell buttons get disabled

    ExitLong();
    ExitShort();
    }




    *The only way for the trader to place more trades in the same day is to disable the strategy on the respective chart.


    Thanks in advance.


    #2
    Design some code to check your RealizedPnL against
    your MaxDailyLoss, and return false if the entry should be
    denied,

    Code:
    private bool CheckMaxDailyLoss()
    {
        if (RealizedPnL < -MaxDailyLoss)
            // trade entry permission denied
            return false;
    
        // trade entry permission granted
        return true;
    }
    The point is, then you can change your trade entry code to
    confirm your RealizedPnL situation before trade entry by
    calling this method.

    Notes:
    RealizedPnL < 0 indicates a loss, and > 0 indicates a profit
    Reset RealizedPnL back to zero at start of each session.
    Enter MaxDailyLoss as a positive number, like +500 or +1000.
    Then comparison 'RealizedPnL < -MaxDailyLoss' should work.
    (Use negative sign to negate MaxDailyLoss at comparison time)
    Last edited by bltdavid; 09-05-2020, 04:36 PM.

    Comment


      #3
      Add additional methods,

      CheckMaxWinningTrades
      CheckMaxLosingTrades

      that you also call before trade entry.

      Comment


        #4
        Hello David. Thank you for your reply.

        Thing is, there won't be any ''code entry'' because I will be placing my orders manually.

        What I dont know is what to write where you wrote ''trade entry denied/granted''

        What can the strategy use to reject/allow placing orders manually.

        I understand the logic the strategy should have to know when the trader reaches the max number of trades taken in a day or a max loss. What I dont know is under what expression/instruction the strategy will be able to reject the placing of discretional orders, by clicking by or sell on the chart trader panel.

        Comment


          #5
          Originally posted by camtrading View Post
          Thing is, there won't be any ''code entry'' because I will be placing my orders manually.

          What can the strategy use to reject/allow placing orders manually.
          Nothing.

          That's not how it works.

          A Strategy is used to submit automated entry orders, and then manage
          the exit of that position automatically with stop and target orders.

          Generally speaking, the entry is an automated action resulting from
          decisions made by the Strategy code, while the exit can be assisted
          manually, it is usually automated as well.

          A Strategy cannot be used to reject/allow the placing of manual orders,
          unless those manual orders are placed through an interface that it provides.
          (Eg, you can create 'Buy/Sell' toolbar buttons that cause your Strategy
          code to submit 'Buy/Sell' entry orders.)

          Strategies are not 'all-knowing', their world is fairly isolated.
          They don't know about other Strategies that are running.
          They don't know about other positions created by other Strategies.
          They don't know about other positions created manually.

          NT8 has 3 types of 'plugins', they are the Indicator, Strategy, and Addon.
          (NT7 did not have the Addon plugin.)

          The Strategy plugin is not the same thing as an ATM Strategy.
          Make sure you understand the differences between those two.

          My point is: neither a Strategy plugin nor an ATM Strategy can
          globally reject/allow the placing of manual orders.

          If you are able to achieve a global reject/allow for trade entries,
          it would be some pretty advanced stuff.

          I mean, how would you reject new orders being submitted manually
          through a DOM? If you don't trade using a DOM, you may not care,
          but my point is: I doubt the NinjaScript framework provides any kind
          of methods or interfaces that can completely do what you want.

          Addons have a global flavor, but I doubt they can globally prevent
          new orders being submitted.

          I'll bow out and let Support assist you from here.

          Good luck!

          [EDIT: I just re-read your original question. Sorry, I did not
          understand correctly what you were asking. I would say that
          what you seek is not possible. Ie, risk mgmt is managed by
          the trader. If you have 2 losing trades, you stop trading.
          If you have 1 winner, you stop trading. I mean, this problem
          is easily solved through trader self-discipline, right? ]

          [EDIT2: In summary, for the manual trader, risk mgmt is
          something that is handled manually -- a Strategy is not part
          of the solution domain for manual risk mgmt.]
          Last edited by bltdavid; 09-06-2020, 07:45 AM.

          Comment


            #6
            Thank you David. At first I thought It wouldnt be possible. I wanted to make sure first.

            Comment


              #7
              Hello camtrading,

              I have an example of a daily loss limit.
              Hello, I've updated the DailyLossLimit and DailyLosLimitMultiTrade examples that were posted on the forum for NinjaTrader 7 for NinjaTrader 8. These are often requested and I felt they are good examples to have for NT8. DailyLossLimitExample_NT7 - http://ninjatrader.com/support/forum...241#post451241 (http://ninjatrader


              This is an idea that could be used to make an addon to place orders through (such as on a button click), that prevents order submissions when clicking the button after the account limit is reached.

              I am also including a link to an example of placing orders through the addon approach.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by mmenigma, Yesterday, 03:25 PM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by kujista, Today, 05:44 AM
              0 responses
              7 views
              0 likes
              Last Post kujista
              by kujista
               
              Started by ZenCortexCLICK, Today, 04:58 AM
              0 responses
              9 views
              0 likes
              Last Post ZenCortexCLICK  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              172 responses
              2,281 views
              0 likes
              Last Post sidlercom80  
              Started by Irukandji, Yesterday, 02:53 AM
              2 responses
              18 views
              0 likes
              Last Post Irukandji  
              Working...
              X