Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Number of elements in data series

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

    Number of elements in data series

    How can I find the number of elements in my DataSeries.. I'm using the MAX and MIN and dont just want to put in a big number.

    #2
    For a DataSeries the number of elements is generally the number of bars on your chart. That number can be found by using CurrentBar.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      OK got the right bars now.. I do not want the dataSeries to contain 0 (zeros). I'v tried alot of gyrations, if statements, .Reset.. but even when I comment out my .Set statement,, the series stills fills with a 0 on every bar.. Anyway I can get rid of the zeros?
      Print statement below:
      dataSeries= 0 Session Bar # 107

      0 Session Bar # 0
      0 Session Bar # 1
      0 Session Bar # 2
      0 Session Bar # 3
      0 Session Bar # 4
      0 Session Bar # 5
      0 Session Bar # 6
      0 Session Bar # 7
      0 Session Bar # 8
      0 Session Bar # 9
      0 Session Bar # 10
      0 Session Bar # 11
      0 Session Bar # 12
      0 Session Bar # 13
      0 Session Bar # 14
      0 Session Bar # 15
      0 Session Bar # 16
      0 Session Bar # 17
      0 Session Bar # 18
      0 Session Bar # 19
      0 Session Bar # 20
      0 Session Bar # 21
      0 Session Bar # 22
      0 Session Bar # 23
      0 Session Bar # 24
      0 Session Bar # 25
      0 Session Bar # 26
      0 Session Bar # 27
      0 Session Bar # 28
      0 Session Bar # 29
      0 Session Bar # 30

      Comment


        #4
        Not sure what you are printing. Please provide your code. Thanks.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          /// // setup to display hhigh lowlow
          protected override void OnBarUpdate()
          {
          //profitSeries.Set(Performance.AllTrades.TradesPerfo rmance.Currency.CumProfit- priorTradesCumProfit);

          DrawTextFixed("PnL","Account\n Max High\n " + MAX(profitSeries,Bars.BarsSinceSession)[0].ToString("$0.00") ,TextPosition.TopRight);
          DrawTextFixed("PnS","Account\n Max Low \n" + MIN(profitSeries,Bars.BarsSinceSession)[0].ToString("$0.00") ,TextPosition.BottomRight);
          Print(profitSeries[0]+ " Session Bar # "+ Bars.BarsSinceSession);
          }

          Comment


            #6
            gg80108,

            You are printing a zero likely because your value is zero. Suggest you print the elements to your math calculation and see.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              I already tried the calculation, thats how I got into this observation.. First I thought because the calculation was 0 for the first bars, thats where the 0 was coming from.. Then I put an if statement to only do the .Set != 0.. didn't help.. Then I commented out the Set statement and an entry was there for each bar , the 0, even though no Set statement.. The only way I got ride of the 0 was just to use the .Set with a constant say -144 and each element was now -144.. When I do the MAX it recognizes 0 as the MAX and never gives me any negative numbers.

              Comment


                #8
                Whatever you are doing with MAX does not matter for your DataSeries. Please set your DataSeries after you have ensured you have at least one trade. Ensure the calculation before your print of the DataSeries. Ensure you have no errors in the Control Center logs.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  No sure what you mean that MAX doesn't matter when the .Set is operational it returns the MAX of the dataSeries > 0 and prints just like its suppose to .. I want Max to return the largest number even if all numbers are negative in the series,, this is where the 0 is causing the problem. Since I already couldn't filter the 0 out checking the calculation for 0 and not setting the series using an if statement..How to you want me to incorporate using a trade. The sequence is code copied below.

                  Comment


                    #10
                    The code you provided, MAX has no influence on the setting of your DataSeries. In fact, you even commented out the line where you do .Set for your DataSeries.

                    Please provide complete and exact code you are using.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      /// // setup to display hhigh lowlow
                      protected override void OnBarUpdate()
                      {
                      profitSeries.Set(Performance.AllTrades.TradesPerfo rmance.Currency.CumProfit- priorTradesCumProfit);

                      DrawTextFixed("PnL","Account\n Max High\n " + MAX(profitSeries,Bars.BarsSinceSession)[0].ToString("$0.00") ,TextPosition.TopRight);
                      DrawTextFixed("PnS","Account\n Max Low \n" + MIN(profitSeries,Bars.BarsSinceSession)[0].ToString("$0.00") ,TextPosition.BottomRight);
                      Print(profitSeries[0]+ " Session Bar # "+ Bars.BarsSinceSession);
                      }

                      Comment


                        #12
                        gg80108,

                        With such code your strategy never makes any trades. Without any trades Performance.AllTrades.TradesPerformance.Currency.C umProfit is guaranteed to be zero. I have no idea what your priorTradesCumProfit is set to, but when you print profitSeries[0] it will result in whatever that math ends up to be.

                        Your use of MAX() does not influence anything on the profitSeries DataSeries. You use it inside DrawText which does not change anything on profitSeries.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Here is all the code,, here also is a print of the output window. You may be wondering why I want to do this.. I didn't know what daily goal to set before I stop trading, so I needed a visual during testing to get an amount.. I found that my account was up $1k before drawing down.. guess what I now quit trading whenever my account hits 1K. The MAX and Min are for display purpose only!
                          I think what is happening is that if we believe that "Bars.BarsSinceSession", is valid for finding the number of bars in array,, then each bar element has to be filled with something(else the array count will be wrong),, if I don't set it, the "system automatically fills with a
                          0.. This accounts for the array being filled with 0s even if I dont set any values into array, or 0's when I dont set on every bar..


                          profitSeries value 0 Session Bar # 1
                          profitSeries value 0 Session Bar # 2
                          profitSeries value 0 Session Bar # 3
                          profitSeries value 0 Session Bar # 4
                          profitSeries value 0 Session Bar # 5
                          profitSeries value 0 Session Bar # 6
                          profitSeries value 0 Session Bar # 7
                          profitSeries value 0 Session Bar # 8
                          profitSeries value 0 Session Bar # 9
                          profitSeries value 0 Session Bar # 10
                          profitSeries value 0 Session Bar # 11
                          profitSeries value 0 Session Bar # 12
                          profitSeries value 0 Session Bar # 13
                          profitSeries value 0 Session Bar # 14
                          profitSeries value 0 Session Bar # 15
                          profitSeries value 0 Session Bar # 16
                          profitSeries value 0 Session Bar # 17
                          profitSeries value -357.999999999994 Session Bar # 18
                          profitSeries value -357.999999999994 Session Bar # 19
                          profitSeries value -357.999999999994 Session Bar # 20
                          profitSeries value -357.999999999994 Session Bar # 21
                          profitSeries value -357.999999999994 Session Bar # 22
                          profitSeries value -357.999999999994 Session Bar # 23
                          profitSeries value -357.999999999994 Session Bar # 24
                          profitSeries value -357.999999999994 Session Bar # 25
                          profitSeries value -357.999999999994 Session Bar # 26
                          profitSeries value -357.999999999994 Session Bar # 27
                          profitSeries value -357.999999999994 Session Bar # 28
                          profitSeries value -357.999999999994 Session Bar # 29
                          profitSeries value -261.999999999994 Session Bar # 30
                          profitSeries value -325.999999999997 Session Bar # 31

                          amespace NinjaTrader.Strategy
                          {
                          /// <summary>
                          /// Enter the description of your strategy here
                          /// </summary>
                          [Description("Enter the description of your strategy here")]
                          public class CCITrader : Strategy
                          {
                          #region Variables
                          // Wizard generated variables

                          private int StartTime = 093500; // Default setting for entry singal start time
                          private int ExitTime = 155500; // Default setting for exit time
                          private bool TimeToTrade = false;

                          private int maxTrades = 20; // Default setting for maximum number of trades in a session
                          private int maxProfit = 2000; // Default setting for maximum total profit in a session
                          private int maxLoss = 1000; // Default setting for maximum total loss in a session
                          private int maxRisk = 20; // Default setting for maximum risk in ticks per trade
                          private int trailStop = 15; // Default setting for Trailing Stop


                          private int s1S2Stop = 14; // Default setting for S1S2Stop
                          private int s1Profit = 10; // Default setting for S1Profit
                          private int t2Trailing = 14; // Default setting for T2Trailing
                          private int beginSession = 93500; // Default setting for BeginSession
                          private int endSession = 155500; // Default setting for EndSession
                          private bool zLR = true; // Default setting for ZLR
                          private bool famir = true; // Default setting for Famir
                          private bool ghost = true; // Default setting for Ghost
                          private int ProfitTarget1 = 10;
                          private int EntryQuantity1 = 1;
                          private int EntryQuantity2 = 1;
                          private int StopLoss = 18;

                          private double HHprofit = 0;
                          private double LLloss = 0;
                          private double profit=0;
                          private DataSeries profitSeries;

                          private int priorTradesCount = 0;
                          private double priorTradesCumProfit = 0;
                          // User defined variables (add any user defined variables below)
                          #endregion

                          /// <summary>
                          /// This method is used to configure the strategy and is called once before any strategy method is called.
                          /// </summary>
                          protected override void Initialize()
                          {
                          SetProfitTarget("S1", CalculationMode.Ticks, ProfitTarget1);
                          SetProfitTarget("L1", CalculationMode.Ticks, ProfitTarget1);
                          SetTrailStop("L2", CalculationMode.Ticks, 18, false);
                          SetTrailStop("S2", CalculationMode.Ticks, 18, false);

                          CalculateOnBarClose = true;
                          EntriesPerDirection = 1;
                          EntryHandling = EntryHandling.UniqueEntries;
                          profitSeries = new DataSeries(this);
                          }

                          // At the start of a new session

                          /// <summary>
                          /// Called on each bar update event (incoming tick)
                          /// </summary>
                          protected override void OnBarUpdate()
                          {

                          if (Bars.FirstBarOfSession)
                          {
                          //reset account display
                          HHprofit = 0;
                          LLloss = 0;
                          profit =0;
                          profitSeries.Reset();
                          DrawTextFixed("PnL","Account\n Max High\n " + "none",TextPosition.TopRight);
                          DrawTextFixed("PnS","Account\n Max Low\n " + "none" ,TextPosition.BottomRight);

                          // Store the strategy's prior cumulated realized profit and number of trades
                          /* NOTE: Using .AllTrades will include both historical virtual trades as well as real-time trades.
                          If you want to only count profits from real-time trades please use .RealtimeTrades. */
                          priorTradesCount = Performance.AllTrades.Count;
                          priorTradesCumProfit = Performance.AllTrades.TradesPerformance.Currency.C umProfit;
                          }

                          ///SESSION Starts Here
                          ///
                          /// // setup to display hhigh lowlow
                          if ((Performance.AllTrades.TradesPerformance.Currency .CumProfit- priorTradesCumProfit) != 0)
                          profitSeries.Set(Performance.AllTrades.TradesPerfo rmance.Currency.CumProfit- priorTradesCumProfit);

                          DrawTextFixed("PnL","Account\n Max High\n " + MAX(profitSeries,Bars.BarsSinceSession)[0].ToString("$0.00") ,TextPosition.TopRight);
                          DrawTextFixed("PnS","Account\n Max Low \n" + MIN(profitSeries,Bars.BarsSinceSession)[0].ToString("$0.00") ,TextPosition.BottomRight);
                          Print(" profitSeries value "+ profitSeries[0]+ " Session Bar # "+ Bars.BarsSinceSession);
                          /* Prevents further trading if the current session's realized profit exceeds $xxxxx or if realized losses exceed $xxxxx.
                          Also prevent trading if xxx trades have already been made in this session. */
                          if (Performance.AllTrades.TradesPerformance.Currency. CumProfit - priorTradesCumProfit >= MaxProfit //Profit
                          || Performance.AllTrades.TradesPerformance.Currency.C umProfit - priorTradesCumProfit <= (-1 * MaxLoss) //Loss
                          || Performance.AllTrades.Count - priorTradesCount > MaxTrades) //Trades
                          // close hanging orders new orders fire same as moneymanagement stop
                          {
                          if (Position.MarketPosition == MarketPosition.Long)
                          ExitLong();
                          if (Position.MarketPosition == MarketPosition.Short)
                          ExitShort();
                          DrawText("AM"+ CurrentBar, "AMstop", 0,High[0]+ TickSize *5, Color.Red);
                          return;
                          }

                          //Only trade between between start and exit time
                          if (ToTime(Time[0]) > StartTime && ToTime(Time[0]) < ExitTime)
                          {
                          TimeToTrade = true;
                          BackColor = Color.MistyRose;
                          }
                          else
                          {
                          TimeToTrade = false;
                          BackColor = Color.LightGray;
                          return;
                          }

                          // Condition LONG set 1

                          // get cci forcaster zlrs test
                          //parameters x,x,x,x,maxsignal for zlr
                          if (CCIForcasterReturn(4, 200, 3, 50, 50, 15, 1, 14, 100, 12, "Points", 10, 10, 185, 185).ZLRL.Get(CurrentBar)
                          && VolCum()[0] > VolCum()[1] && VolCum() [1] != 0 )

                          {
                          DrawText("ZRL"+ CurrentBar, "ZLR\nL "+ ( High[0] ).ToString("0.0"), 0,High[0]+ TickSize *25, Color.Blue);
                          EnterLong(EntryQuantity1, "L1");
                          EnterLong(EntryQuantity2, "L2");
                          SetStopLoss("L1", CalculationMode.Ticks, StopLoss, false);


                          //
                          }

                          // Condition Short set 2
                          //parameters x,x,x,x,maxsignal for zlr
                          if (CCIForcasterReturn(4, 200, 3, 50, 50, 15, 1, 14, 100, 12, "Points", 10, 10, 185, 185).ZLRS.Get(CurrentBar)
                          && VolCum()[0] < VolCum()[1] && VolCum() [1] != 0 )
                          {
                          DrawText("ZRLs"+ CurrentBar, "ZLS\nL "+ ( High[0] ).ToString("0.0"), 0,High[0]+ TickSize *25, Color.Red);
                          EnterShort(EntryQuantity1, "S1");
                          EnterShort(EntryQuantity2, "S2");
                          SetStopLoss("S1",CalculationMode.Ticks,StopLoss, false);
                          //
                          }
                          //display account info

                          // if (profit > HHprofit)
                          // {
                          // HHprofit = profit;
                          // DrawTextFixed("PnL","Account\n Max High\n " + HHprofit.ToString("$0.00") ,TextPosition.TopRight);
                          // }
                          // if (profit < LLloss)
                          // {
                          // LLloss = profit;
                          // DrawTextFixed("PnS","Account\n Max Low \n" + LLloss.ToString("$0.00") ,TextPosition.BottomRight);
                          //
                          // }


                          }
                          Last edited by gg80108; 04-18-2009, 10:20 AM.

                          Comment


                            #14
                            gg80108,

                            The reason you are likely getting some zeroes is because you use .Reset(). For your intents and purposes there should be no reason to use .Reset(). You should just set the value you want on every single bar.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally I had no reset and had the same outcome...

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              581 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              338 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              554 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              552 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X