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

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?
    Paul H.NinjaTrader Customer Service

    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;
        }
        Paul H.NinjaTrader Customer Service

        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

            Paul H.NinjaTrader Customer Service

            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


                  Paul H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by AttiM, 02-14-2024, 05:20 PM
                  12 responses
                  213 views
                  0 likes
                  Last Post DrakeiJosh  
                  Started by cre8able, 02-11-2023, 05:43 PM
                  3 responses
                  237 views
                  0 likes
                  Last Post rhubear
                  by rhubear
                   
                  Started by frslvr, 04-11-2024, 07:26 AM
                  8 responses
                  117 views
                  1 like
                  Last Post NinjaTrader_BrandonH  
                  Started by stafe, 04-15-2024, 08:34 PM
                  10 responses
                  47 views
                  0 likes
                  Last Post stafe
                  by stafe
                   
                  Started by rocketman7, Today, 09:41 AM
                  3 responses
                  12 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X