Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need help with Strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Need help with Strategy

    if i have the following code in my indicator,
    Code:
     if(CurrentBar<1)  
    		{
    			
    			if(Smooth > 1 && avg==null)
    				avg=(HMA(Input,Smooth));
    			trend.Set(true);
                UpTrend.Set(Input[0]);
                DownTrend.Set(Input[0]);
    			
    			//MACD
    				fastEma.Set(Input[0]);
    				macdAvg2.Set(Input[0]);
    				Value.Set(0);
    				Avg.Set(0);
    				Diff.Set(0);
                return;
    		}
    how do i resolve the issue of initializing the variables at no bar.
    Thanks.

    #2
    sherazwaqar,

    I would suggest checking if CurrentBar <= 0, then simply return. The issue is that you wont have values accessible possibly. CurrentBar can be -1 as well before there is any data in the primary series.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      is there any other that is called between the initialize and the onbarupdate() method. I have copied the code from the indicator to strategy and replaced the drawarrow code with the enterlong and entershort. But the arrows from the indicator are different from the trades taken by strategy.

      Comment


        #4
        sherazwaqar,

        You can use OnStartup to initialize variables.

        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Need urgent help

          I have this code, which is running perfectly in indicator but when i use this in straretgy it creates an error " Error on calling 'OnBarUpdate' method for strategy etc/.......bject reference not set to an instance of an object" , but i have initialized all the objects.

          Code:
          if(CurrentBar<1)  
          		{
          			
          			if(Smooth > 1 && avg==null)
          				avg=(HMA(Input,Smooth));
          			trend.Set(true);
                      UpTrend.Set(Input[0]);
                      DownTrend.Set(Input[0]);
          			
          			//MACD
          				fastEma.Set(Input[0]);
          				macdAvg2.Set(Input[0]);
          				Value.Set(0);
          				Avg.Set(0);
          				Diff.Set(0);
                      return;
          		}
          and when i check it through out put window and set if(CurrentBar ==21) on this condition it is working fine, but entershort(), enterlong() arrows are not correct place. as my indicator is doing. Please help me i will thankful to you.

          Comment


            #6
            sherazwaqar,

            What is the Calculate on bar close setting for the indicator, and for the strategy?

            There must be one object that is being overlooked, i.e. not instantiated. Its most likely one of the plots dataseries that needs some code added to the "Properties" section of your code.

            For example :

            Code:
            [Browsable(false)]	// this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                    [XmlIgnore()]		// this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                    public DataSeries CurrentOpen
                    {
                        get { return Values[0]; }
                    }
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              need urgent help

              Thanx to reply,
              the setting of calculate on bar close is default(true)in both cases. and also when i initialized the IDataSeries avg as you told(in properties) but it is generating an error.


              Code:
               #region Variables
              			private IDataSeries avg 	= null; ([COLOR="Red"]is this correct way to initialize the IDataSeries object [/COLOR])
              			
                                      private BoolSeries trend;
              			private DataSeries 	fastEma;
              			private DataSeries	diffArr;
              			private DataSeries 	macdAvg2;
              			private DataSeries 	signal;
              			private DataSeries	Macd;
              			private DataSeries	MacdUp;
              			private DataSeries	MacdDn;
              			private DataSeries	MacdNeutral;
              			private DataSeries 	Avg;
              			private DataSeries	Diff;
              			private DataSeries	ADX1;	
              		        private DataSeries      closeopen;
              			private DataSeries      highlow;
              			private DataSeries      plot0;
              			private DataSeries      UpTrend;
              			private DataSeries      DownTrend;
                      #endregion
              
                      /// This method is used to configure the strategy and is called once before any         protected override void Initialize()
                      {
                         
              			closeopen			= new DataSeries(this);
              			highlow				= new DataSeries(this);
              			plot0 				= new DataSeries(this);
              			
              		         fastEma				= new DataSeries(this);
              			macdAvg2			= new DataSeries(this);
              			diffArr				= new DataSeries(this);
              			signal				= new DataSeries(this);
              			
              			Macd				= new DataSeries(this);
              			MacdUp				= new DataSeries(this);
              			MacdDn				= new DataSeries(this);
              			MacdNeutral			= new DataSeries(this);
              			Avg					= new DataSeries(this);
              			Diff				= new DataSeries(this);
              			ADX1				= new DataSeries(this);	
              			trend 				= new BoolSeries(this);
              			UpTrend				= new DataSeries(this);	
              			DownTrend			= new DataSeries(this);	
              						
              			CalculateOnBarClose = true;
                       
              		}
              can you tell me what object i have not initialized?? i think i have initialized every thing. i dont know why that code is creating an error? when i use CurrentBar==21 in strategy then it is working but in indicator i am using CurrentBar<1 , but result is not correct as my indicator indicates. i have need as my indicator results in strategy. please help thanks

              Comment


                #8
                sherazwaqar, please try this : work with the IDataSeries exactly the same in the variables section as you would with the regular DataSeries objects, don't set it to null here. Skip the Initialize() section for it, but on the first OnBarUpdate() bar (CurrentBar < 1) set this to a dummy start value, for example Input. Then recheck.
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by bortz, 11-06-2023, 08:04 AM
                47 responses
                1,609 views
                0 likes
                Last Post aligator  
                Started by jaybedreamin, Today, 05:56 PM
                0 responses
                9 views
                0 likes
                Last Post jaybedreamin  
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                19 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by Jon17, Today, 04:33 PM
                0 responses
                6 views
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                16 views
                0 likes
                Last Post Javierw.ok  
                Working...
                X