• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Daily and Weekly stop loss function

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

    Daily and Weekly stop loss function

    I urgently need a built-in Daily loss limit function, Sierra Chart has this but I want to stay with Ninja Trader!
    I am searching for instructions on how I could best tweak the sample P&L script below to do the following. Once applied to any chart it should:

    1. Close all positions immediately and prevent any new positions to be opened for that particular day if x USD loss limit is reached
    2. Trailing loss limit, If in profit the same loss distance should follow for example if I set the Daily loss limit to -500 USD and I am 1000ahead and give back 500 USD it should close all positions immediately and prevent any new positions to be opened for that particular day
    3. A weekly trailing loss limit same as 1 and 2 but will prevent any new trades for that particular week
    4. Once the strategy is set it should always work and cannot be disabled until it is a weekend

    Please share what I need to add or change to the script below to reach this specification:

    //
    // Copyright (C) 2015, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class SamplePnL : Strategy
    {
    private int priorTradesCount = 0;
    private double priorTradesCumProfit = 0;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Using trade performance statistics for money management";
    Name = "Sample PnL";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 2;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 5;
    }

    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < BarsRequiredToTrade) return;
    // At the start of a new session
    if (Bars.IsFirstBarOfSession)
    {
    // Store the strategy's prior cumulated realized profit and number of trades
    priorTradesCount = SystemPerformance.AllTrades.Count;
    priorTradesCumProfit = SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit;

    /* NOTE: Using .AllTrades will include both historical virtual trades as well as real-time trades.
    If you want to only count profits from real-time trades please use .RealtimeTrades. */
    }

    /* Prevents further trading if the current session's realized profit exceeds $1000 or if realized losses exceed $400.
    Also prevent trading if 10 trades have already been made in this session. */
    if (SystemPerformance.AllTrades.TradesPerformance.Cur rency.CumProfit - priorTradesCumProfit >= 1000
    || SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit - priorTradesCumProfit <= -450
    || SystemPerformance.AllTrades.Count - priorTradesCount > 15)
    {
    /* TIP FOR EXPERIENCED CODERS: This only prevents trade logic in the context of the OnBarUpdate() method. If you are utilizing
    other methods like OnOrderUpdate() or OnMarketData() you will need to insert this code segment there as well. */

    // Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.
    return;
    }
    }
    }
    }

    #2
    Hello CelticTiger,

    Thank you for your post.

    Such a project would likely be best made as an Add On so that not only would it not disable like a strategy but also that it could watch all account position, execution, and order events as needed.

    We don't provide programming services but I can help you get started on this project.

    Please refer to the following links for details on the items you will need to begin this project:
    If you would like to seek a third party to develop such an item for you I can have our affiliate NinjaTrader Ecosystem follow up with a list of NinjaScript Consultants.

    Please let me know if you have any questions.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Hi Patrick, Thank you for your answer. Yes please send me a list with consultants. Now if I get this programme and integrated so that the account is prevented from initiating new trades, what happens when you release the next update, will the code need to be updated?

      Are there no plans to release a function like this with Ninjatrader 8? Dependant on the costs I might have no other choice other than going with Sierra, very disappointing if that is the case, I am not sure why this is not an out of the box feature? Regards, Peter

      Comment


        #4
        Hello CelticTiger,

        Thank you for your response.

        I will have our affiliate NinjaTrader Ecosystem follow up with the list of NinjaScript Consultants.

        If you do have an add on built for NinjaTrader 8 it should function in NinjaTrader 8 through iterations. There are only code breaking changes between major changes of the platform such as from NinjaTrader 6.5 to NinjaTrader 7 and NinjaTrader 7 to NinjaTrader 8.

        I can forward your request to our development team for potential implementation in a future release of NinjaTrader.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Thank you, I hope I can get this implemented in the DNA of NT8 so that it works well. There will be more and more experienced traders asking for this, especially if they look at their Daily P&L curve and find out that they would already be profitable if only the few disaster Days are kept under control...

          Comment


            #6

            Hello CelticTiger ,

            You can search our extensive library of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more:
            You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third-party services for NinjaTrader, all pricing and support information will need to be obtained through the consultant.

            This NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The companies and services listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem, LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
            Christopher S.NinjaTrader Customer Service

            Comment


              #7
              Hello CelticTiger,

              Thank you for your patience.

              The internal tracking id for your request has been assigned the id SFT-2936.

              When a feature request is implemented, you'll find it in the release notes: http://ninjatrader.com/support/helpG...ease_notes.htm

              Please let me know if you have any questions.
              Patrick H.NinjaTrader Customer Service

              Comment


                #8
                Hello Patrick, Thank you for taking this back and putting it into development, that is great news! I think this feature can attract more people to trade via Ninja Trader, for the time being, I am subscribing to Sierra Charts to get this 1st line of defense established protecting my capital and have my Ninja Charts just running for viewing charts. I am volunteering to be a beta tester for this feature if possible?

                It would be awesome to have this function be a once set you can not change it for that day function, for example, you set it to 500 USD Daily loss limit then you apply it and until the session is over you can not change the limit anymore and only continue trading SIM or you can choose to leave it as maintainable- same with the weekly jut there from weekend to weekend. That way folks can decide how much control they need to protect them from emotional days.

                Regards,
                Peter
                Last edited by CelticTiger; 10-19-2018, 10:56 AM.

                Comment


                  #9
                  Hello CelticTiger,

                  Thank you for your response.

                  We appreciate your additional comments on this item. At this time we would not have a beta version for testing.
                  Patrick H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by futurenick, Today, 06:26 AM
                  1 response
                  11 views
                  0 likes
                  Last Post nkhoi
                  by nkhoi
                   
                  Started by NinjaCustomer, Today, 12:29 PM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_ShawnB  
                  Started by Steve L, Today, 11:32 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post Steve L
                  by Steve L
                   
                  Started by prabbala, Today, 10:41 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post prabbala  
                  Started by bebbus, Today, 10:36 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post bebbus
                  by bebbus
                   
                  Working...
                  X