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

Today's volume larger than highest down volume day in 10 days

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

    Today's volume larger than highest down volume day in 10 days

    In my strategy, i would like to include the following condition: Today's volume is larger than the highest down volume day over the prior 10 days. Up volume days should not be considered. In my code below i do the inverse way, so i'm searching for a potential higher down volume day than today's volume.

    bool isVolumeHigher = false;
    for (int i = 1; i < 10; i++)
    {
    if (Close[i] < Open[i] && Volume[0] < Volume[i])
    isVolumeHigher = false;
    else
    isVolumeHigher = true;

    if (isVolumeHigher == true)
    break;
    }

    Thanks...

    #2
    Hello Sweet&Sour,
    Thanks for your post.

    When you reference the volume on a down day- would you like to reference what the bid volume is or the total volume for that down day?
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      No Bid or Ask dependancy.

      Once the close of the price is less than the previous day, the vol of this day will be a "negative vol day".

      Comment


        #4
        Hello Sweet&Sour,

        You could do this without a loop by storing the volume values in a custom series and then comparing that to the previous 10 down values. Something similar to the following snippet would store a "0" in the custom series on all up volume days and then store the current volume on down volume days. This eliminates up volumes days and allows you to compare the 10 highest values over a period of 10.

        Code:
        private Series<double> MyDownVolSeries;
        protected override void OnStateChange()
        {
        	else if (State == State.DataLoaded)
        	{
        		MyDownVolSeries = new Series<double>(this);
        	}
        }
        protected override void OnBarUpdate()
        {
        	if (Close[0] > Open[0])
        		MyDownVolSeries[0] = 0;
        	
        	else if (Close[0] < Open[0])
        	{
        		MyDownVolSeries[0] = Volume[0];		
        		int highestBar = HighestBar(MyDownVolSeries,10);
        		double highestVolume = Volume[highestBar];
        		
        		if (Volume[0] >= highestVolume)
        		{
        			//today is the highest down volume day in the last 10 days
        		}
        	}
        }

        Help Guide-- Series<T>

        Help Guide-- HighestBar()

        Please let me know if you have any questions.
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          Hi Josh,

          Thanks for the snippet. Will have a look on it in the next few days.

          Krgds...

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bmartz, 03-12-2024, 06:12 AM
          4 responses
          31 views
          0 likes
          Last Post bmartz
          by bmartz
           
          Started by Aviram Y, Today, 05:29 AM
          4 responses
          11 views
          0 likes
          Last Post Aviram Y  
          Started by algospoke, 04-17-2024, 06:40 PM
          3 responses
          28 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by gentlebenthebear, Today, 01:30 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by cls71, Today, 04:45 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X