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

average 20 period volume

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

    average 20 period volume

    I'm trying to have a condition that the average 20 period volume > 500,000 but on index 1.

    I have tried the two below but get compile errors

    if (SMA(Volume(BarsArray[1], 20)[0]) > 500000)

    if (SMA(Volume, 20)[1][0] > 500000)

    #2
    Think I got it, in blue below. Was curious if you can check the overall code below to see if I am missing anything. It compiles ok but just wanted to double check. Unsure if I need it to check if there's enough bars available and where exactly to put? thanks

    Code:
       protected override void Initialize()
            {
                Add(PeriodType.Day, 1);
    			Add(PeriodType.Day, 5);
    			CalculateOnBarClose = false;
    			
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Condition set 1 Long Entry, current price > week high & current price < 5% from day low. 
    			// And time to start/stop entering positions.
                if ((BarsInProgress == 0) //OnBarUpdate called for 5min bars	
    			&& (Close[0] > Highs[2][0] && Close[0] < Lows[1][0] * 1.05)
    			&& (ToTime(Time[0]) >= timestart && ToTime(Time[0]) < timeend))	
    			
    			//Dayhigh - Daylow > ATR20*.75. AvDailyVol>500k, Stocks $10-90, and ATR>1.5 & ATR<3.	
    			[COLOR="blue"]{avgdailyvolume = SMA(Volumes[1],20)[0];}[/COLOR]
    			if ((BarsInProgress == 1) //OnBarUpdate called for daily bars
    			&& (Highs[1][0] - Lows[1][0] > ATR(BarsArray[1], 20)[0]*ATRrange)
    			[COLOR="Blue"]&& (avgdailyvolume > 500000)[/COLOR]
    			&& (Closes[1][1] >= 10 && Closes[1][1] <= 90)
    			&& (ATR(BarsArray[1], 20)[0] > 1.5 && ATR(BarsArray[1], 20)[0] < 3))	
    			
                {
                    EnterLong(200);
                }
    			
    			// Condition set 2 Fixed Stop, 
    			if ((BarsInProgress == 0) && (Position.MarketPosition == MarketPosition.Flat))
                {
    				SetStopLoss(CalculationMode.Price, ATR(BarsArray[1], 14)[0]*longstopATRperc);
    			}
    			// Condition set 3 Trail Trigger & Trail How
    			else if ((BarsInProgress == 0)
                &&	(Position.MarketPosition == MarketPosition.Long && ToTime(Time[0]) > 93500))  
    			{SetStopLoss(CalculationMode.Price, Swing(1).SwingLowBar(0, 1, 10));}
    
    			// Condition set 4 Long Exit,
    			if (ToTime(Time[0]) >= 155000)
    			{
                    ExitLong(200);
                }
            }
    Last edited by zachj; 05-05-2013, 07:23 PM.

    Comment


      #3
      zachj, you defintely want to include a check for enough bars for all your series referenced in the script, like shown here at the start of your OnBarUpdate() section - http://www.ninjatrader.com/support/h...ub=CurrentBars
      BertrandNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Segwin, 05-07-2018, 02:15 PM
      14 responses
      1,788 views
      0 likes
      Last Post aligator  
      Started by Jimmyk, 01-26-2018, 05:19 AM
      6 responses
      837 views
      0 likes
      Last Post emuns
      by emuns
       
      Started by jxs_xrj, 01-12-2020, 09:49 AM
      6 responses
      3,293 views
      1 like
      Last Post jgualdronc  
      Started by Touch-Ups, Today, 10:36 AM
      0 responses
      13 views
      0 likes
      Last Post Touch-Ups  
      Started by geddyisodin, 04-25-2024, 05:20 AM
      11 responses
      63 views
      0 likes
      Last Post halgo_boulder  
      Working...
      X