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

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.
        JimNinjaTrader Customer Service

        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.
            JimNinjaTrader Customer Service

            Comment


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

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by FAQtrader, Today, 12:00 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by pechtri, 06-22-2023, 02:31 AM
              4 responses
              113 views
              0 likes
              Last Post Nyman
              by Nyman
               
              Started by Tim-c, Today, 03:54 AM
              2 responses
              11 views
              0 likes
              Last Post Tim-c
              by Tim-c
               
              Started by gnocchi, Today, 11:56 AM
              1 response
              2 views
              0 likes
              Last Post NinjaTrader_Zachary  
              Started by geddyisodin, Today, 05:20 AM
              5 responses
              32 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Working...
              X