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

Low price in time range

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

    Low price in time range

    How would I go about getting the lowest price between say 830-930am?

    #2
    Zachj,

    There's a couple different ways.

    You can run a check filter for when its 9:30 and use MIN over the last hour depending on your chart interval

    Say I was running a 5 min chart
    Code:
    if(ToTime(Time[0]) == 093000)
    {
         double minLookback = MIN(Low, 20);
    }
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      I figured I could assign it to the 4th index by the following but it's not working. Can I not assign MIN to an index?

      double minLookback = MIN(BarsArray[4], Low, 1)[0];

      Comment


        #4
        Use Lows[4] instead.

        MIN doesn't have 3 overloads available.

        MIN(Lows[4], 1)[0]
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Gotcha. If I'm looking at futures and have my entries starting at 930am but I have a condition looking at the low of the bar from 830-930am it's not gonna give me any trades is it? Because it's previous to my entry cutoff and doesn't meet min bars required. Or if not there must be another reason I'm getting 0 trades.

          Comment


            #6
            What's the whole script?

            Do you have a CurrentBar check in place?

            What chart interval are you using and instrument?
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              It's ES. Primary is 1min and I have all the added series below. Bar checks are below. I changed minLookback to sigBarlow. And I took out MIN and just made it double sigBarlow = Lows[4][0]; seeing I'm only looking at 1 bar. I was getting a lot of trades previous but with adding

              if(ToTime(Time[0]) == 93100)
              {
              double sigBarlow = Lows[4][0];
              }

              I'm not getting any trades....


              Code:
              public class FuturesNew1130 : Strategy
                  {
                      #region Variables
                      private double sigBarlow = 0;
              		
                      #endregion
              
              
               protected override void Initialize()
                      {  
              
              //Primary 40min
              
              //1min
              Add("ES ##-##",PeriodType.Minute, 5); //Index 1
              //10min
              Add("ES ##-##",PeriodType.Minute, 10); //Index 2
              //30min
              Add("ES ##-##",PeriodType.Minute, 20); //Index 3
              //Hour
              Add("ES ##-##",PeriodType.Minute, 60); //Index 4
              //Day
              Add("ES ##-##",PeriodType.Minute, 150); //Index 5
              
               CalculateOnBarClose = true;
              			EntriesPerDirection = 1;
              			
              						
              			SetStopLoss("EnterShort", CalculationMode.Ticks, 85, true);
              			SetProfitTarget("EnterShort",CalculationMode.Ticks, 80);
              			
                      }
              
              
               protected override void OnBarUpdate()
              		{
              
              //Entry Conditions
              	if(ToTime(Time[0]) == 93100)
              {
                   double sigBarlow = Lows[4][0];
              }
              
              			if ((BarsInProgress == 3)
              			&& (BarsSinceEntry(0,"",0) > 40 || BarsSinceExit(0,"",0)==-1)
              			&& (CurrentBars[0] >= 2)  //1min 
              			&& (CurrentBars[2] >= 2) //10min
              			&& (CurrentBars[3] >= 1) //20min
              			&& (CurrentBars[4] >= 2) //600min
              			&& Volume[0] > 80000 
              			&& Volume[0] > Volume[1])
              			{
              																						
              				if(ToTime(Time[0]) >= 93000  
              				&& ToTime(Time[0]) <= 110000  					
              				&& Opens[0][0] - Closes[0][0] <= 3.25
              				&& Close[0] < Open[0] - 1.25
              				&& Falling(SMA(BarsArray[0], 190))
              				&& Closes[0][0] < SMA(BarsArray[0], 190)[0]
              				&& Closes[0][0] < SMA(BarsArray[0], 65)[0]
              				&& Closes[0][0] < sigBarlow
              				&& ATR(BarsArray[4], 14)[0] > 4
              				&& Close[0] < PriorDayOHLC().PriorHigh[0])
              					
              				{  
              					
              					EnterShort(0, 1, "EnterShort");
              					Print(sigBarlow + "sigBarlow");
              				}				
              						
              			}
              
              
              //ShortExit
              				if((BarsInProgress == 2) && Position.MarketPosition == MarketPosition.Short 
              				&& Closes[0][0] < Position.AvgPrice - (TickSize*15) && Close[0] > Open[0] + 2.5)
              				{
                              ExitShort(0, 1, "UpCandle", "EnterShort");
              				}
              				
              				if (Position.MarketPosition == MarketPosition.Short && ToTime(Time[0]) >= 113000)
              				{
                              ExitShort(0, 1, "ExitTime", "EnterShort");
              				}
              				
              				if ((BarsInProgress == 1) && Position.MarketPosition == MarketPosition.Short 
              				&& CrossAbove(SMA(13), SMA(38), 1))//13&38
              				{
                              ExitShort(0, 1, "SMAExit", "EnterShort");
              				}
              				
              				if((BarsInProgress == 0) && Position.MarketPosition == MarketPosition.Short 
              				&& BarsSinceEntry(0, "", 0) <= 20 && Closes[0][0] < Position.AvgPrice - (TickSize*26))//
              				{
                              ExitShort(0, 1, "TimeCutS", "EnterShort");
              				}
              }

              Comment


                #8
                Are you not getting any entries and/or exits?

                Does that first IF statement ever become true?
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  I get 300+ trades if I comment out..

                  if(ToTime(Time[0]) == 93100)
                  {
                  double sigBarlow = Lows[4][0];
                  }

                  Basically this is saying that sigBarlow is the low price of the bar from 830 to 930 correct? My Index 4 is a 60min bar.

                  Comment


                    #10
                    I don't know I think that statement is doing something strange like only allowing trades at 930 exactly. I'm just going to use this statement below, although long, I'm comfortable it's doing what I intend. My entry time is between 930 and 11, so depending on what time it is I'm checking for the current price to be below the low of 830-930 bar. My index 4 is a 60min bar and index 3 is a 30min bar...

                    If (ToTime(Time[0]) > 93000 && ToTime(Time[0]) <= 100000 && Closes[0][0] < Lows[4][0]
                    || ToTime(Time[0]) > 100000 && ToTime(Time[0]) <= 103000 && Closes[0][0] < Lows[3][1]
                    && Closes[0][0] < Lows[3][2]
                    || ToTime(Time[0]) > 103000 && ToTime(Time[0]) <= 110000 && Closes[0][0] < Lows[4][1]))

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by KennyK, 05-29-2017, 02:02 AM
                    3 responses
                    1,282 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by AttiM, 02-14-2024, 05:20 PM
                    11 responses
                    184 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by fernandobr, Today, 09:11 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Started by timmbbo, Today, 08:59 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by itrader46, Today, 09:04 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Working...
                    X