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 PaulMohn, Today, 05:00 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post PaulMohn  
                  Started by ZenCortexAuCost, Today, 04:24 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post ZenCortexAuCost  
                  Started by ZenCortexAuCost, Today, 04:22 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post ZenCortexAuCost  
                  Started by SantoshXX, Today, 03:09 AM
                  0 responses
                  16 views
                  0 likes
                  Last Post SantoshXX  
                  Started by DanielTynera, Today, 01:14 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post DanielTynera  
                  Working...
                  X