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

new bar type with variable range

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

    new bar type with variable range

    Hi, I am trying to develop a bar type that creates new bar when the height of a bar exceeds a value that comes from some calculation, e.g., 4 times the ATR value of period 10. It is technically a range bar that its range value changes. I came up with this code but does not seem to be correct. I appreciate if you could give me some hints as to what might be the problem. Thank you in advance.

    Code:
    namespace NinjaTrader.NinjaScript.BarsTypes
    {
        public class zATRbar : BarsType
        {
            // Define constants and variables at the class level
            private const int atrPeriod = 4; // Number of bars to compute ATR
            private List<double> trueRanges = new List<double>(); // List to store true ranges
            private double atrValue = 0; // The computed ATR value
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description = @"Volatility bar";
                    Name = "zATRbar";
                    BarsPeriod = new BarsPeriod { BarsPeriodType = (BarsPeriodType)15, Value = 1 };
                   // BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1 };
                    BuiltFrom = BarsPeriodType.Minute;
                    DaysToLoad = 5;
                    IsIntraday = true;
                    IsTimeBased        = false;
                }
                else if (State == State.Configure)
                {
                    Name = string.Format("zATRbar");
    
                    Properties.Remove(Properties.Find("BaseBarsPeriodType",            true));
                    Properties.Remove(Properties.Find("BaseBarsPeriodValue",        true));
                    Properties.Remove(Properties.Find("PointAndFigurePriceType",    true));
                    Properties.Remove(Properties.Find("ReversalType",                true));
                    Properties.Remove(Properties.Find("Value2",                        true));
                }
            }
    
            public override int GetInitialLookBackDays(BarsPeriod barsPeriod, TradingHours tradingHours, int barsBack)
            {
                return 1;
            }
    
            protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask)
            {
                
                //if (trueRanges.Count < atrPeriod) return;
                
                // Compute the True Range for the current tick
                double trueRange;
                if (bars.Count == 0) // First bar
                {
                    trueRange = high - low;
                }
                else
                {
                    trueRange = Math.Max(high - bars.GetClose(bars.Count - 1), Math.Max(bars.GetClose(bars.Count - 1) - low, high - low));
                }
    
                // Add the true range to the list and maintain the list's length
                trueRanges.Add(trueRange);
                if (trueRanges.Count > atrPeriod)
                {
                    trueRanges.RemoveAt(0); // Remove the oldest value
                }
    
                // Compute the ATR
                atrValue = trueRanges.Average();
                Print(atrValue);
                // Decide whether to add a new bar or update the current one
                if ((high - low) >= atrValue * 1)
               {
                AddBar(bars, open, high, low, close, time, volume);
                }
                else
                {
                    // If you don't add a new bar, you may want to update the current bar.
                    UpdateBar(bars, high, low, close, time, volume);
                }
            }
    
            public override void ApplyDefaultBasePeriodValue(BarsPeriod period)
            {
                //replace with any default base period value logic
            }
    
            public override void ApplyDefaultValue(BarsPeriod period)
            {
                //replace with any default value logic
            }
    
            public override string ChartLabel(DateTime dateTime)
            {
                return dateTime.ToString();
            }
    
            public override double GetPercentComplete(Bars bars, DateTime now)
            {
                return 1.0d; // replace with your bar percent logic if needed
            }
        }
    }​

    #2
    Hello Photon66,

    Thank you for your post.

    Please note that our support would not be able to assist with designing custom logic, but we are happy to assist with guiding you through the debugging process to help you understand your code.

    This thread will remain open for any community members that would like to help with creating custom logic.



    If you would like assistance with the debugging process, can you clarify exactly what exactly is incorrect with the script? Are you seeing any errors in the Log tab of the Control Center?

    To understand why the script is behaving as it is, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the script add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition.

    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    I am happy to assist you with analyzing the output from the output window.

    Run the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

    Below is a link to a forum post that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.



    Please let me know if I may further assist with analyzing the output or if you need any assistance creating a print.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Click image for larger version

