NexusFi: Find Your Edge


Home Menu

 





MaxBarsBack in Signal problem


Discussion in MultiCharts

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




 
Search this Thread

MaxBarsBack in Signal problem

  #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 tried to code some very simple signal using my own indicator as below:

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

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

		[Input]	
        public int Period
        {
            get { return this._Period; }
            set { 
				
				if (value<2) {
					this._Period = 2;
				} else {
					this._Period = value; 
				}			
			}
        }			
		
		private IOrderMarket buy_order;
		private IOrderMarket sell_order;	
		
		private PowerLanguage.Indicator.Jeffrey_ATR_v2 atr;
		
		private PowerLanguage.Indicator.Jeffrey_HMA hma;		
		
		protected override void Create() {
			// create variable objects, function objects, order objects etc.

			// 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_v2)AddIndicator("Jeffrey_ATR_v2");
			atr.Mode=1;
			atr.Period=Period;
			*/
			
			
			hma = (PowerLanguage.Indicator.Jeffrey_HMA)AddIndicator("Jeffrey_HMA");
			hma.Period=Period;
			
			
		}
		protected override void StartCalc() {
			// assign inputs 
			
			#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(){
			// strategy logic 

			
			#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 = hma.Plots[0].Values[0] > hma.Plots[0].Values[1];
			bool exitCondition1 = hma.Plots[0].Values[0] < hma.Plots[0].Values[1];

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

			if (exitCondition1) {
				sell_order.Send();								
			}
			
			#if DEBUG					
				Output.WriteLine("CalcBar()");
				Output.WriteLine("");
			#endif					
			
		}
	}
}
I have set the period to 10 and maxbarsSetting in the properties to 500. However I still get the error saying I am referencing the bars outside the range.

It is totally fine if I use my own HMA indicator as study since I will set the period to 2 as minimum programmatically. Not sure why it become so trouble when it is referenced inside a strategy.




Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Build trailing stop for micro index(s)
Psychology and Money Management
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
Futures True Range Report
The Elite Circle
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Are there any eval firms that allow you to sink to your …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
60 thanks
Funded Trader platforms
43 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #2 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690

I saw you also posted this on the MultiCharts forum. Can you update whether it's solved for you now?

It would be a shame if people on futures.io (formerly BMT) invest time in trying to solve this problem when it's already solved.

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


No...No reply from MC support right now.

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


Jeffrey View Post
No...No reply from MC support right now.


Solved. If the signal is calling an indicator with MaxBarSetting coded programmatically, it will throw error.

I think the reason is MC allows user to set the MaxBarSetting in the signal's properties tab, and the value can't override the one inside the indicator.

Strange design thru, the MaxBarSetting shouldn't be set programmatically unless you will never use it inside a signal.

Started this thread Reply With Quote




Last Updated on June 30, 2015


© 2024 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 - Privacy Policy - Downloads - Top
no new posts