NexusFi: Find Your Edge


Home Menu

 





Find the highest and lowest value of the series (MC.NET)


Discussion in MultiCharts

Updated
    1. trending_up 5,759 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 Jeffrey 
Hong Kong
 
Experience: Beginner
Platform: MultiCharts, NinjaTrader
Trading: HSIF, ES
Posts: 10 since Jul 2010
Thanks Given: 2
Thanks Received: 1

I am trying to implement a Donchian channel indicator which needs to find the highest and lowest value of the past <period> bar. Say period is 20 then I need to find the highest high and lowest lowe value of the previous 20 bars every time I call the CalcBar() method.

Is there any simple way to do this? Instead of looping previous n bar every time?


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Post-Summit Market Verdict: ES -1%, NQ -1.5%, 10-Year Yi …
Traders Hideout
Without Pulisic, USA 61.5% Live vs. Australia -- France …
Prediction Markets & Event Contracts
The June 15 Resolution Trap: Irans Agreed Text Still Pri …
Prediction Markets & Event Contracts
Thanks Mike. Godspeed.
The Elite Circle
Iran Airspace Contract Surges to 33.5% as Project Freedo …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
16 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
2 thanks
30 Sessions
1 thanks
CME Expands 24/7 Trading to WTI Crude Oil and Gold -- We …
1 thanks
  #2 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,099 since Jun 2009
Thanks Given: 877
Thanks Received: 8,098


Jeffrey View Post
I am trying to implement a Donchian channel indicator which needs to find the highest and lowest value of the past <period> bar. Say period is 20 then I need to find the highest high and lowest lowe value of the previous 20 bars every time I call the CalcBar() method.

Is there any simple way to do this? Instead of looping previous n bar every time?

sure, cut & paste these codes;

#region Variables
....
// User defined variables (add any user defined variables below)
......
private double curlow,curhigh,lasthigh,lastlow,targethigh,targetlow, savelow =0,savehigh=0;
......

.............
protected override void OnBarUpdate()
{
if (CurrentBar <Period) ///// Do not calculate if we don't have enough bars
return;
......

curlowpos=LowestBar(Low,Period);
curlow=Low[curlowpos];

curhighpos=HighestBar(High, Period);
curhigh=High[curhighpos];
-------


Reply With Quote
  #3 (permalink)
 Jeffrey 
Hong Kong
 
Experience: Beginner
Platform: MultiCharts, NinjaTrader
Trading: HSIF, ES
Posts: 10 since Jul 2010
Thanks Given: 2
Thanks Received: 1



cory View Post
sure, cut & paste these codes;

#region Variables
....
// User defined variables (add any user defined variables below)
......
private double curlow,curhigh,lasthigh,lastlow,targethigh,targetlow, savelow =0,savehigh=0;
......

.............
protected override void OnBarUpdate()
{
if (CurrentBar <Period) ///// Do not calculate if we don't have enough bars
return;
......

curlowpos=LowestBar(Low,Period);
curlow=Low[curlowpos];

curhighpos=HighestBar(High, Period);
curhigh=High[curhighpos];
-------

Hi Cory,

Thanks for the suggestion. However I am using MC.NET instead of NT7. I am actually trying to move the Donchian indicator from NT7 to MC.NET ... However I can't find the functions like MAX in MC.NET so I am wondering do I have to build one on my own.....


Started this thread Reply With Quote
  #4 (permalink)
 
Jasonnator's Avatar
 Jasonnator 
Denver, Colorado United States
 
Experience: Intermediate
Platform: NT8 + Custom
Broker: NT Brokerage, Kinetick, IQFeed, Interactive Brokers
Trading: ES
Posts: 158 since Dec 2014
Thanks Given: 40
Thanks Received: 167


Jeffrey View Post
Hi Cory,

Thanks for the suggestion. However I am using MC.NET instead of NT7. I am actually trying to move the Donchian indicator from NT7 to MC.NET ... However I can't find the functions like MAX in MC.NET so I am wondering do I have to build one on my own.....

You could you the standard .NET Math.Max(a, b) which is simple and great for code maintenance down the road. Performance wise, it's nearly identical to inlining, stackoverflow thread on that. DotNetPearls has a quick 30 second read on it that's pretty good too.


Reply With Quote
  #5 (permalink)
 Jeffrey 
Hong Kong
 
Experience: Beginner
Platform: MultiCharts, NinjaTrader
Trading: HSIF, ES
Posts: 10 since Jul 2010
Thanks Given: 2
Thanks Received: 1

I have found the answer, there are some PublicFunctions available in MC.NET:

 
Code
		public Jeffrey_DonchianChannel(object _ctx):base(_ctx){
		
			// default 14 days
			Period = 14;			
		}		
		
		protected override void Create() {
			// create variable objects, function objects, plot objects etc.
			
			
			//plot1 = AddPlot(new PlotAttributes("ATR", EPlotShapes.Line, Color.Cyan, Color.Empty, 0, 0, true));
			
			upperBoundPlot = AddPlot(new PlotAttributes("UpperBound", EPlotShapes.Line, Color.Yellow, Color.Empty, 0, 0, true));
			lowerBoundPlot = AddPlot(new PlotAttributes("LowerBound", EPlotShapes.Line, Color.Yellow, Color.Empty, 0, 0, true));
			meanPlot = AddPlot(new PlotAttributes("Mean", EPlotShapes.Line, Color.Yellow, Color.Empty, 0, 0, true));
			
			upperBoundSeries = new VariableSeries<Double>(this);
			lowerBoundSeries = new VariableSeries<Double>(this);
			meanSeries = new VariableSeries<Double>(this);
		}
		
		protected override void StartCalc() {
			// assign inputs 
			
			//ExecInfo.MaxBarsBack = Period+1;
				
			#if DEBUG							
				Output.WriteLine("{0} - BarNumber: {1} - MaxBarsBack: {2}",
	            Bars.Time[0].ToString("yyyy/MM/dd HH:mm:ss"),
	            Bars.CurrentBarAbsolute() + 1,
	            ExecInfo.MaxBarsBack);
			#endif							
		}			
			
		
		protected override void CalcBar() {
		
			
			double upper = PublicFunctions.Highest(Bars.High, Period);
			double lower = PublicFunctions.Lowest(Bars.Low, Period);
			
			#if DEBUG			
				Output.WriteLine("Current bar is {0}", Bars.CurrentBar);
				Output.WriteLine("Date/Time: {0}, Upper: {1}, Lower: {2}", Bars.Time[0].ToString("yyyy/MM/dd HH:mm:ss"), upper, lower);
				Output.WriteLine("");
			#endif	
			
			// 0 means no displacement of the current bar
			upperBoundPlot.Set(0, upper);	
			lowerBoundPlot.Set(0, lower);	
			//meanPlot.Set(0, meanSeries.Value);	

		}
	}


Started this thread Reply With Quote




Last Updated on April 23, 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