Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

want to have trades execute on day earlier

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

    want to have trades execute on day earlier

    if(Open[0]>Open[1])
    {
    EnterLong(
    1);
    }
    if(Open[0]<Open[1])
    {
    EnterShort(
    1);
    }
    the code above results in the trades shown in the attachment.
    is there a way to make the trade executions occur a day earlier? [ie] if open today is greater than open yesterday, enter long today?
    Attached Files

    #2
    Hello joemiller,

    Yes, it would be possible to do that but you would have to add a smaller time frame than 1 day to your Strategy, and change your conditions slightly in order to do this because you are checking the value of the Historical Daily bar which NinjaTrader will not know the value of the data. To add a multi-time series script in your strategy you may view our example by going to Tools -> Edit NinjaScript -> Strategy -> SampleMultiTimeFrame strategy.

    Let me know if you have any questions.
    JCNinjaTrader Customer Service

    Comment


      #3
      as shown below, in SampleMultiTimeFrame strategy 5 and 15 minute bars are employed.
      should I use a combination of day bars and minute bars for the purpose described in my original post?

      // Add a 5 minute Bars object to the strategy
      Add(PeriodType.Minute, 5);

      // Add a 15 minute Bars object to the strategy
      Add(PeriodType.Minute, 15);

      Comment


        #4
        Hello joemiller,

        Yes, you can use a Minute bar. Basically, you would just need any time frame that is less than one day to be able to have the trade placed on the same day.

        Let us know if you have any questions.
        JCNinjaTrader Customer Service

        Comment


          #5
          I have established day and hour time frames
          Add(PeriodType.Day, 1);
          Add(PeriodType.Minute, 60)


          now that I have 2 time frames, what should be the syntax for
          if
          (Open[0]>Open[1])?

          [eg] I imagine it will be something like (which it isn't)
          if(BarsArray[1].Open[0]>BarsArray[1].Open[1])


          Comment


            #6
            joemiller, you can just use Opens here which would allow for access of the open price of each bars index as desired - http://www.ninjatrader.com/support/h.../nt7/opens.htm
            BertrandNinjaTrader Customer Service

            Comment


              #7
              the test code below still results in position entry a day later than desired. i think I have properly followed directions given to me in previous posts to this thread but position entry still occurs one day late [ie] if open today is greater than open yesterday, entry long occurs tomorrow, not today?

              attached is an image of the chart output from this code, showing that
              position entry occurs one day later than desired. I added a multitimeframe structure [ie] a day period and an hourly period. please advise me what else I must do to make position entry occur on the same day as when the signal occurs.

              protected override void Initialize()
              {
              Add(PeriodType.Day, 1);//jcm this is BarsArray[1]
              Add(PeriodType.Minute, 60);//jcm this is BarsArray[2]
              // Note: Bars are added to the BarsArray and can be accessed via an index value
              // E.G. BarsArray[1] ---> Accesses the 1st Bars object added above
              CalculateOnBarClose = false;
              }
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              if(Opens[1][0]>Opens[1][1])
              {
              EnterLong(1);
              }
              if(Opens[1][0]<Opens[1][1])
              {
              EnterShort(1);
              }
              }
              Attached Files

              Comment


                #8
                joemiller, that would unfortunately not work since your first barsarray is the daily one - this will only update once the open tick of the new day is seen in backtesting > hence the condition trigger to enter is at this point. You would need to reformulate your condition using the intraday data available and added into the strategy and then also submit the order to the finer series to test this. For example consider this snippet, provided our first added series holds intraday data (i.e. 5 min).

                if (Bars.SessionBreak && (CurrentDayOHL(BarsArray[1]).CurrentOpen[0] > PriorDayOHLC(BarsArray[1]).PriorOpen[0]))
                EnterLong(1, DefaultQuantity, "LongMin");
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Thank you

                  thanks loads for the explanation of why, PLUS the detailed solution...it would have taken me forever to go from the why to the how.... very much appreciated.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by helpwanted, Today, 03:06 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post helpwanted  
                  Started by Brevo, Today, 01:45 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post Brevo
                  by Brevo
                   
                  Started by aussugardefender, Today, 01:07 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post aussugardefender  
                  Started by pvincent, 06-23-2022, 12:53 PM
                  14 responses
                  242 views
                  0 likes
                  Last Post Nyman
                  by Nyman
                   
                  Started by TraderG23, 12-08-2023, 07:56 AM
                  9 responses
                  384 views
                  1 like
                  Last Post Gavini
                  by Gavini
                   
                  Working...
                  X