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.
    https://ninjatrader.com/support/foru...ples#post93881
    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.
                https://ninjatrader.com/support/help.../exitshort.htm
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  hahahah I miseed that
                  Thank you Chelsea

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by demarcog, Today, 08:51 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post demarcog  
                  Started by futuros, 01-26-2023, 05:10 PM
                  3 responses
                  40 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Started by number1, Yesterday, 09:13 PM
                  1 response
                  31 views
                  0 likes
                  Last Post NinjaTrader_Sev  
                  Started by angelvincent37, Yesterday, 08:15 AM
                  2 responses
                  25 views
                  0 likes
                  Last Post angelvincent37  
                  Started by Entwaze, Yesterday, 06:41 AM
                  5 responses
                  54 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Working...
                  X