Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Storing Open Value

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

    Storing Open Value

    Hello NT,

    I want to set up a variable "openp" that stores each day the value of the open of the first 5 minute bar during regular market hours. How would I do this. I'm in central time, so this would be 8:30 am.

    Thanks,
    Ben

    #2
    Hello harr5754,

    Thanks for your post.

    Can you clarify if you are using the Strategy Builder or are you working directly in Ninjascript?

    If I understand correctly you are looking for the open price of the 5 minute bar that begins at 8:30 and ends at 8:35?

    Comment


      #3
      I'm using Ninjascript. If there is a way to do in Strategy Builder that would be good to know.

      Correct. I'm looking for the open price of the 5 minute bar that begins at 8:30 and ends at 8:35

      Comment


        #4
        Hello harr5754,

        Thanks for your reply.

        In the Strategy Builder, create a double type variable to store the open price. In a set create the condition Time>time series, Equals, Time>Time value and set for 8:35 am. in the do the following section of the set, add the condition to assign the variable (Misc) you created to Price>Open[0].

        In Ninjascript it will look like:

        if (Times[0][0].TimeOfDay == new TimeSpan(08, 35, 0))
        {
        MyOpenPrice = Open[0];
        // MyOpenPrice was created at the class level as a double type with private double MyOpenPrice;
        }

        Comment


          #5
          Thanks.

          If I want to see if it worked on ES, would I use the following?

          Console.Writeline ();

          I'm not sure how to call up ES in Ninjascipt. I always use the Strategy Analyzer/

          Thanks,
          Ben

          Comment


            #6
            Hello Ben,

            Thanks for your reply.

            I suggest you create it in the Strategy Builder and then click on the "View code" button to see what it would look like in Ninjascript.

            To create directly in Ninjascript you would need to use the Ninjascript Editor: https://ninjatrader.com/support/help...t8/?editor.htm

            Comment


              #7
              Thanks Paul,

              I used the Strategy Builder along with your lines to come up with the following code:

              Code:
               public class MyOpenPrice : Strategy
              {
              private double OpenPrice;
              
              
              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"Enter the description for your new custom Strategy here.";
              Name = "MyOpenPrice";
              Calculate = Calculate.OnBarClose;
              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;
              OpenPrice = 4000;
              }
              else if (State == State.Configure)
              {
              }
              }
              
              protected override void OnBarUpdate()
              {
              if (BarsInProgress != 0)
              return;
              
              if (CurrentBars[0] < 0)
              return;
              
              // Set 1
              if (Times[0][0].TimeOfDay == new TimeSpan(08,35,0))
              {
              OpenPrice = Open[0];
              
              Console.Write();
              I'm wondering instead of the Console.Write line I added at the end, if there is a command that would make OpenPrice show up in the Control Center Log. I want to confirm what's being stored to OpenPrice before adding any more conditions.

              Regards,
              Ben

              Comment


                #8
                Hey Paul,

                Please disregard my last post. I was able to confirm OpenPrice was storing the correct price buy adding a limit order and reviewing the trades.

                Thanks,
                Ben

                Comment


                  #9
                  Hello Ben,

                  Thanks for your reply.

                  Glad you were able to figure out a solution.

                  If you are wanting to print something out, you can use Print("your text here"); and the information will be visible on the New>Ninjascript output window.

                  Here is a link to the Print statement: https://ninjatrader.com/support/help...nt8/?print.htm


                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Yesterday, 05:17 AM
                  0 responses
                  54 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  130 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  72 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  44 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  49 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X