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

Cumulitive Profit not changing..

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

    Cumulitive Profit not changing..

    Using the script below from NT's SamplePnL strategy but it doesn't appear to be working. I put in a print statement for priorTradesCumProfit and it never changes. It's always 0. Is there anything wrong with the script below?

    if (Bars.FirstBarOfSession)
    {
    priorTradesCumProfit = Performance.AllTrades.TradesPerformance.Currency.C umProfit;

    }
    if (Performance.AllTrades.TradesPerformance.Currency. CumProfit - priorTradesCumProfit <= -1500)

    {
    return;
    }

    #2
    I dont see anything "wrong" with this script snippet here.

    Is you system triggering any historical trades?

    When you perform your print where are you placing the print statement?
    LanceNinjaTrader Customer Service

    Comment


      #3
      This is in Backtesting. Print statement is in OBU below EnterLongLimit. I'm just looking for it to calculate the Cumulitive profit at the start of everday. And then from that point on in the day if it goes below -1500 PnL to stop any further trades. Do I have to possibly do a BIP to make sure it's using a Daily bar?

      Comment


        #4
        Originally posted by zachj View Post
        Print statement is in OBU below EnterLongLimit.
        Is the entry getting filled at a later point? If yes are there exits ever getting filled?

        If you print this at the same time your entering the long limit it could vary well be zero if not trades have been completed yet.

        There are a lot of potential reasons here and the issue will need to be debugged. But your initial syntax does look correct to me.
        LanceNinjaTrader Customer Service

        Comment


          #5
          There's trades completed from it already running a month back, so I don't see how the Cumulitive PnL could be 0.

          Comment


            #6
            I'd need more information about the script before I can provide any additional assistance. Do you have a simple script that replicates the issue?
            LanceNinjaTrader Customer Service

            Comment


              #7
              Let me try some more debugging on it first, just wanted to make sure I wasn't missing something simple. thanks

              Comment


                #8
                I moved the PnL condition outside of the BIP IF statement and it started showing figures for priorTradesCumProfit.

                Issue now is... I have one day where the PnL goes way under -1500. Calculating the PnL by tracking the exited positions for that day, at around 2:15pm the 7th exited position puts it over the -1500 PnL but all the other positions were entered way before 2:15pm and are still active.

                So my question is.. is there any way to have it track the PnL sec by sec or min by min instead of via exited positions? Via exited positions its way too late. I asssume on this particular day it went -1500 early in the am.
                Last edited by zachj; 10-24-2013, 09:16 PM.

                Comment


                  #9
                  As you have noticed the results you have are for exited trades.

                  To get unrealized PnL you can do this:


                  You could then add this value to the total realized PnL you already have.

                  Let me know if I can further assist.
                  LanceNinjaTrader Customer Service

                  Comment


                    #10
                    Like this correct?

                    if ((Performance.AllTrades.TradesPerformance.Currency . CumProfit - priorTradesCumProfit) +
                    Position.GetProfitLoss(Close[0], PerformanceUnit.Points))

                    <= -1500)

                    Comment


                      #11
                      Looks correct. Just keep in mind the value here would be changing so you would need to decide after the condition is met to either close open positions or to just not allow additional trades.
                      LanceNinjaTrader Customer Service

                      Comment


                        #12
                        Lance. Only thing I see to stop the strategy once a -1500 unrealized loss is reached is the script below given in the haltstrategy sample. I was looking to just stop it for that particular day, is there any other option to halt trading just for the day and have it resume the next day? Some sort of reset type action maybe. Again just for backtesting purposes.

                        private void StopStrategy()
                        {
                        // If our Long Limit order is still active we will need to cancel it.
                        CancelOrder(entryOrder);

                        // If we have a position we will need to close the position
                        if (Position.MarketPosition == MarketPosition.Long)
                        ExitLong();
                        }
                        Last edited by zachj; 10-27-2013, 08:21 PM.

                        Comment


                          #13
                          by resetting your variable priorTradesCumProfit at the start of each session you will be able to get new values each day. However if you hold trades overnight you will have to implement additional logic to account for these trades not yet included in the cumulative profit.

                          LanceNinjaTrader Customer Service

                          Comment


                            #14
                            I think I see the issue, within StopStrategy() it's hitting CancelOrder(entryOrder) which cancels all orders as it should but when it gets to the line...
                            //If we have a position we will need to close the position
                            if (Position.MarketPosition == MarketPosition.Long)
                            ExitLong()

                            it's not exiting the positions that were already open and it's carrying those positions overnight and actually to the end of the backtest period which is like a week later. It's also not allowing any new trades the next day because the unrealized loss is still active at below -1500.

                            Any idea why it might not be exiting the active positions?
                            Last edited by zachj; 10-29-2013, 09:56 PM.

                            Comment


                              #15
                              It's hard for me to say without seeing the code. Things you might want to check are, first ensuring the ExitLong() is being called. Ensuring the signal names match, and ensure it's tied to the correct Bars In Progress.
                              Those are going to be the big ones to check. Beyond that it will just be isolating the codes logic and checking it step by step.

                              When debugging strategies like this I often like to use drawing objects so I can see visually on the chart when the order should have been exited or why it might not have been called.

                              Let me know if I can further assist.
                              LanceNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by AttiM, 02-14-2024, 05:20 PM
                              12 responses
                              213 views
                              0 likes
                              Last Post DrakeiJosh  
                              Started by cre8able, 02-11-2023, 05:43 PM
                              3 responses
                              238 views
                              0 likes
                              Last Post rhubear
                              by rhubear
                               
                              Started by frslvr, 04-11-2024, 07:26 AM
                              8 responses
                              117 views
                              1 like
                              Last Post NinjaTrader_BrandonH  
                              Started by stafe, 04-15-2024, 08:34 PM
                              10 responses
                              47 views
                              0 likes
                              Last Post stafe
                              by stafe
                               
                              Started by rocketman7, Today, 09:41 AM
                              3 responses
                              12 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X