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 trilliantrader, Today, 03:01 PM
            0 responses
            2 views
            0 likes
            Last Post trilliantrader  
            Started by pechtri, 06-22-2023, 02:31 AM
            9 responses
            122 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by frankthearm, 04-18-2024, 09:08 AM
            16 responses
            67 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by habeebft, Today, 01:18 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by benmarkal, Today, 12:52 PM
            2 responses
            19 views
            0 likes
            Last Post benmarkal  
            Working...
            X