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

Account Performance

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

    Account Performance

    Hello,
    I added the SampleHaltStrategy example to my strategy to get an idea of how it would work. I only get 3 trades on my opening chart and then the strategy takes no more trades. It seems that the StopStrategy() can stop the strategy ok, but doesn't restart it the next day. Can someone give me an example of how to start everything up the next day. Here is my code. Maybe I've done something wrong.

    if (Performance.AllTrades.TradesPerformance.Currency. CumProfit > 1000
    || Performance.AllTrades.TradesPerformance.Currency.C umProfit < -400)

    {
    StopStrategy();
    return;
    }
    Print("OnBarUpdate(): " + Time[0]);
    {
    my strategy conditions
    }
    private void StopStrategy()
    {

    // If we have a position we will need to close the position
    if (Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong("End Trading", "VCR Long");
    ExitLong("End Trading", "Runner Long");
    }
    else if (Position.MarketPosition == MarketPosition.Short)
    {
    ExitShort("End Trading", "VCR Short");
    ExitShort("End Trading", "Runner Short");
    }

    #2
    Hello CaptainAmericaXX,

    It seems that the StopStrategy() can stop the strategy ok, but doesn't restart it the next day.
    Correct - This is the intended design of the sample. If you are looking for help resetting performance values for each new session, there is a dedicated sample for that:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks for that info. I have a further question. Is there a way to reset without a "tradecounter".? I'm not interested in limiting the amount of trades but the amount of money lost.

      Comment


        #4
        Yes, this is possible. It's a little more involved as you have to work directly with trade performance class and do some looping through last so many trades.

        This sample is more suited for what you're looking to do:


        if (Bars.FirstBarOfSession && FirstTickOfBar)
        {
        lastThreeTrades = 0;
        priorSessionTrades = Performance.AllTrades.Count;
        }

        /* Here, Performance.AllTrades.Count - priorSessionTrades checks to make sure there have been three trades today.
        priorNumberOfTrades makes sure this code block only executes when a new trade has finished. */
        if ((Performance.AllTrades.Count - priorSessionTrades)


        That line highlighted along with the FirstBarOfSession block are key to getting the trade count for the current session.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks Ryan

          Comment


            #6
            Hello,
            There is a specific trade condition that may sometimes "get my strategy going" first thing in the morning. Other strategy condition may have already started before market open and I miss the move if I wait for those conditions. This specific condition I would only consider 1st thing in the morning. I believe Performance.AllTrades.Count will help me to identify the "first thing in the morning" idea, but I don't know how to say it. Anyone have a suggestion on how to program this idea?

            Comment


              #7
              You can identify the first bar of the session with Bars.FirstBarOfSession

              Can also work with Bars.BarsSinceSession to return the number of bars that has passed since session start.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Oops I stated my question wrong. I won't have any problem taking that first trade. It's after that first trade that I wouldn't want to take it again. I believe I could set a bool flag to that trade once it was taken, but if the conditions for that trade were never met and the regular conditions called a trade I would not want the strategy to look for that "1st trade" anymore. I hope that makes sense.

                Comment


                  #9
                  Yes, you can control the sequence you want to check for with custom programming. Bool flags can be used for this and if you need to reset their value at the start of the day, use Bars.FirstBarOfSession mentioned earlier.
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Ryan. I'll play around with that.

                    Comment


                      #11
                      Perhaps Ryan has already answered this and I just haven't figured it out yet, but I have a further question about ending trading when a profit or loss has been met. I found the SamplePnLStrategy and it is working better than the StopStrategy(), but if on the last trade where the PnL has been met, the regular exit conditions are somehow made null and the exit is made on close of market. I took out the priorTradesCount because I don't know how many trades it will take to reach my PnL. I though of ToTime( ), but again I don't know what time the PnL will be met. Is there another way to end the strategy when the PnL is met?
                      Thanks

                      Comment


                        #12
                        If you have the conditions for stopping a strategy worked out, then you can custom code handling for the strategy to cancel orders, close positions, and not accept further signals.

                        This sample has a special StopStrategy() method that first cancels orders, closes positions, and sets a bool flag that when true prevents all strategy processing.

                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          That did it. Not sure why it didn't work before. Thanks

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Segwin, 05-07-2018, 02:15 PM
                          10 responses
                          1,769 views
                          0 likes
                          Last Post Leafcutter  
                          Started by Rapine Heihei, 04-23-2024, 07:51 PM
                          2 responses
                          30 views
                          0 likes
                          Last Post Max238
                          by Max238
                           
                          Started by Shansen, 08-30-2019, 10:18 PM
                          24 responses
                          943 views
                          0 likes
                          Last Post spwizard  
                          Started by Max238, Today, 01:28 AM
                          0 responses
                          10 views
                          0 likes
                          Last Post Max238
                          by Max238
                           
                          Started by rocketman7, Today, 01:00 AM
                          0 responses
                          7 views
                          0 likes
                          Last Post rocketman7  
                          Working...
                          X