Name:	atr bar.png
Views:	113
Size:	150.9 KB
ID:	1285824 Thanks for the reply. When the chart is started, the historic bars look ok; however, as it gets to current bars, it starts to print a lot of zero bars ( zero or 1 range bar every few second quickly). I attach the snapshot. Here is also an example of the print output. You see many zeros and small values that are printed very quickly.
      0.1875
      0.1875
      0.1875
      0.125
      0.125
      0.1875
      0.1875
      0.1875
      0.125
      0.0625
      0
      0
      0
      0
      0​
      0
      0
      0
      0
      0
      0
      0
      0.0625
      0.125
      0.125
      0.125
      0.0625
      0.0625
      0.0625
      0.0625
      0.0625
      0.0625
      0.125
      0.125
      0.125
      0.0625
      0
      0
      0

      Comment


        #4
        Hello,

        Are these prints just printing atrValue?

        It would be helpful to add additional prints that print the values used for the logic of the script, including a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

        This way we can see how the logic being used to calculate atrValue is evaluating as 0.

        Add a print before and after each condition for example,


        Code:
        Print("bars.Count: " + bars.Count);
        
        if (bars.Count == 0) // First bar
        
        {
        
        trueRange = high - low;
        
        Print("trueRange: "+ trueRange);
        
        }
        
        else
        
        {
        
        trueRange = Math.Max(high - bars.GetClose(bars.Count - 1), Math.Max(bars.GetClose(bars.Count - 1) - low, high - low));
        
        Print("trueRange: "+ trueRange);
        
        }
        ​
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the reply. I added these print lines:
          Code:
                      double trueRange;
                      Print("----bars.Count: " + bars.Count);
                      if (bars.Count == 0) // First bar
                      {
                          trueRange = high - low;
                          Print("trueRange(1): "+ trueRange);
                      }
                      else
                      {
                          trueRange = Math.Max(high - bars.GetClose(bars.Count - 1), Math.Max(bars.GetClose(bars.Count - 1) - low, high - low));
                          Print("trueRange(2): "+ trueRange);
                      }
          
                      // Add the true range to the list and maintain the list's length
                      trueRanges.Add(trueRange);
                      if (trueRanges.Count > atrPeriod)
                      {
                          trueRanges.RemoveAt(0); // Remove the oldest value
                      }
          
                      // Compute the ATR
                      atrValue = trueRanges.Average();
                      Print("atrValue:" + atrValue);​
          This is a part of the output:
          .
          .
          .

          ----bars.Count: 1018
          trueRange(2): 1.25
          atrValue:1.9375
          ----bars.Count: 1018
          trueRange(2): 1.25
          atrValue:1.625
          ----bars.Count: 1018
          trueRange(2): 1
          atrValue:1.375
          ----bars.Count: 1018
          trueRange(2): 1.25
          atrValue:1.1875
          ----bars.Count: 1019
          trueRange(2): 3.5
          atrValue:1.75
          ----bars.Count: 1020
          trueRange(2): 2.5
          atrValue:2.0625
          ----bars.Count: 1021
          trueRange(2): 2.75
          atrValue:2.5
          ----bars.Count: 1022
          trueRange(2): 1.5
          atrValue:2.5625
          ----bars.Count: 1022
          trueRange(2): 1.25
          atrValue:2
          ----bars.Count: 1022
          trueRange(2): 1.75
          atrValue:1.8125
          ----bars.Count: 1022
          trueRange(2): 2
          atrValue:1.625
          ----bars.Count: 1023
          trueRange(2): 1.5
          atrValue:1.625
          ----bars.Count: 1023
          trueRange(2): 1.25
          atrValue:1.625
          ----bars.Count: 1023
          trueRange(2): 2
          atrValue:1.6875
          ----bars.Count: 1024
          trueRange(2): 10
          atrValue:3.6875
          ----bars.Count: 1025
          trueRange(2): 5.75
          atrValue:4.75
          ----bars.Count: 1026
          trueRange(2): 12.25
          atrValue:7.5
          ----bars.Count: 1026
          trueRange(2): 0
          atrValue:7
          ----bars.Count: 1026
          trueRange(2): 0.25
          atrValue:4.5625
          ----bars.Count: 1026
          trueRange(2): 0
          atrValue:3.125
          ----bars.Count: 1026
          trueRange(2): 0
          atrValue:0.0625
          ----bars.Count: 1026
          trueRange(2): 0
          atrValue:0.0625
          ----bars.Count: 1026
          trueRange(2): 0
          atrValue:0
          ----bars.Count: 1027
          trueRange(2): 0
          atrValue:0
          ----bars.Count: 1028
          trueRange(2): 0
          atrValue:0
          ----bars.Count: 1029
          trueRange(2): 0
          atrValue:0
          ----bars.Count: 1030
          trueRange(2): 0
          atrValue:0
          ----bars.Count: 1031
          trueRange(2): 0
          atrValue:0​
          .
          .
          .
          Thank you.

          Comment


            #6
            Hello,

            From the prints, it looks like the calculation for trueRange in the else statement (trueRange(2) print) is sometimes evaluating as 0, leading to the atrValue being 0 or very close to 0.

            I suggest adding an additional print statements for the calculations you are doing in those Math.Max methods to see why it is picking 0 as the maximum value.

            Print("high - bars.GetClose(bars.Count - 1): " + (high - bars.GetClose(bars.Count - 1).ToString());

            Print("bars.GetClose(bars.Count - 1) - low: " + (bars.GetClose(bars.Count - 1) - low).ToString());

            Print("high - low: " + (high - low).ToString());


            Please let me know if you need additional assistance.
            Gaby V.NinjaTrader Customer Service

            Comment


              #7
              Thanks for the reply. You are correct about the value going to zero. It happens right at the moment where it switches from historical to live data. I am confused that the new bar is based in 1min bars but it starts printing bars for every second with the bars go live. I expect every bar to be at least 1 minute apart but when it goes live it is much shorter. Thank you:
              .
              .
              .
              ----bars.Count: 1059
              trueRange(2): 2.5
              high - bars.GetClose(bars.Count - 1): 0.75
              bars.GetClose(bars.Count - 1) - low: 1.75
              high - low: 2.5
              atrValue:2.75
              ----bars.Count: 1059
              trueRange(2): 2
              high - bars.GetClose(bars.Count - 1): 1.25
              bars.GetClose(bars.Count - 1) - low: 0.75
              high - low: 2
              atrValue:2.6875
              ----bars.Count: 1059
              trueRange(2): 1.5
              high - bars.GetClose(bars.Count - 1): 0.75
              bars.GetClose(bars.Count - 1) - low: 0.75
              high - low: 1.5
              atrValue:2.4375
              ----bars.Count: 1059
              trueRange(2): 2
              high - bars.GetClose(bars.Count - 1): 1.75
              bars.GetClose(bars.Count - 1) - low: 0.25
              high - low: 2
              atrValue:2
              ----bars.Count: 1060
              trueRange(2): 3.25
              high - bars.GetClose(bars.Count - 1): 0
              bars.GetClose(bars.Count - 1) - low: 3.25
              high - low: 3.25
              atrValue:2.1875
              ----bars.Count: 1061
              trueRange(2): 1.25
              high - bars.GetClose(bars.Count - 1): 1.25
              bars.GetClose(bars.Count - 1) - low: -0.25
              high - low: 1
              atrValue:2
              ----bars.Count: 1061
              trueRange(2): 1.25
              high - bars.GetClose(bars.Count - 1): 1.25
              bars.GetClose(bars.Count - 1) - low: -1.25
              high - low: 0
              atrValue:1.9375
              ----bars.Count: 1061
              trueRange(2): 0
              high - bars.GetClose(bars.Count - 1): 0
              bars.GetClose(bars.Count - 1) - low: 0
              high - low: 0
              atrValue:1.4375
              ----bars.Count: 1061
              trueRange(2): 0
              high - bars.GetClose(bars.Count - 1): 0
              bars.GetClose(bars.Count - 1) - low: 0
              high - low: 0
              atrValue:0.625
              ----bars.Count: 1061
              trueRange(2): 0
              high - bars.GetClose(bars.Count - 1): 0
              bars.GetClose(bars.Count - 1) - low: 0
              high - low: 0
              atrValue:0.3125
              ----bars.Count: 1061
              trueRange(2): 0
              high - bars.GetClose(bars.Count - 1): 0
              bars.GetClose(bars.Count - 1) - low: 0
              high - low: 0
              atrValue:0
              ----bars.Count: 1062
              trueRange(2): 0
              high - bars.GetClose(bars.Count - 1): 0
              bars.GetClose(bars.Count - 1) - low: 0
              high - low: 0
              atrValue:0​

              Comment


                #8
                Hello,

                From OnDataPoint():

                "Historical data processing receives a single update for every base bar determined by the BuiltFrom property. Once transitioned to real-time, updates will call on every tick processed by the core."



                This is why you are seeing more than one update per bar once it transitions to real time.
                Gaby V.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks for catching the problem. How can I fix that for real-time? Thanks.

                  Comment


                    #10
                    Hello,


                    If you want to do something once per bar, you could create a variable to track bars.Count when it increases.


                    For example,


                    Code:
                    int myBarCount;
                    
                    
                    if (bars.Count == 0) // First bar
                    
                    {
                    
                    trueRange = high - low;
                    
                    Print("trueRange(1): "+ trueRange);
                    
                    }
                    
                    
                    if (bars.Count == 1) {
                    
                    myBarCount = 0;
                    
                    }
                    
                    
                    if (myBarCount < bars.Count)
                    
                    {
                    
                    myBarCount = bars.Count;
                    
                    //whatever logic you want to execute once per new bar
                    
                    }
                    Gaby V.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you for the tip. I am still having problem implementing that.
                      Code:
                              private int myBarCount = 0;
                              protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask)
                              {
                                  
                                  //if (trueRanges.Count < atrPeriod) return;
                                  
                                  // Compute the True Range for the current tick
                                  double trueRange;
                                  Print("----bars.Count: " + bars.Count);
                                  if (bars.Count == 0) // First bar
                                  {
                                      trueRange = high - low;
                                      Print("trueRange(1): "+ trueRange);
                                  }
                                  else
                                  {
                                      trueRange = Math.Max(high - bars.GetClose(bars.Count - 1), Math.Max(bars.GetClose(bars.Count - 1) - low, high - low));
                                      Print("trueRange(2): "+ trueRange);
                                      
                                      Print("high - bars.GetClose(bars.Count - 1): " + (high - bars.GetClose(bars.Count - 1)));
                      
                                      Print("bars.GetClose(bars.Count - 1) - low: " + (bars.GetClose(bars.Count - 1) - low));
                      
                                      Print("high - low: " + (high - low).ToString());
                                      
                                  }
                      
                                  // Add the true range to the list and maintain the list's length
                                  trueRanges.Add(trueRange);
                                  if (trueRanges.Count > atrPeriod)
                                  {
                                      trueRanges.RemoveAt(0); // Remove the oldest value
                                  }
                      
                                  // Compute the ATR
                                  atrValue = trueRanges.Average();
                                  Print("atrValue:" + atrValue);
                                  // Decide whether to add a new bar or update the current one
                                  
                       if (myBarCount < bars.Count)
                          {
                              myBarCount = bars.Count;
                      
                              // Your logic to execute once per new bar goes here
                              
                                          if ((high - low) >= atrValue * 1)
                                 {
                                  AddBar(bars, open, high, low, close, time, volume);
                                  }
                                  else
                                  {
                                      // If you don't add a new bar, you may want to update the current bar.
                                      UpdateBar(bars, high, low, close, time, volume);
                                  }
                              
                      
                          }​



                      The chart stops at 4:59 of the daybefore but it keeps printing values
                      .
                      .
                      .


                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11
                      high - bars.GetClose(bars.Count - 1): 11
                      bars.GetClose(bars.Count - 1) - low: -11
                      high - low: 0
                      atrValue:11.1875
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.1875
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.1875
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.1875
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844
                      trueRange(2): 11.25
                      high - bars.GetClose(bars.Count - 1): 11.25
                      bars.GetClose(bars.Count - 1) - low: -11.25
                      high - low: 0
                      atrValue:11.25
                      ----bars.Count: 1844​
                      .
                      .
                      .

                      and here is the chart

                      Click image for larger version

Name:	image.png
Views:	115
Size:	56.4 KB
ID:	1287045

                      Comment


                        #12
                        Hello,

                        Thank you for your response.

                        I suggest taking a look at the code for RangeBarsType in the NinjaScript Editor.

                        The sample code for OnDataPoint() in the Help Guide uses high != bars.GetHigh(bars.Count - 1) and low != bars.GetLow(bars.Count - 1) to supply the high and the low to UpdateBar().

                        However, taking a look at the code for RangeBarsType this uses bars.GetHigh(bars.Count - 1) and bars.GetLow(bars.Count - 1).




                        Additionally, when deciding whether or not to update your trueRanges array with a new bar, you'll want to do a check here for the bar.Count. If the count changes, this is when you'll want to add a new element to trueRanges and if not update the last element to new trueRange for the current bar.

                        Lastly, you may want to change your BuiltFrom property from Minute to Tick as the bar you are building is based on movement and not time.

                        Please let us know if we can assist further.
                        Gaby V.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks you very much for your suggestions. As you mentioned using Tick bar as the base makes more sense.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Haiasi, 04-25-2024, 06:53 PM
                          2 responses
                          16 views
                          0 likes
                          Last Post Massinisa  
                          Started by Creamers, Today, 05:32 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post Creamers  
                          Started by Segwin, 05-07-2018, 02:15 PM
                          12 responses
                          1,786 views
                          0 likes
                          Last Post Leafcutter  
                          Started by poplagelu, Today, 05:00 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post poplagelu  
                          Started by fx.practic, 10-15-2013, 12:53 AM
                          5 responses
                          5,407 views
                          0 likes
                          Last Post Bidder
                          by Bidder
                           
                          Working...
                          X