Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Quick Questions regarding strategy historical processing

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

    Quick Questions regarding strategy historical processing

    Hi,

    I have a strategy that manages its own ongoing balance (AccountBalance). I set the initial value in the strategy dialog in the beginning, and then the strategy manages the ongoing total based on profit/loss.

    When i run this strategy live at the beginning of each day, it goes back and processes a significant amount of historical data and virtual trades (seems like about two weeks worth or more). The end result is that after it processes this historical data, the account balance is very wrong to start the trading day.

    I have min bars required set to zero, and i also have the lookback number of minutes set to only 60. For some reason, it still processes a couple of weeks of historical data.

    How can i keep the strategy from processing historical trades? I used the (Historical) function, but this will keep any historical data from being processed and will impact the signal generating functions of the strategy.

    Any ideas how I can keep my account balance from being updated before the strategy begins to process live orders?

    Thanks

    #2
    You can just let it run and do its thing and then as it goes live, reset the AccountSize value.

    Code:
    if (!Historical && setAccount)
    {
         AccountSize = 25000;
         setAccount = false;
    }
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      now that is good thinkin'!

      Thanks!

      Comment


        #4
        So, i think this will fix my core problem and allow the strategy to execute ok.

        But, won't this throw off my profit related metrics? For example, i track and report on cumulative profit...since it is processing all these historical trades (virtually), it will think it has amassed this profit prior to ever processing a live order.

        is there anything easily done about that? Its not the end of the world, but it would be nice to produce accurate statistics.

        Thanks

        Comment


          #5
          Not sure what you mean. Profit performance is not influenced at all.


          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Hi,

            I use this statement to add trade profit to my running balance during processing:

            Positions[currentStock.GetIndex()].GetProfitLoss(Close[0], PerformanceUnit.Currency)


            What I am finding is that when i run the strategy live, it preprocesses a bunch of historical data and runs up the balance prematurely. Is there some way to only take profit/loss from real time trades? Maybe that is my mistake.

            thanks

            Comment


              #7
              First, remember GetProfitLoss() is unrealized PnL. I recommend you use the Performance class and just aggregate those.

              Code:
              if (Performance.RealtimeTrades.Count > 0) 
              { 
                  // Get the last completed real-time trade 
                  Trade lastTrade = Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 1];
              
                  // Calculate the PnL for the last completed real-time trade 
                  double lastProfit = lastTrade.ProfitCurrency * lastTrade.Quantity; 
               
                  // Pring the PnL to the Output window 
                  Print("The last trade's profit is " + lastProfit); 
              }
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Great, thanks. I will switch to that!

                Comment


                  #9
                  Hi Josh,

                  I switched to this method of profit calculation, but it seems a little flaky.

                  Basically, I am calling "ExitLong()..."

                  and then I am generating an email that immediately sends me the P/L based on the code you provided. Unfortunately, it is sending me some numbers that don't correlate to the real P/L of the trade (not even close, really).

                  Is there any requirement that I must wait until another bar is processed to use this code, or should it work on the same bar immediately after calling ExitLong?

                  Thanks!

                  Comment


                    #10
                    bridenour,

                    Just because you called ExitLong() does not mean the order was filled by the exchange yet. You need to wait for your order to be filled before you will receive proper values.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Ok, thats what i was afraid of. What do you think is a "best practice" for this? Simply wait until the next bar arrives? Or is there a more surefire approach?

                      Comment


                        #12
                        If you have the ExitLong() stored to an IOrder you can use OnOrderUpdate() and OnExecution() to track the status of the order. When you receive an order state of Filled then you know you can run your profit checks.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Ok i will give that a shot.

                          one thing i noticed -- when I submit a market order, it is often filled in multiple batched. When i execute your real time trade profit code, it seems like it is only grabbing one of these partial fills, and not the profit for the overall market order. In order words, it seems like each partial fill for a single market order is tracked as an individual real time trade, making it difficult to get an overall P/L for the entire trade.

                          Does this agree with your understanding?

                          Thanks

                          Comment


                            #14
                            Hello,

                            I am not sure. I will have someone respond to this post on Monday.
                            DenNinjaTrader Customer Service

                            Comment


                              #15
                              I do have the IOrder stored and am using OnExecution. Does a single market order get stored to multiple "trades" (such as each partial fill is stored on a "trade")? If so, is there any way to group them logically to sum up the total P/L?

                              Thanks!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by judysamnt7, 03-13-2023, 09:11 AM
                              4 responses
                              59 views
                              0 likes
                              Last Post DynamicTest  
                              Started by ScottWalsh, Today, 06:52 PM
                              4 responses
                              36 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by olisav57, Today, 07:39 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post olisav57  
                              Started by trilliantrader, Today, 03:01 PM
                              2 responses
                              22 views
                              0 likes
                              Last Post helpwanted  
                              Started by cre8able, Today, 07:24 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post cre8able  
                              Working...
                              X