Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

range problem

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

    range problem

    I creaated the following using the strat builder in an attempt to get the current day's range as of 10am. Instead of printing the current day's range as of 10am, it prints the full previous day's range. Please tell me what to do differently.



    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Day, 1);
    }
    else if (State == State.DataLoaded)
    {
    Range1 = Range(Closes[1]);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 0
    || CurrentBars[1] < 1)
    return;

    // Set 1
    if (Times[0][0].TimeOfDay == new TimeSpan(10, 0, 0))
    {
    Print(Convert.ToString(Range1[0]));
    }​

    #2
    Hello trader3000a,

    Thanks for your post.

    I see in the code you shared that you are checking if the Time of the primary data series is 10:00AM (Times[0][0].TimeOfDay).

    Instead, you would need to check the Time of the added data series to get the range value when the added data series time is 10:00AM. In the Strategy Builder, you would need to set the condition to use the Time Series of the added daily series. See the attached screenshot.

    The code would look something like this:
    if (Times[1][0].TimeOfDay == new TimeSpan(10, 0, 0))
    {
    //your code here
    }​

    Please let me know if I may assist further.
    Attached Files
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hi Brandon,
      I changed the series as above. Unfortunately now I receive no Prints. Here is the modified code:

      }
      else if (State == State.Configure)
      {
      AddDataSeries(Data.BarsPeriodType.Day, 1);
      }
      else if (State == State.DataLoaded)
      {
      Range1 = Range(Closes[1]);
      }
      }

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 0
      || CurrentBars[1] < 1)
      return;

      // Set 1
      if (Times[1][0].TimeOfDay == new TimeSpan(10, 0, 0))
      {
      Print(Convert.ToString(Range1[0]));
      }​

      ____________________________________________
      Here is the full page, in case:

      region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.Indicators;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion

      //This namespace holds Strategies in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public class MorningPullbackRetracement : Strategy
      {
      private double PreOrderHigh;
      private double PreOrderLow;
      private double HighAtOrder;
      private double LowAtOrder;


      private Range Range1;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"If market is up or down x+ % between 9:30 and 10am, look for a mean reversion, then take a position in the direction of the earlier trend.";
      Name = "MorningPullbackRetracement";
      Calculate = Calculate.OnPriceChange;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      OrderFillResolution = OrderFillResolution.Standard;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Gtc;
      TraceOrders = false;
      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;
      BarsRequiredToTrade = 20;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      PercentChangeAsDecimal = 1.01;
      RetraceOfRangeDecimal = 0.618;
      WindowStart = DateTime.Parse("09:30", System.Globalization.CultureInfo.InvariantCulture) ;
      WindowEnd = DateTime.Parse("11:30", System.Globalization.CultureInfo.InvariantCulture) ;
      PreOrderHigh = 0;
      PreOrderLow = 0;
      HighAtOrder = 0;
      LowAtOrder = 0;
      }
      else if (State == State.Configure)
      {
      AddDataSeries(Data.BarsPeriodType.Day, 1);
      }
      else if (State == State.DataLoaded)
      {
      Range1 = Range(Closes[1]);
      }
      }

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 0
      || CurrentBars[1] < 1)
      return;

      // Set 1
      if (Times[1][0].TimeOfDay == new TimeSpan(10, 0, 0))
      {
      Print(Convert.ToString(Range1[0]));
      }

      }

      Comment


        #4
        Hello trader3000a,

        Thanks for your note.

        After further investigation, I see that the added Daily data series will only have 1 timestamp at the end of the day.

        This means that a specific time cannot be checked for the added Daily series.

        You could consider adding a Minute data series to the script, such as a 10-Minute added series, creating a condition checking if the Time of the added series is 10:00AM, and printing out the Range() value of that added series in that condition.

        See the attached example script demonstrating this.

        Let me know if I may assist further.
        Attached Files
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Hi Brandon. Nothing seems to get me what i need so far. Perhaps I can explain more clearly. I want to know the range of the session as of a certain time. For instance, the range of the ES ETH session (from 6pm last night) today as of 10am was 49.5 points. There must be a simple way to achieve this programmatically, yes?

          Comment


            #6
            Hello trader3000a,

            Thanks for your note.

            This would not be possible to accomplish using the Strategy Builder with the Range indicator.

            To accomplish this, you would need to make a custom Series and assign the High price minus the Low price to that custom Series to calculate the range.

            Note that you would also have to persist the Series value because you are setting it once when a Time condition becomes true. This means that you would always need to set the current bar's value to the previous bar's value to keep it persisting.

            For example, in Set 1 you could set the current bar series to the previous bar series value (myCustomSeries[0] = myCustomSeries[1]). In Set 2 you could set up the Time condition and then set High - Low for the data series you want the range of. Daily will be yesterday's value unless you are using realtime data and Calculate.OnEachTick. In other sets, you could check the custom Series value and either its persisted value which was previously set by the Time condition or the Time condition resets it to the current range at that time.

            Note that this would be much more complicated with a more granular series as you would need to worry about finding the Highest High and Lowest Low when you do the Time condition since you would be dealing with many more than 1 bar between the session start and whatever time you wanted the range from.

            Please let me know if I may assist further.

            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            71 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            143 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            76 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            47 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            51 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X