Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strange question

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

    strange question

    by any chance is there a way in NT7 to upload an instrument as secondary instrument that returns a constant value of 1?

    I am using the Add("variable", PeriodType.Minute, 60); // BarsArray[1] type to add a secondary instrument in my strategy. The strategy will automatically assign an instrument to the variable, however under certain circumstances I would need the value to be constant ==1

    #2
    Hello yades,

    Thank you for your post.

    This would not be possible without creating a data feed that provided a constant value of 1. You can however do this by creating a data series that has a constant value of 1. Please see the example below on how to add this data series and call it into an indicator as the input:
    Code:
            #region Variables
    		private DataSeries myDataSeries;
            #endregion
    		
            protected override void Initialize()
    		{			
    			myDataSeries = new DataSeries(this);
    		}
    
            protected override void OnBarUpdate()
            {	
    			myDataSeries.Set(1);
    			
    			//Prints the 10 period SMA of the myDataSeries
    			Print(SMA(myDataSeries, 10)[0]);
    		}
    For information on the DataSeries class please visit the following link: http://www.ninjatrader.com/support/h...ries_class.htm

    Please let me know if I may be of further assistance.

    Comment


      #3
      Patrick
      very useful, I need a secondary instrument in my strategy to recall the cross rate for forex rates, but only for specific xurrency pairs.

      Do you think this script would work:

      Code:
      Variables
      		
      	private string variable0
      	myDataSeries = new DataSeries(this);	
      
      Initialize()
      
      	myDataSeries = new DataSeries(this);					
      	Add(xRate, PeriodType.Minute, 60)// BarsArray[1]	
      
      protected override void OnStartUp()
      {
      	var variable0 = String.Empty;
      	if(Instrument.MasterInstrument.Name == "USDJPY") variable0 = "$GBPJPY";
      	if(Instrument.MasterInstrument.Name == "EURUSD") variable0 = "$GBPUSD";
      	if(Instrument.MasterInstrument.Name == "EURGBP") variable0 = "myDataSeries"; 
      }
      
      protected override void OnBarUpdate()
      {
      	myDataSeries.Set(1);
      Originally posted by NinjaTrader_PatrickH View Post
      Hello yades,

      Thank you for your post.

      This would not be possible without creating a data feed that provided a constant value of 1. You can however do this by creating a data series that has a constant value of 1. Please see the example below on how to add this data series and call it into an indicator as the input:
      Code:
              #region Variables
      		private DataSeries myDataSeries;
              #endregion
      		
              protected override void Initialize()
      		{			
      			myDataSeries = new DataSeries(this);
      		}
      
              protected override void OnBarUpdate()
              {	
      			myDataSeries.Set(1);
      			
      			//Prints the 10 period SMA of the myDataSeries
      			Print(SMA(myDataSeries, 10)[0]);
      		}
      For information on the DataSeries class please visit the following link: http://www.ninjatrader.com/support/h...ries_class.htm

      Please let me know if I may be of further assistance.

      Comment


        #4
        Hello yades,

        Thank you for your response.

        I do not understand what you intend to do with variable0, can you explain this section of the code further?
        Code:
        var variable0 = String.Empty;
        	if(Instrument.MasterInstrument.Name == "USDJPY") variable0 = "$GBPJPY";
        	if(Instrument.MasterInstrument.Name == "EURUSD") variable0 = "$GBPUSD";
        	if(Instrument.MasterInstrument.Name == "EURGBP") variable0 = "myDataSeries";
        I look forward to your response.

        Comment


          #5
          sure.

          First of all this is a MTF strategy.

          According to what my primary instrument is (BarsArray[0]), I want my strategy to select a specific secondary instrument (BarsArray[1]), given this selection is done only once on start-up, i thought it might be convenient to include this computation in the OnStartUp() method. Also I assume the output format of variable0 must be a string, as this will then be used in the Add() method in the Intialize() method to select the secondary instrument. Let me know if this is clear enough.


          Originally posted by NinjaTrader_PatrickH View Post
          Hello yades,

          Thank you for your response.

          I do not understand what you intend to do with variable0, can you explain this section of the code further?
          Code:
          var variable0 = String.Empty;
          	if(Instrument.MasterInstrument.Name == "USDJPY") variable0 = "$GBPJPY";
          	if(Instrument.MasterInstrument.Name == "EURUSD") variable0 = "$GBPUSD";
          	if(Instrument.MasterInstrument.Name == "EURGBP") variable0 = "myDataSeries";
          I look forward to your response.

          Comment


            #6
            Patrick alternatively to the variable i could use a switch type to determine the secondary instrument. However, what I need to know is if this can be done in the OnStartUp() method? I ask this because the string assigned must then be added to the Add() type in the Initiation() camp.

            Originally posted by NinjaTrader_PatrickH View Post
            Hello yades,

            Thank you for your response.

            I do not understand what you intend to do with variable0, can you explain this section of the code further?
            Code:
            var variable0 = String.Empty;
            	if(Instrument.MasterInstrument.Name == "USDJPY") variable0 = "$GBPJPY";
            	if(Instrument.MasterInstrument.Name == "EURUSD") variable0 = "$GBPUSD";
            	if(Instrument.MasterInstrument.Name == "EURGBP") variable0 = "myDataSeries";
            I look forward to your response.

            Comment


              #7
              Hello yades,

              Thank you for your response.

              The "myDataSeries" string will not work as that is a DataSeries and not an instrument. I am not sure how checking the MasterInstrument.Name will work as OnStartUp() is called after Initialize().

              Can you provide details on what exactly you are trying to do?

              I look forward to your response.

              Comment


                #8
                Forget about the myDataSeries, i've another way around this. To cut a long story short I need to know if its possible to set the secondary instrument bars object from within the strategy, hence running a calculation in the initiate() method or elsewhere. Would you be able to advise on this?
                Originally posted by NinjaTrader_PatrickH View Post
                Hello yades,

                Thank you for your response.

                The "myDataSeries" string will not work as that is a DataSeries and not an instrument. I am not sure how checking the MasterInstrument.Name will work as OnStartUp() is called after Initialize().

                Can you provide details on what exactly you are trying to do?

                I look forward to your response.

                Comment


                  #9
                  Hello yades,

                  Thank you for your response.

                  You could do something like the following:
                  Code:
                          protected override void Initialize()
                          {
                             	if(Instrument.MasterInstrument.Name == null)
                  				return;
                  			if(Instrument.MasterInstrument.Name == "EURUSD")
                  			{
                  				Add("$GBPUSD", PeriodType.Minute, 60);
                  			}
                          }
                  Please let me know if I may be of further assistance.

                  Comment


                    #10
                    This answer all my questions. Thanks
                    Originally posted by NinjaTrader_PatrickH View Post
                    Hello yades,

                    Thank you for your response.

                    You could do something like the following:
                    Code:
                            protected override void Initialize()
                            {
                               	if(Instrument.MasterInstrument.Name == null)
                    				return;
                    			if(Instrument.MasterInstrument.Name == "EURUSD")
                    			{
                    				Add("$GBPUSD", PeriodType.Minute, 60);
                    			}
                            }
                    Please let me know if I may be of further assistance.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    655 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    370 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    109 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    574 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    577 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X