Showing "tried to reference back more bars" in backtest - MultiCharts | futures io social day trading
futures io futures trading


Showing "tried to reference back more bars" in backtest
Updated: Views / Replies:943 / 2
Created: by Jeffrey Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors – all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you don’t need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Showing "tried to reference back more bars" in backtest

  #1 (permalink)
Elite Member
Hong Kong
 
Futures Experience: Beginner
Platform: MultiCharts, NinjaTrader
Favorite Futures: HSIF, ES
 
Posts: 10 since Jul 2010
Thanks: 2 given, 1 received

Showing "tried to reference back more bars" in backtest

I have developed a custom ATR as below. I have no problem using it on my charts.

 
Code
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator{
	
	[UpdateOnEveryTick(false)]
	public class Jeffrey_ATR : IndicatorObject {
	
		/*
		This is the first proven working version that work as a reference and shouldn't be changed.				
		*/		
		
		private int _Period;

		[Input]	
        public int Period
        {
            get { return this._Period; }
            set { 
				
				if (value<1) {
					this._Period = 1;
				} else {
					this._Period = value; 
				}			
			}
        }						
			
		private IPlotObject plot1;
		
		private VariableSeries<Double> atrSeries;

			
		public Jeffrey_ATR(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));
			atrSeries = new VariableSeries<Double>(this);
			
		}
		
		protected override void StartCalc() {
			// assign inputs 
						
			ExecInfo.MaxBarsBack = 1;
				
			#if DEBUG				
				Output.Clear();
				Output.WriteLine("{0} StartCalc()", this.GetType().ToString());			
				Output.WriteLine("[{0}] CurrentBar={1} CurrentBarAbsolute+1={2} MaxBarsBack={3} Period={4} Close[0]={5}",
				Bars.Time[0].ToString("yyyy/MM/dd HH:mm:ss"),			
	            Bars.CurrentBar,
				Bars.CurrentBarAbsolute()+1,
	            ExecInfo.MaxBarsBack,
				Period,
				Bars.Close[0]);
			#endif				
			
			#if DEBUG						
				Output.WriteLine("StartCalc()");			
				Output.WriteLine("");
			#endif								
		}
		protected override void CalcBar(){

			#if DEBUG			
				Output.WriteLine("CalcBar()");
				Output.WriteLine("[{0}] CurrentBar={1} CurrentBarAbsolute+1={2}",
				Bars.Time[0].ToString("yyyy/MM/dd HH:mm:ss"),
				Bars.CurrentBar, 				
				Bars.CurrentBarAbsolute()+1);			
			#endif							
			
			// logic from NT7
			/*
			if (CurrentBar == 0)
				Value.Set(High[0] - Low[0]);
			else
			{
				double trueRange = High[0] - Low[0];
				trueRange = Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1])));
				Value.Set(((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period));
			}
			*/			
			
			double trueRange;						
			
			/* 
			This is not the real first bar, this is the first bar after the MaxBarsBack. 
			The MaxBarsBack has been set to 1, so the absolute position of this bar is 2nd indeed.
			*/						
			if (Bars.CurrentBar == 1) {
				
				double trueRangeOfBarZero = Math.Abs(Bars.High[1] - Bars.Low[1]);
				
				trueRange = Math.Max(Math.Abs(Bars.Low[0] - Bars.Close[1]), Math.Max(Math.Abs(Bars.High[0] - Bars.Low[0]), Math.Abs(Bars.High[0] - Bars.Close[1])));
				
				// we calculate ATR of the first (absolute) and second (absolute)
				atrSeries.Value = (trueRangeOfBarZero + trueRange) / 2;
			}
			
			// Start from 2nd bar (CurrentBar) / 3rd bar (CurrentBarAbsolute)
			else {
				
				trueRange = Math.Max(Math.Abs(Bars.Low[0] - Bars.Close[1]), Math.Max(Math.Abs(Bars.High[0] - Bars.Low[0]), Math.Abs(Bars.High[0] - Bars.Close[1])));
				
				// we will multiply by currentBar. So on the 2nd bar (CurrentBar), we wiill multiply by 2 and divide by 3 since 1st bar (currentbar) has an average of two days.
				atrSeries.Value = (Math.Min(Bars.CurrentBar, Period-1) * atrSeries[1] + trueRange) / Math.Min(Bars.CurrentBar + 1, Period);			
			}
			
			if (Bars.CurrentBarAbsolute()+1 >= Period) {
			
				#if DEBUG				
					Output.WriteLine("Print this bar");		
				#endif				

				// 0 means no displacement to the current bar
				plot1.Set(0, atrSeries.Value);
			}			

			#if DEBUG								
				Output.WriteLine("Close[1]={0} High[0]={1} Low[0]={2}",
				Bars.Close[1],
				Bars.High[0], 
				Bars.Low[0]);
			
				Output.WriteLine("atrSeries[1]={0} trueRange[0]={1} multiplier={2} divider={3} atrSeries.Value={4}",
				atrSeries[1],
				trueRange,
				Math.Min(Bars.CurrentBar, Period-1),
				Math.Min(Bars.CurrentBar + 1, Period),
				atrSeries.Value
				);
			#endif			
			
			#if DEBUG					
				Output.WriteLine("CalcBar()");
				Output.WriteLine("");
			#endif						
		}
	}
}
However I when try to reference it in the below strategy and backtest it, it always throw "tried to reference more bars than allowed by the current max bars back setting".

