Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stopping a strategy after a certain amount of loss

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

    Stopping a strategy after a certain amount of loss

    Hello,
    I have an automated trading strategy based on Ninjascript. Is there a way to stop a strategy from making further trades based on the following criteria.

    - If the cumulative loss is more than or equal to $4000 for any 'calender month', stop trading for that particular month.


    On the other hand, I want the strategy to start placing trades next month if the cumulative loss for this month was more than or equal to $4000. I.e. if I have a loss of $4000 this month, I want the strategy to stop placing trades for this month only but want it to start working next calendar month without me in the need to activating it.

    I found the following statement from Help section, but it is not working for me. Can someone please help me to understand what could be wrong here?
    protected override void OnBarUpdate()
    {
    if Performance.RealtimeTrades.TradesPerformance.Curre ncy.ProfitPerMonth >= -4000
    return;

    Appreciate your help in advance.

    #2
    Hello pandyav,

    Thank you for your post.

    The ProfitPerMonth will only return a percentage. So you would need to factor in how many trades were made and what percentage of those trades profit would be acceptable to begin trading or quit trading: http://www.ninjatrader.com/support/h...itpermonth.htm

    Comment


      #3
      Hi Patrick,
      Thank you for you reply.
      So, profitpermonth is not the right approach in my situation.

      Since I am specifically looking to stop trading at a cumulative loss of $4000 for any calendar month, what would you suggest should be the performance value/statement that I need to use?

      Comment


        #4
        Hello pandyav,

        Thank you for your response.

        There really would be no supported method for this. You would need to track the profit for the month by calculating your own values based on currency.

        Comment


          #5
          Thanks Patrick. So if I cannot calculate loss for a month, is a there a statement that I can use to stop the strategy from making any further trades once the cumulative losses are more than $4000?

          Comment


            #6
            Originally posted by pandyav View Post
            Thanks Patrick. So if I cannot calculate loss for a month, is a there a statement that I can use to stop the strategy from making any further trades once the cumulative losses are more than $4000?
            It is not that you cannot calculate it. You just have to write the code to do so.

            Cycle backwards through the Trades collection, and add up all the trades which have an exit date in the month in question. There are a number of ways to do it. Unfortunately, using a resource intensive while loop might be the simplest.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Irukandji, Today, 09:34 AM
            0 responses
            3 views
            0 likes
            Last Post Irukandji  
            Started by TraderBCL, Today, 04:38 AM
            3 responses
            25 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by WeyldFalcon, 08-07-2020, 06:13 AM
            11 responses
            1,423 views
            0 likes
            Last Post jculp
            by jculp
             
            Started by RubenCazorla, Today, 09:07 AM
            0 responses
            5 views
            0 likes
            Last Post RubenCazorla  
            Started by BarzTrading, Today, 07:25 AM
            2 responses
            29 views
            1 like
            Last Post BarzTrading  
            Working...
            X