Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

At my wits end with this Multi-Instrument Indicator.

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

    At my wits end with this Multi-Instrument Indicator.

    Hello,

    I have developed a multi-instrument indicator to show me the relative strength of a basket of currencies.

    The first version of the indicator that I created on just 4 JPY pairs works.

    The second version, with almost identical code, I created for 7 pairs on the EUR DOES NOT.

    JPY version works.

    EUR version does not.

    SAME CODE!

    Verified that I have data from my provider to the indicator, so that is not the issue.

    This is driving me nuts!

    JPY CODE

    Code:
    public class RelativeStrengthJPY : Indicator
    {
            #region Variables
            // Wizard generated variables
            // User defined variables (add any user defined variables below)
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
    			Add(new Plot(Color.FromKnownColor(KnownColor.Cyan), PlotStyle.Line, "FifteenMinute"));
                Add(new Plot(Color.FromKnownColor(KnownColor.MediumBlue), PlotStyle.Line, "OneHour"));
               
                Add(new Line(Color.FromKnownColor(KnownColor.Green), 75, "OverBought"));
                Add(new Line(Color.FromKnownColor(KnownColor.Red), 25, "OverSold"));
                Overlay				= false;
    			
    			//Fifteen minute time period
    			Add("$USDJPY",PeriodType.Minute, 15); //bars array 1
    			Add("$GBPJPY",PeriodType.Minute, 15); //bars array 2
    			Add("$CHFJPY",PeriodType.Minute, 15); //bars array 3
    			Add("$EURJPY",PeriodType.Minute, 15); //bars array 4
    			Add("$AUDJPY",PeriodType.Minute, 15); //bars array 5
    			
    			
    			
    			//60 minute period
    			Add("$USDJPY",PeriodType.Minute, 60); //bars array 6
    			Add("$GBPJPY",PeriodType.Minute, 60); //bars array 7
    			Add("$CHFJPY",PeriodType.Minute, 60); //bars array 8
    			Add("$EURJPY",PeriodType.Minute, 60); //bars array 9
    			Add("$AUDJPY",PeriodType.Minute, 60); //bars array 10
    			
    			
    			
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			 // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
                double hourly_strength;
    	    double fifteen_minute_strength;
    			
    			if (CurrentBar < 3)
    				return;
    			
               	
    			
    			fifteen_minute_strength = 100 - ( ( RSI(BarsArray[1],2,1)[0] + RSI(BarsArray[2],2,1)[0]
    			+RSI(BarsArray[3],2,1)[0] + RSI(BarsArray[4],2,1)[0] + RSI(BarsArray[5],2,1)[0])
    			/ 5);
    			
    			hourly_strength = 100 - ( ( RSI(BarsArray[6],2,1)[0] + RSI(BarsArray[7],2,1)[0]
    			+RSI(BarsArray[8],2,1)[0] + RSI(BarsArray[9],2,1)[0] + RSI(BarsArray[10],2,1)[0]
    			)/ 5);
    			
    			
    			
    			
    			
    			OneHour.Set(hourly_strength);
                
                FifteenMinute.Set(fifteen_minute_strength);
            }


    EUR CODE



    Code:
    public class RelativeStrengthEUR : Indicator
        {
            #region Variables
            // Wizard generated variables
            // User defined variables (add any user defined variables below)
    		double hourly_strength;
    		double fifteen_minute_strength;
    		
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
    			Add(new Plot(Color.FromKnownColor(KnownColor.Cyan), PlotStyle.Line, "FifteenMinute"));
                Add(new Plot(Color.FromKnownColor(KnownColor.MediumBlue), PlotStyle.Line, "OneHour"));
    			
                Add(new Line(Color.FromKnownColor(KnownColor.Green), 75, "OverBought"));
                Add(new Line(Color.FromKnownColor(KnownColor.Red), 25, "OverSold"));
                Overlay				= false;
    			
    			//Fifteen minute time period
    			Add("$EURUSD",PeriodType.Minute, 15); //bars array 1
    			Add("$EURJPY",PeriodType.Minute, 15); //bars array 2
    			Add("$EURGBP",PeriodType.Minute, 15); //bars array 3
    			Add("$EURCHF",PeriodType.Minute, 15); //bars array 4
    			Add("$EURAUD",PeriodType.Minute, 15); //bars array 5
    			Add("$EURNZD",PeriodType.Minute, 15); //bars array 6
    			Add("$EURCAD",PeriodType.Minute, 15); //bars array 7
    			
    			//One hour time period
    			Add("$EURUSD",PeriodType.Minute, 60); //bars array 8
    			Add("$EURJPY",PeriodType.Minute, 60); //bars array 9
    			Add("$EURGBP",PeriodType.Minute, 60); //bars array 10
    			Add("$EURCHF",PeriodType.Minute, 60); //bars array 11
    			Add("$EURAUD",PeriodType.Minute, 60); //bars array 12
    			Add("$EURNZD",PeriodType.Minute, 60); //bars array 13
    			Add("$EURCAD",PeriodType.Minute, 60); //bars array 14
    			
    			
    			
    			
    			
    			
    		
    			
    			
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			 // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
               
    			if(CurrentBar < 3)
    				return;
    			 
    			
               	
    			//15 Min RSI
    			fifteen_minute_strength =  
    			  (RSI(BarsArray[1],2,1)[0]
    			+ RSI(BarsArray[2],2,1)[0]
    			+ RSI(BarsArray[3],2,1)[0]
    			+ RSI(BarsArray[4],2,1)[0]
    			+ RSI(BarsArray[5],2,1)[0]
    			+ RSI(BarsArray[6],2,1)[0]
    			+ RSI(BarsArray[7],2,1)[0])/7;
    			
    			
    			//1H RSI
    			hourly_strength =  
    			  (RSI(BarsArray[8],2,1)[0]
    			+ RSI(BarsArray[9],2,1)[0]
    			+ RSI(BarsArray[10],2,1)[0]
    			+ RSI(BarsArray[11],2,1)[0]
    			+ RSI(BarsArray[12],2,1)[0]
    			+ RSI(BarsArray[13],2,1)[0]
    			+ RSI(BarsArray[14],2,1)[0])/7;
    			
    			
    			
    			
    								
                FifteenMinute.Set(fifteen_minute_strength);
    			
    			OneHour.Set(hourly_strength);
    			
            }

    #2
    Unhommefou, any errors in the log tab as you apply your indicators to the charts? Please try incorporating a CurrentBars check for each individual series in the indicators at the OnBarUpdate() start -

    Code:
    if (CurrentBars[0] < 0 || CurrentBars[1] < 0 || ..... CurrentBars[x] < 0) return;
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Yes, Bert is correct. I just replaced your current bar check with this and it works for me:

      if (CurrentBars[0] < 0
      || CurrentBars[
      1] < 0
      || CurrentBars[
      2] < 0
      || CurrentBars[3] < 0
      || CurrentBars[4] < 0
      || CurrentBars[5] < 0
      || CurrentBars[6] < 0
      || CurrentBars[7] < 0
      || CurrentBars[8] < 0
      || CurrentBars[9] < 0
      || CurrentBars[10] < 0
      || CurrentBars[11] < 0
      || CurrentBars[12] < 0
      || CurrentBars[13] < 0) return;

      Last edited by mountainclimber; 05-07-2010, 10:25 AM.

      Comment


        #4
        Originally posted by NinjaTrader_Bertrand View Post
        Unhommefou, any errors in the log tab as you apply your indicators to the charts? Please try incorporating a CurrentBars check for each individual series in the indicators at the OnBarUpdate() start -

        Code:
        if (CurrentBars[0] < 0 || CurrentBars[1] < 0 || ..... CurrentBars[x] < 0) return;
        Yep, that did the trick!

        Thank you. Here's a virtual hug!

        ::hug::

        Comment


          #5
          Great!
          ........................................
          Last edited by mountainclimber; 05-07-2010, 10:25 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by yertle, 04-18-2024, 08:38 AM
          9 responses
          40 views
          0 likes
          Last Post yertle
          by yertle
           
          Started by techgetgame, Yesterday, 11:42 PM
          0 responses
          9 views
          0 likes
          Last Post techgetgame  
          Started by sephichapdson, Yesterday, 11:36 PM
          0 responses
          2 views
          0 likes
          Last Post sephichapdson  
          Started by bortz, 11-06-2023, 08:04 AM
          47 responses
          1,615 views
          0 likes
          Last Post aligator  
          Started by jaybedreamin, Yesterday, 05:56 PM
          0 responses
          10 views
          0 likes
          Last Post jaybedreamin  
          Working...
          X