I have set the MaxBarBack of the strategy to 5 and using Period as 5, but still no luck.

 
Code
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;

namespace PowerLanguage.Strategy {
	
	public class Jeffrey_SimpleIntraDayBreakoutLE : SignalObject {
				
		public Jeffrey_SimpleIntraDayBreakoutLE(object _ctx):base(_ctx){}
		
		private int _Period;

		[Input]	
        public int Period
        {
            get { return this._Period; }
            set { 
				
				if (value<1) {
					this._Period = 1;
				} else {
					this._Period = value; 
				}			
			}
        }	
		
		private IOrderMarket buy_order;
		private IOrderMarket sell_order;		
				
		private TimeSpan morningStartTime;
		private TimeSpan morningEndTime;
		
		private TimeSpan afternoonStartTime;
		private TimeSpan afternoonEndTime;
		
		private TimeSpan nightStartTime;
		private TimeSpan nightEndTime;		
		
		private PowerLanguage.Indicator.Jeffrey_ATR atr;
		
		protected override void Create() {
			
			// create variable objects, function objects, order objects etc.
			buy_order = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
			sell_order = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Sell));

			atr = (PowerLanguage.Indicator.Jeffrey_ATR)AddIndicator("Jeffrey_ATR");

		}
		protected override void StartCalc() {
						
			#if DEBUG							
				Output.Clear();
				Output.WriteLine("{0} StartCalc()", this.GetType().ToString());			
				Output.WriteLine("[{0}] CurrentBar={1} CurrentBarAbsolute+1={2} MaxBarsBack={3} Period={4} Close[0]={5}",
				Bars.Time[0].ToString("yyyy/MM/dd HH:mm:ss"),			
	            Bars.CurrentBar,
				Bars.CurrentBarAbsolute()+1,
	            ExecInfo.MaxBarsBack,
				Period,
				Bars.Close[0]);
			#endif				
			
			#if DEBUG						
				Output.WriteLine("StartCalc()");			
				Output.WriteLine("");
			#endif				
		}
		protected override void CalcBar(){
			
			#if DEBUG			
				Output.WriteLine("CalcBar()");
				Output.WriteLine("[{0}] CurrentBar={1} CurrentBarAbsolute+1={2}",
				Bars.Time[0].ToString("yyyy/MM/dd HH:mm:ss"),
				Bars.CurrentBar, 				
				Bars.CurrentBarAbsolute()+1);			
			#endif			
			
			bool entryCondition1 = Bars.Close[0] - Bars.Close[1] > 1000; 
			bool exitCondition1 = Bars.Close[0] - Bars.Close[1] < 1000; 

			
			if (entryCondition1) {
				buy_order.Send();								
			}

			if (exitCondition1) {
				sell_order.Send();								
			}
			
			
			#if DEBUG					
				Output.WriteLine("CalcBar()");
				Output.WriteLine("");
			#endif					
		}
	}
}
the problem is from the line: atr = (PowerLanguage.Indicator.Jeffrey_ATR)AddIndicator("Jeffrey_ATR"); if I comment this out the strategy is able to work.

Anyone have a clue about what's going on?

Reply With Quote
 
  #2 (permalink)
Elite Member
Cleveland Ohio/United States
 
Futures Experience: Advanced
Platform: Tradestation
Broker/Data: various
Favorite Futures: futures
 
Posts: 2,386 since Jul 2012
Thanks: 1,138 given, 4,384 received

It is telling you you need more than 5 for the max bars back value. So, try 10, and see if it works. Or, keep increasing it until it doesn't throw the error.

If you have any questions please send me a Private Message or use the futures.io "Ask Me Anything" thread
Reply With Quote
 
  #3 (permalink)
 Vendor: tradingcode.net 
The Netherlands
 
Futures Experience: None
Platform: MultiCharts, TradingView
Favorite Futures: ...
 
Jura's Avatar
 
Posts: 774 since Apr 2010
Thanks: 2,347 given, 661 received



kevinkdog View Post
It is telling you you need more than 5 for the max bars back value. So, try 10, and see if it works. Or, keep increasing it until it doesn't throw the error.

A better approach might be to not specify the number of MaxBarsBack explicitly (either manually or programmatically). That way MultiCharts will use auto-detect for the number of MaxBarsBack, ensuring this value is always big enough for the script's calculations.

Reply With Quote

Reply



futures io > > > > Showing "tried to reference back more bars" in backtest

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
tried to reference too many bars back malibu TradeStation 4 June 2nd, 2014 04:33 PM
Crossing back to the"The first Fibonacci support" fractal EasyLanguage Programming 3 March 26th, 2012 08:53 AM
Fukushima: "China Syndrome Is Inevitable" ... "Huge Steam Explosions", or "Nuclear Bo Quick Summary News and Current Events 0 November 22nd, 2011 02:50 AM
How to change "Stop Loss" and "Take Profit" in "shElderImpulse" Strategy javed759 NinjaTrader 1 November 1st, 2011 11:44 PM
"mid", "buy", "sell" volumes lokgotkent Traders Hideout 6 September 30th, 2011 02:24 PM


All times are GMT -4. The time now is 10:54 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-11 in 0.08 seconds with 19 queries on phoenix via your IP 54.145.16.43