NexusFi: Find Your Edge


Home Menu

 





Logic question. Finding next greatest number. Help!


Discussion in NinjaTrader

Updated
    1. trending_up 1,827 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 7 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3

double BaseNumber = 27;

double Z1 = 25;
double Z2 = 12;
double Z3 = 8;
double Z4 = 26;
double Z5 = 35;
double Z6 = 40;

I have a collection of Z doubles, and want to find out what the next greater number to the BaseNumber is, how do I do this?
In this case the next number to 27 in Z collection would be 35.
How do I extract that number?

Thanks in advance.


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Topstep Acquires The Futures Desk -- Prop Firm Consolida …
Funded Trading Evaluation Firms
The 50/50 Paradox: Peace and Invasion Each at 20% -- Ira …
Prediction Markets & Event Contracts
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
Prediction Markets & Event Contracts
TradingView Opens Volume Footprint Data to Pine Script - …
TradingView
The Backwardation Signal: How the CL Futures Curve Tells …
Commodities
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860



kidvic View Post
double BaseNumber = 27;

double Z1 = 25;
double Z2 = 12;
double Z3 = 8;
double Z4 = 26;
double Z5 = 35;
double Z6 = 40;

I have a collection of Z doubles, and want to find out what the next greater number to the BaseNumber is, how do I do this?
In this case the next number to 27 in Z collection would be 35.
How do I extract that number?

Thanks in advance.

Something like this :

 
Code
using System.Collection.Generic,

double Z1 = 25;
double Z2 = 12;
double Z3 = 8;
double Z4 = 26;
double Z5 = 35;
double Z6 = 40


double BaseNumber = 27;

Print(Biggest(Z1,Z2,Z3,Z4,Z5,Z6, BaseNumber));



double Biggest (double Z1,double Z2, double Z3, double Z4, double Z5, double Z6, double myNumber)
{
	List <double> myList = new List <double>();
	myList.Add(Z1);
	myList.Add(Z2);
	myList.Add(Z3);
	myList.Add(Z4);
	myList.Add(Z5);
	myList.Add(Z6);

	myList.Sort();

	foreach (double myZ in myList)
	{
 		if (myZ > myNYmber)
			return myZ;
	}
	return (0.0);

}


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3


rleplae View Post
Something like this :

 
Code
using System.Collection.Generic,

double Z1 = 25;
double Z2 = 12;
double Z3 = 8;
double Z4 = 26;
double Z5 = 35;
double Z6 = 40


double BaseNumber = 27;

Print(Biggest(Z1,Z2,Z3,Z4,Z5,Z6, BaseNumber));



double Biggest (double Z1,double Z2, double Z3, double Z4, double Z5, double Z6, double myNumber)
{
	List <double> myList = new List <double>();
	myList.Add(Z1);
	myList.Add(Z2);
	myList.Add(Z3);
	myList.Add(Z4);
	myList.Add(Z5);
	myList.Add(Z6);

	myList.Sort();

	foreach (double myZ in myList)
	{
 		if (myZ > myNYmber)
			return myZ;
	}
	return (0.0);

}


still new to the game: Getting errors,
 
Code
#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.Gui.Chart;
using System.Collection.Generic;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    /// <summary>
    /// 
    /// </summary>
    [Description("")]
    public class TestZ : Indicator
    {
        #region Variables
        // Wizard generated variables
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
            Overlay				= true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
     double Z1 = 25;
double Z2 = 12;
double Z3 = 8;
double Z4 = 26;
double Z5 = 35;
double Z6 = 40;


double BaseNumber = 27;

Print(Biggest(Z1,Z2,Z3,Z4,Z5,Z6, BaseNumber));



double Biggest (double Z1,double Z2, double Z3, double Z4, double Z5, double Z6, double myNumber)
{
	List <double> myList = new List <double>();
	myList.Add(Z1);
	myList.Add(Z2);
	myList.Add(Z3);
	myList.Add(Z4);
	myList.Add(Z5);
	myList.Add(Z6);

	myList.Sort();

	foreach (double myZ in myList)
	{
 		if (myZ > myNYmber)
			return myZ;
	}
	return (0.0);

}
	
        }

        #region Properties

        #endregion
    }
}

