• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Plotting Indicator On Chart With Variables

  • Filter
  • Time
  • Show
Clear All
new posts

    Plotting Indicator On Chart With Variables

    Hello. I've been trying to figure this out for a few days and no can do. Im trying to simply add an opening range indicator to the chart in my strategy but don't want the time parameters to be static, instead I'd like to select them in the strategy analyzer so I can optmize/try different time's etc.

    The issue is, getting the ADD function to recognize my line of code which includes variables. This is what the normal static line would look like without variables
    Add(BzvOpeningRange4("0300", "0400", "1400"));

    Im looking to replace the three time slots with variables and created the following code:

    	#region variables
    		private string 	ORind 				= null;		//String to hold the full code for the Opening Range Indicator
    		private int		orstarth			= 300;		// Opening Range Start Hour
    		private int		orstartm			= 30;		// Opening Range Start Minutes
    		private int		orendh				= 400;		// Opening Range End Hour
    		private int		orendm				= 0;		// Opening Range End Minutes
    		private int		orstoph				= 1300;		// Opening Range Stop Hour
    		private int		orstopm				= 0;		// Opening Range Stop Minutes
    		private int 	orstart 			= 0;		// Opening Range Start Time. Hour and minutes combined
    		private int 	orend				= 0;		// Opening Range End Time. Hour And Minutes Combined
    		private int 	orstop 				= 0;		// Opening Range Stop Time. Hour And Minutes Combined
    protected override void Initialize()
    			orstart = orstarth+orstartm; 	//Combines the Hour and minutes
    			orend = orendh+orendm;			//Combines the Hour and minutes
    			orstop = orstoph+orstopm;		//Combines the Hour and minutes
    			ORind = "BzvOpeningRange4(\"0"+orstart+"\", \"0"+orend+"\", \""+orstop+"\")"; 	 //Combines all the above into a string
    			PrintWithTimeStamp(ORind);		//Prints Output just for visual confirmation
    			Add(ORind);						//Actual line which ADDs the indicator
    THe print output shows exactly what I should have which is
    BzvOpeningRange4("0300", "0400", "1400")
    but when compiling I get the following error messages
    "The best overloaded method match for 'NinjaTrader.Strategy.StrategyBase.Add(NinjaTrader .Indicator.IndicatorBase)' has some invalid arguments"
    "Strategy\OrbNay1g.cs Argument '1': cannot convert from 'string' to 'NinjaTrader.Indicator.IndicatorBase' CS1503 - click for info 977 8"

    Any help would be appreciated
    Last edited by naydee; 11-07-2014, 12:46 PM.

    naydee, would this compile for you then as alternative?

    Add(BzvOpeningRange4(orstart, orend, orstop);

    Your present version will not compile as it expects an indicator as input and not a string.
    BertrandNinjaTrader Customer Service


      Thats what I had originally tried and it didn't work.. As I was waiting for your response I tried the following and it did indeed work
      Add(BzvOpeningRange4("0"+orstart+"", "0"+orend+"", ""+orstop+""));

      Seems the quotes are needed for the indicator, without them it won't compile. Its now loading perfectly, question.. When I refer to this indcator within my strategy "onbarupdate" should I reference it just as above with the dual double quotes or is there a more elegant way? Im just making some of this stuff up through trial and error and reading the forums


        Great to hear.

        You could assign as well to a variable like -

        private BzvOpeningRange4 ind; // in your variables section

        ind = BzvOpeningRange4("0"+orstart+"", "0"+orend+"", ""+orstop+"");

        And then call ind[0] for example in OnBarUpdate() for the current value...
        BertrandNinjaTrader Customer Service


          Oh great, I didn't know you could do that. I will give it a shot. Thanks bud


          Latest Posts


          Topics Statistics Last Post
          Started by heurvsgs, Today, 02:27 AM
          0 responses
          1 view
          Last Post heurvsgs  
          Started by Ntrifix, Today, 02:26 AM
          0 responses
          1 view
          Last Post Ntrifix
          by Ntrifix
          Started by aviat72, Today, 12:41 AM
          1 response
          Last Post NinjaTrader_ChrisSch  
          Started by _Zero_, 01-06-2020, 01:16 PM
          2 responses
          Last Post CiprianV  
          Started by RuthB, 05-29-2020, 09:41 PM
          3 responses
          Last Post aviat72
          by aviat72