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

Exiting on different time series

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

    Exiting on different time series

    How do I make this exit on the 3rd bar series. It continually just exits on the first. I've tried with BIP=2 with no luck.



    //ENTRY CONDITIONS

    if (
    ToTime(Time[0]) >= ToTime(2,59,00)
    && ToTime(Time[0]) <= ToTime(6,59,00)
    && Closes[1][0] > Opens[1][0]
    && Closes[1][0] - Opens[1][0] >= 0.30
    && (BarsSinceExit(2,"",0) == -1 || BarsSinceExit(2,"",0) > 240)
    && !(Time[0].DayOfWeek == DayOfWeek.Wednesday)
    && (VOL[0] > 100)
    )

    {
    EnterLong(2,1,"Locked");
    EnterLong(2,1,"Open");
    }


    // EXIT CONDITIONS

    if (BarsInProgress == 2) {
    if (
    ToTime(Time[0]) >= 123000
    )
    {
    ExitLong(2,1,"LockedExit","Locked");
    ExitLong(2,1,"OpenExit","Open");
    }
    }
    Last edited by albazzaztariq; 01-26-2014, 09:11 PM.

    #2
    Hello albazzaztariq,

    Thank you for your post.

    In a multi-instrument script the BarsInProgress index of the Exit() method would determine the instrument the exit is submitted to. However, in a multi-time frame script the Exit() order is still going to execute on the same instrument. Unfortunately, there is no method to force the fill at a specific bar close.

    Comment


      #3
      are you telling me there's no way to make it exit on the 3rd bar series?

      Comment


        #4
        Hello albazzaztariq,

        Thank you for your response.

        The third bar series is the same instrument as the second and primary, correct? Then it will exit on the same instrument.

        Comment


          #5
          I'm not asking about instrument. I'm asking about it exiting on the same series. The 3rd series is 1 min. It keeps exiting on the primary series

          Comment


            #6
            Hello albazzaztariq,

            Thank you for your response.

            Yes, I am aware it is the same instrument. So I may detail this item further please advise what the primary series is.

            Comment


              #7
              20 minutes

              Comment


                #8
                Hello albazzaztariq,

                Thank you for your response.

                Please attach your strategy to your response. You will find the strategy located in the following directory on your PC: (My) Documents\NinjaTrader 7\bin\Custom\Strategy

                Comment


                  #9
                  #region Using declarations
                  using System;
                  using System.ComponentModel;
                  using System.Diagnostics;
                  using System.Drawing;
                  using System.Drawing.Drawing2D;
                  using System.Xml.Serialization;
                  using NinjaTrader.Cbi;
                  using NinjaTrader.Data;
                  using NinjaTrader.Indicator;
                  using NinjaTrader.Gui.Chart;
                  using NinjaTrader.Strategy;
                  #endregion

                  // This namespace holds all strategies and is required. Do not change it.
                  namespace NinjaTrader.Strategy
                  {
                  /// <summary>
                  /// Enter the description of your strategy here
                  /// </summary>
                  [Description("Enter the description of your strategy here")]
                  public class AlanRallyV5 : Strategy
                  {

                  protected override void Initialize()
                  {
                  Add(Bollinger(Close, 2, 20));
                  Add(PeriodType.Minute,60);
                  Add(PeriodType.Minute,1);
                  CalculateOnBarClose = true;
                  SetProfitTarget("Locked", CalculationMode.Ticks, 30);
                  SetProfitTarget("Open", CalculationMode.Ticks, 15);
                  SetStopLoss("",CalculationMode.Ticks,40,false);
                  }


                  protected override void OnBarUpdate()
                  {


                  // BEGINNING OF EXECUTION

                  //ENTRY CONDITIONS BEGINNING


                  if (
                  ToTime(Time[0]) >= ToTime(2,59,00)
                  && ToTime(Time[0]) <= ToTime(6,59,00)
                  && Closes[1][0] > Opens[1][0]
                  && Closes[1][0] - Opens[1][0] >= 0.30
                  && (BarsSinceExit(2,"",0) == -1 || BarsSinceExit(2,"",0) > 240)
                  )

                  {
                  EnterLong(2,1,"Locked");
                  EnterLong(2,1,"Open");
                  }


                  // EXIT CONDITIONS
                  if (BarsInProgress==2) {
                  if (
                  ToTime(Time[0]) >= 123000
                  )
                  {
                  ExitLong(2,1,"LockedExit","Locked");
                  ExitLong(2,1,"OpenExit","Open");
                  }
                  }


                  }


                  }

                  }

                  Comment


                    #10
                    Hlelo albazzaztariq,

                    Thank you for your response.

                    I see the StopLoss is exiting the positions on my end, unfortunately we cannot dictate the bar series the Set() methods are submitted to. Are you seeing your Exit() methods exiting the position on your end? If so, what instrument and from and to date are you testing?

                    Comment


                      #11
                      CL continuation, just do from 2013-2014. Take the stop out if you want or play around with it. You'll see it doesn't exit on the 1 min series.

                      Comment


                        #12
                        Hello albazzaztariq,

                        Thank you for your response.

                        I am seeing the exits on the 1 minute bar. The majority of the exits in the attached screenshot are at 12:31 PM, 1 minute after the desired time for close not 20 minutes.
                        Attached Files

                        Comment


                          #13
                          I think the issue I was having was with it not exiting at any point because I forgot it is only evaluating 20 min bars. Thank you

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by jeronymite, 04-12-2024, 04:26 PM
                          3 responses
                          43 views
                          0 likes
                          Last Post jeronymite  
                          Started by frankthearm, Today, 09:08 AM
                          4 responses
                          9 views
                          0 likes
                          Last Post frankthearm  
                          Started by yertle, Today, 08:38 AM
                          5 responses
                          15 views
                          0 likes
                          Last Post NinjaTrader_BrandonH  
                          Started by adeelshahzad, Today, 03:54 AM
                          3 responses
                          16 views
                          0 likes
                          Last Post NinjaTrader_BrandonH  
                          Started by bill2023, Yesterday, 08:51 AM
                          6 responses
                          27 views
                          0 likes
                          Last Post NinjaTrader_Erick  
                          Working...
                          X