Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi instrument

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

    Multi instrument

    Hello. I want general stock enter market after some conditions of secondary instrument.
    So, I add new stock in strategy from sample like this

    Code:
     
    protected override void Initialize()
            {
    			...................................
    			
    			// Add own index to strategy
    			Add("MSFT", PeriodType.Day, 1);
    			
    			CalculateOnBarClose = true;
            }
    Than I'd like to enter long if secondary stock (MSFT) close more than previous 20 closes. How to do this?

    Code:
    protected override void OnBarUpdate()
            {
                
    			// Condition for long
    			if (
    				Close(BarsArray[1])[0]>=MAX(BarsArray[1],20)&& 
    .................................................................................................................................

    #2
    Hello,

    You'll want to use Closes to get the correct closing price if you're outside of the secondary series

    If you haven't done so already I'd suggest reading this article: http://www.ninjatrader.com/support/h...nstruments.htm

    Code:
    if( Closes[1][0] >= MAX(BarsArray[1],20) )
    {
      //enter long here, you'll want to pass the correct BarsInProgress overload
    }
    http://www.ninjatrader.com/support/h...?enterlong.htm

    Let me know if I can further assist.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Check for instrument name or class in script

      Hello. I use strategy to backtest some instruments. What if I need to check in script name and class of instrument?
      For example, I run Strategy Analyzer on forex $EURUSD, $USDCAD, stock MSFT, futures CL ##-##. So, how and when to check (in Initialize() or in OnBarUpdate())? Because Instrument can't be accessed within the Initialize() method.

      Comment


        #4
        Hello alexstox,

        Thank you for your post.

        You can do this at the beginning of the OnBarUpdate() method using the Instrument.FullName: http://www.ninjatrader.com/support/h...t_fullname.htm

        Comment


          #5
          Originally posted by NinjaTrader_PatrickH View Post
          Hello alexstox,

          Thank you for your post.

          You can do this at the beginning of the OnBarUpdate() method using the Instrument.FullName: http://www.ninjatrader.com/support/h...t_fullname.htm
          Well, I thought it's too brutal. Maybe Instrument can be used in OnStartUp()?

          Comment


            #6
            Week bar value in Day bar

            One more question. I add weekly chart to strategy. So, there are MSFT daily and MSFT weekly. I check for week close up or down. Problem is that this up or down true only on day which week closes.

            For example, week closed on 11JUL2014 and condition is true only on 11JUL2014, next only on 18JUL2014, but not on 14,15,16,17JUL2014.

            What should I do to see last week close in after-week-close days?

            Comment


              #7
              Hello alexstox,

              Thank you for your response.

              Bars would not be loaded OnStartUp() either. And for the Weekly close you need to make sure you are accessing the Closes[1][0] to ensure you are accessing the weekly close. If this is not the case can you provide the code that is not working?

              Comment


                #8
                Originally posted by NinjaTrader_PatrickH View Post
                Hello alexstox,

                Thank you for your response.

                Bars would not be loaded OnStartUp() either. And for the Weekly close you need to make sure you are accessing the Closes[1][0] to ensure you are accessing the weekly close. If this is not the case can you provide the code that is not working?
                1) I asked about OnStartUp() to check for Instrument.FullName. Will it work there?
                2) I use indicator with BoolSeries UP and DOWN (week close up or week close down). So, in strategy script OnBarUpdate() condition UP[0] is true only on week's end. That;s why days between two weeks' ends are false. How to avoid this?
                Last edited by alexstox; 07-15-2014, 01:24 AM.

                Comment


                  #9
                  Hello alexstox,

                  The Instrument.FullName will work in the OnStartUp() method. The value of the BoolSeries should be the previous week's end until the current week does in fact close, so your understanding of the issue is incorrect. The value is only false if the previous is down.

                  If you do not believe this is the case, please provide the full code used for the BoolSeries.

                  Comment


                    #10
                    Please look at attached Output. So, as you see there on week's end day (date at which week closes) everything is OK. But days betweens weeks' ends are contrary.
                    Click image for larger version

Name:	WeekClose.PNG
Views:	2
Size:	38.8 KB
ID:	870810

                    Code:
                    protected override void OnBarUpdate()
                    		{
                    			if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired /*|| CurrentBars[2] <= 20*/)
                    				return;
                    	if (BarsInProgress==1) //start BarsInProgress
                    {
                    if (blablabla)
                    	{
                    	WeekHigh=High[0];
                    	WeekLow=Low[0];
                    	momDW=0;
                    	momUP=1;
                                   }
                    		
                    else if ( blablabla)
                    	{
                    	WeekLow=Low[0];
                    	WeekHigh=High[0];
                    	momDW=1;
                    	momUP=0;
                    	}
                    				
                    if(momUP==1) 
                    {
                    dOWNweek.Set(false);
                    uPweek.Set(true);
                    }
                    					
                    else if(momDW==1) 
                    {
                    dOWNweek.Set(true);
                    uPweek.Set(false);
                    }
                    So, I think this because of BarsInProgress==1 is absent in between weeks's ends days. Indicator works with weekly bars. I use this indicator in strategy with daily bars.

                    Comment


                      #11
                      Hello alexstox,

                      Thank you for your response.

                      Can you provide a full test script attached to your response in it's .cs file format? Are you using CalculatOnBarClose = False?

                      Comment


                        #12
                        Originally posted by NinjaTrader_PatrickH View Post
                        Hello alexstox,

                        Thank you for your response.

                        Can you provide a full test script attached to your response in it's .cs file format? Are you using CalculatOnBarClose = False?
                        I can sent it to you via mail. I used COBC=False and True. Nothing changed.
                        I used script on EOD data in Strategy Analyzer

                        Comment


                          #13
                          Hello alexstox,

                          Thank you for sending in the file.

                          Are you applying the same indicator to another bar series? How are you getting the days between the week closes?

                          Comment


                            #14
                            Originally posted by NinjaTrader_PatrickH View Post
                            Hello alexstox,

                            Thank you for sending in the file.

                            Are you applying the same indicator to another bar series? How are you getting the days between the week closes?
                            In strategy script I add
                            Add(MyInstrum1,PeriodType.Week,1);
                            Than in OnBarUpdate() tried to use as condition
                            CloseWeek(MyInstrum1).UPweek[0]
                            but you know the result.

                            You know what is interesting? After week Up on following days Upweek==false, DOWNweek==true!!!! and vice versa after week DOWN on following days DOWNweek==false, UPweek==true!!! You can see this in Output, that I attached earlier.

                            Comment


                              #15
                              So, can you help me please?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by siroki, Today, 03:22 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post siroki
                              by siroki
                               
                              Started by nailui, Today, 03:01 AM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by an.fedorov, Today, 02:32 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post an.fedorov  
                              Started by rustyspring, Today, 01:31 AM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by op1031, Today, 12:26 AM
                              0 responses
                              12 views
                              0 likes
                              Last Post op1031
                              by op1031
                               
                              Working...
                              X