Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Daily Profit/Loss Halt code, need assistance please

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

    Daily Profit/Loss Halt code, need assistance please

    Hello, I recently downloaded the SampleHaltBasicStrategy_NT8 script off another thread on this forum and attempted to integrate the logic into a Sample Ma Crossover strategy. The strategy compiled and the strategy makes trades but it does not stop when the loss or profit limits are reached. The script code is attached along with a copy of the sample Halt strategy that Ninjatrader provided. Can someone please point me in the right direction on why this is not working properly? Thanks

    SampleMA_DailyLimitHalt.zip

    SampleHaltBasicStrategy_NT8.zip

    #2
    Hello bassgoboom,

    I'm not seeing any stop loss or profit target with SetStopLoss() or SetProfitTarget() or ExitLongLimit() or ExitLongStop() used anywhere in the script.

    I recommend that you use prints to understand the behavior.

    Below is a link to a forum post that demonstrates how to use prints to debug a script.


    Print the time and all values used in the condition that places the order in question to the output window.
    Are you seeing that the condition is evaluating as true?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      The strategy doesn't use Stop Loss or Profit Target. It continuously trades the MA crosses until you stop the strategy. Each MA cross reverses the previous entry.

      Comment


        #4
        Hello bassgoboom,

        The SampleHaltBasicStrategy checks if SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit is outside of a certain range, calls the StopStrategy method which cancels entry orders and exits open positions, and then reaches a return statement which then prevents the strategy from processing further.

        If you are seeing that the strategy is continuously taking trades, this would mean that trades are being taken before this return statement is reached. As we can see from your code, the strategy is submitting orders before checking if it should stop and cease processing.

        Code:
        [B]if (CrossAbove(smaFast, smaSlow, 1))
            EnterLong();
        else if (CrossBelow(smaFast, smaSlow, 1))
            EnterShort();[/B]
        
        if (CurrentBar < BarsRequiredToTrade)
            return;
        // After our strategy has a PnL greater than $1000 or less than -$400 we will stop our strategy
        if (SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit > 100
            || SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit < -250)
        {
            /* A custom method designed to close all open positions and cancel all working orders will be called.
            This will ensure we do not have an unmanaged position left after we halt our strategy. */
            StopStrategy();
        
            // Halt further processing of our strategy
            return;
        }
        Please let us know if we can be of further assistance.
        Last edited by NinjaTrader_Jim; 01-16-2019, 01:50 PM.

        Comment


          #5
          So, a follow up to this -
          can
          SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit be used inside an incator code to just show the realized PnL at the bottom left corner of a chart..?? (using Draw.TextFixed..

          Comment


            #6
            Hello shanshan1001,

            Thanks for your question.

            SystemPerformance only exists in the context of a strategy and gives a report for that strategy's performance. A strategy's performance cannot be fetched from an indicator as strategy positions are handled as unique positions owned by the strategy, not to be confused with the entire position on the account.

            If you would like to view account level PnL per instrument from an indicator, you may wish to use an indicator similar to the following.

            Position Display Indicator - https://ninjatraderecosystem.com/use...lay-indicator/

            The 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 add-ons 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.

            Please let me know if there is anything else we can do to help.

            Comment


              #7
              JIm
              THat's very useful. Thanks for your help.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Yesterday, 05:17 AM
              0 responses
              56 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              132 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              73 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              45 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              49 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X