Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Analyzer discrepancies

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

    #16
    Ok, now the strategy compiles with no error.
    However, it gives me only one TOTAL Unrealized P/L at the end of the session.
    Since the DrawText instruction was put after any Entry/Exit, I understood it was possible to get and display it on the chart for each closed trade: is this not allowed ?
    And may the string be printed also in other fonts and sizes ?
    Attached Files

    Comment


      #17
      Hi fliesen,

      If you would like a text box on each bar, you will need to use a unique tag for each draw text call, otherwise when reusing a tag name this will overwrite the older text box.

      For example:
      DrawText("PnLTag1"+CurrentBar, "Unrealized PnL: " + Position.GetProfitLoss(Close[0], PerformanceUnit.Currency).ToString(), 0, Close[0], Color.Black);
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Previously I got only one P/L in the whole day; now I get it for ANY candle - even when there are no pending trades.
        Is it not possible to print the P/L just whenever a trade is closed, as its final result, and even better, next the "Close Position" remark, as in the red box of my attachment ?
        Moreover, what do the "+" sign and the arrow in the yellow box mean ?
        Finally, may I draw a text in bold or other fonts ?
        Attached Files

        Comment


          #19
          Hello fliesen,

          You can print the PnL when an order closes.

          To do this you will need to detect the exit order filling in OnOrderUpdate and then draw the box when it is detected.

          For example:
          Code:
          protected override void OnOrderUpdate(IOrder order)
          {
          if (order.OrderState == OrderState.Filled && order.Name == "^-")
          {
          DrawText("PnLTag2", "Last trade PnL: " + (Performance.AllTrades[0].ProfitCurrency).ToString(), 0, Low[0]-5*TickSize, Color.Black);
          }		
          }
          It is not possible to add text to the execution marker. You can try and draw your text box below /above it though.

          The "+" sign in the execution marker text is the signal name you have chosen for your EnterLong call. The ExitLong call has a signal name of "^-".

          You can change the font to bold using a font object in the font overload parameter.

          For example:
          DrawText("PnLTag2", true, "Last trade PnL: " + (Performance.AllTrades[0].ProfitCurrency).ToString(), 0, Low[0]-5*TickSize, 0, Color.Black, new Font("Arial", 10f, FontStyle.Bold, GraphicsUnit.Pixel), StringAlignment.Center, Color.Empty, Color.Empty, 10);

          DrawText(string tag, bool autoScale, string text, int barsAgo, double y, int yPixelOffset, Color textColor, Font font, StringAlignment alignment, Color outlineColor, Color areaColor, int areaOpacity)
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            Followed your guidelines, but unfortunately, I still see no PnL marker of the just closed trades. Actually, now I get NO PnL indication at all.
            To avoid disturbing you long time for this thread, could you directly run my code and check what is wrong with it ?

            (By the way: is it normal that trades disappear from the Strat.Analyzer's chart as soon as I load the chart template with the strategy's indicators ?)
            Attached Files

            Comment


              #21
              Hi fliesen,

              The issue is that the ExitShort("^+", ""); and ExitLong("^-", ""); calls are not being triggered. Instead, you are changing positions from to short or short to long.

              If you are in a short position and you call EnterLong(), NinjaTrader automatically exits your current position and will enter you into the new position. Calling ExitLong() and then EnterShort() will usually cause problems with your script.

              In this case, we also need to detect when the Close position order is filled as well as the sell order is filled. Close position is the order name when NinjaTrader automatically exits your order when reversing your position.

              Change:
              if (order.OrderState == OrderState.Filled && (order.Name == "^+" || order.Name == "^-")

              To:
              if (order.OrderState == OrderState.Filled && (order.Name == "^+" || order.Name == "^-" || order.Name == "Close position") || order.Name == "Buy to cover" || order.Name == "Sell")
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Fine, now things look much better. The only problem, the P/L is the same (-104) for ALL trades.
                How must this "Performance.AllTrades[0].ProfitCurrency" function be changed in order to display the P/L of each closed trade ?

                And by the way: is it normal that trades disappear from the Strat.Analyzer's chart as soon as (for a strategy verification) I load the chart template with the indicators included in the strategy ? If so, no chance to verify it....
                Last edited by fliesen; 04-17-2014, 02:05 AM.

                Comment


                  #23
                  Hi fliesen,

                  I had the index of the performance collection backwards. The most current trade is the count-1 not 0.

                  Try Performance.AllTrades[Performance.AllTrades.Count-1].ProfitCurrency.

                  Using Performance.AllTrades[0].ProfitCurrency would always return the first trade (but not all trades).

                  Attached is a sample script that demonstrates this. You'll need to open the Output window to see the prints.
                  (Tools -> Output Window...)
                  Attached Files
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Yes it works.
                    Thanks a lot.

                    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
                    21 views
                    0 likes
                    Last Post helpwanted  
                    Started by cre8able, Today, 07:24 PM
                    0 responses
                    10 views
                    0 likes
                    Last Post cre8able  
                    Working...
                    X