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

Alternative to Account.FlattenEverything()

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

    Alternative to Account.FlattenEverything()

    Hello
    I am running multiple strategies on the same chart, and I am using Account..FlattenEverything() to execute my Daily Stop Loss, it works good since it automatically disable all trading for me when Daily StopLoss is hit.
    But I would like to add another per trade StopLoss that execute without having to disable all running strategies.
    is there an alternative to Account.FlattenEverything() that would close all current open trades when the UnRealized PNL is smaller than my Specified StopLoss Without disabling the strategies?

    #2
    Hello onlinebusiness,

    You would need to submit an exit order from the strategy to close the strategy position without disabling the strategy.

    Below is a link to 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
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi, Thank you for your fast reply

      I tried doing that, but my current strategy has some complicated logic parameters that it uses. I was unable to figure out how to implement that exit order by a specified StopLoss and keep the strategy working fine.

      This is the strategy I am testing on Price
      Would you be kind enough to take a look at it and walk me through how I can make the changes to it?

      This what I need:
      1. A StopLoss input where I can specify the amount in currency (like -200)
      2. if the current UnRealized PnL of any running trade (Long or Short) is Equal or Less than my specified StopLoss. Close that trade at market price.
      3. The strategy should keep working

      I would very much appreciate this
      Last edited by onlinebusiness; 12-05-2022, 06:23 PM.

      Comment


        #4
        Hello onlinebusiness,
        A StopLoss input where I can specify the amount in currency (like -200)
        You can add a stop loss. However this would not be used for the daily loss limit.
        This is shown on line 46 in State.DataLoaded.

        The daily loss limit is done with logic. The currentPnL is tracked. When the currentPnL is less than the allowed amount, the logic submits an exit market order, and prevents further entries.
        if the current UnRealized PnL of any running trade (Long or Short) is Equal or Less than my specified StopLoss. Close that trade at market price.
        The currentPnL is calculated on line 78 in OnPositionUpdate.
        The position is exited when the daily loss limit is reached on line 69.
        New entries are prevented after the daily loss limit is reached on line 57.
        The strategy should keep working
        The example does keep working, and reset for new entries on a new session on lines 53, and 54.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you ChelseaB,

          But I afraid I may have not explained what I need correctly, allow me to explain again please.

          I am not looking for a daily loss limit, I have a different way of achieving that.

          What I want is a stop loss per trades. let's when I run my strategy the first trade was bad and started accumulating loses on me, I don't want that trade to keep going, I want it to be closed and the strategy to keep being enabled and open new trades on the same day.

          Does that make sense?

          Comment


            #6
            Hello onlinebusiness,

            Have a condition looking for the trade to be "bad", and then call an exit order to exit that position. Use a signal name with the entry, and use that as the fromEntrySignal to attach that exit to that specific entry (exiting only the quantity of that entry).
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              So this is what I did so far:

              For the Long trades:
              Code:
              else if (TradeLoss > Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]))
                          {
                              ExitLong(Convert.ToInt32(DefaultQuantity),"Stop Loss", "Long");
                          }​
              And it is working fine.

              And for the Short trades:
              Code:
              else if (TradeLoss > Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]))
                          {
                              ExitLong(Convert.ToInt32(DefaultQuantity),"Stop Loss", "Short");
                          }​
              But it is not working for the short trades, it doesn't exit the trade when the UnRealized PnL reach my specified minimum stop loss.
              However for the Long trades it is working fine.

              Could you have any idea about what's causing this and how to fix it?
              Thank you


              The properties:
              Code:
              #region Properties
                      [NinjaScriptProperty]
                      [Range(-99999, double.MaxValue)]
                      [Display(Name="TradeLoss", Order=1, GroupName="Parameters")]
                      public double TradeLoss
                      { get; set; }
                      #endregion​

              Comment


                #8
                Hello onlinebusiness,

                Use ExitShort() to exit a short position.

                Below is a link to the help guide.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  hahahah I miseed that
                  Thank you Chelsea

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by alifarahani, Today, 09:40 AM
                  6 responses
                  31 views
                  0 likes
                  Last Post alifarahani  
                  Started by Waxavi, Today, 02:10 AM
                  1 response
                  17 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by Kaledus, Today, 01:29 PM
                  5 responses
                  14 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by Waxavi, Today, 02:00 AM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by gentlebenthebear, Today, 01:30 AM
                  3 responses
                  17 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X