#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    public partial class Indicator : IndicatorBase
    {
        private TestZ[] cacheTestZ = null;

        private static TestZ checkTestZ = new TestZ();

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public TestZ TestZ()
        {
            return TestZ(Input);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public TestZ TestZ(Data.IDataSeries input)
        {
            if (cacheTestZ != null)
                for (int idx = 0; idx < cacheTestZ.Length; idx++)
                    if (cacheTestZ[idx].EqualsInput(input))
                        return cacheTestZ[idx];

            lock (checkTestZ)
            {
                if (cacheTestZ != null)
                    for (int idx = 0; idx < cacheTestZ.Length; idx++)
                        if (cacheTestZ[idx].EqualsInput(input))
                            return cacheTestZ[idx];

                TestZ indicator = new TestZ();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                Indicators.Add(indicator);
                indicator.SetUp();

                TestZ[] tmp = new TestZ[cacheTestZ == null ? 1 : cacheTestZ.Length + 1];
                if (cacheTestZ != null)
                    cacheTestZ.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheTestZ = tmp;
                return indicator;
            }
        }
    }
}

// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
    public partial class Column : ColumnBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.TestZ TestZ()
        {
            return _indicator.TestZ(Input);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Indicator.TestZ TestZ(Data.IDataSeries input)
        {
            return _indicator.TestZ(input);
        }
    }
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    public partial class Strategy : StrategyBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.TestZ TestZ()
        {
            return _indicator.TestZ(Input);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Indicator.TestZ TestZ(Data.IDataSeries input)
        {
            if (InInitialize && input == null)
                throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

            return _indicator.TestZ(input);
        }
    }
}
#endregion

This is my code.


Reply With Quote
  #5 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860


kidvic View Post
still new to the game: Getting errors,
 
Code
#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.Gui.Chart;
using System.Collection.Generic;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    /// <summary>
    /// 
    /// </summary>
    [Description("")]
    public class TestZ : Indicator
    {
        #region Variables
        // Wizard generated variables
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
            Overlay				= true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
     double Z1 = 25;
double Z2 = 12;
double Z3 = 8;
double Z4 = 26;
double Z5 = 35;
double Z6 = 40;


double BaseNumber = 27;

Print(Biggest(Z1,Z2,Z3,Z4,Z5,Z6, BaseNumber));



double Biggest (double Z1,double Z2, double Z3, double Z4, double Z5, double Z6, double myNumber)
{
	List <double> myList = new List <double>();
	myList.Add(Z1);
	myList.Add(Z2);
	myList.Add(Z3);
	myList.Add(Z4);
	myList.Add(Z5);
	myList.Add(Z6);

	myList.Sort();

	foreach (double myZ in myList)
	{
 		if (myZ > myNYmber)
			return myZ;
	}
	return (0.0);

}
	
        }

        #region Properties

        #endregion
    }
}

#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    public partial class Indicator : IndicatorBase
    {
        private TestZ[] cacheTestZ = null;

        private static TestZ checkTestZ = new TestZ();

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public TestZ TestZ()
        {
            return TestZ(Input);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public TestZ TestZ(Data.IDataSeries input)
        {
            if (cacheTestZ != null)
                for (int idx = 0; idx < cacheTestZ.Length; idx++)
                    if (cacheTestZ[idx].EqualsInput(input))
                        return cacheTestZ[idx];

            lock (checkTestZ)
            {
                if (cacheTestZ != null)
                    for (int idx = 0; idx < cacheTestZ.Length; idx++)
                        if (cacheTestZ[idx].EqualsInput(input))
                            return cacheTestZ[idx];

                TestZ indicator = new TestZ();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                Indicators.Add(indicator);
                indicator.SetUp();

                TestZ[] tmp = new TestZ[cacheTestZ == null ? 1 : cacheTestZ.Length + 1];
                if (cacheTestZ != null)
                    cacheTestZ.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheTestZ = tmp;
                return indicator;
            }
        }
    }
}

// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
    public partial class Column : ColumnBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.TestZ TestZ()
        {
            return _indicator.TestZ(Input);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Indicator.TestZ TestZ(Data.IDataSeries input)
        {
            return _indicator.TestZ(input);
        }
    }
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    public partial class Strategy : StrategyBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.TestZ TestZ()
        {
            return _indicator.TestZ(Input);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Indicator.TestZ TestZ(Data.IDataSeries input)
        {
            if (InInitialize && input == null)
                throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

            return _indicator.TestZ(input);
        }
    }
}
#endregion

This is my code.

the function needs to be outside the other function
you will need to study a few hours on functions/ basics...
classes, members, methods


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3


rleplae View Post
the function needs to be outside the other function
you will need to study a few hours on functions/ basics...
classes, members, methods

This seems a lot more difficult than I imagined. Thank you for trying.


Reply With Quote
  #7 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860


kidvic View Post
This seems a lot more difficult than I imagined. Thank you for trying.

don't give up
all beginning is hard


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #8 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3


rleplae View Post
don't give up
all beginning is hard


I'm not. Thank you for the effort.


Reply With Quote




Last Updated on November 1, 2015


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts