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

Issue with passing the Value of an ISeries from an indicator to a Strategy/Addon

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

    Issue with passing the Value of an ISeries from an indicator to a Strategy/Addon

    Hi !

    I'm currently experiencing an issue, with moving the value of an ISeries to an addon then strategy, and would love some help !

    To explain :
    The goal of this is to create a ISeries double and its values in a indicator, to pass this value trough and indicator, to have a strategy getting the values of the Series, and then the strategy use it for a plot.

    - I have a indicator, let's say Indicator1, that create and set the values for a Series double, let's say Series1[0]. The Series1 has the value expected in the indicator, and can be used and printed like expected.

    - I then want the value of Series1 to be used in a strategy, so i create an addon, and in the addon i have a Series<double> called SeriesStorage1.

    - I then do NinjaTrader.NinjaScript.AddOns.Addon1.SeriesStorag e1[0] = Series1[0]

    - And in the strategy i then do SeriesStrategy1[0] = NinjaTrader.NinjaScript.AddOns.Addon1.SeriesStorag e1[0]


    Those principles work great while working with a double, i can even create a Series double in the strategy, and then get the value from the addon IF i'm using a double in the addon. But as soon as i try to use a Series double in the addon to store the value, it will compile, well, but create an error of Object reference not set to an instance of a object.

    This error is common when a Series double is not declared, so i tried to not go trough an addon, and just set the Series1 (from the indicator) to public, and also i tried by changing the Series<double> to static series (or we would get an error), and then in the strategy, do so SeriesStrategy1[0] = NinjaTrader.NinjaScript.Indicators.Indicator1.Seri es1[0]

    Sadly, using this last method, the value dissapear during the transfer, so if i print the Series1[0] value in the indicator before the transfer, we have the correct value, but after the transfer, the value in the SeriesStrategy1[0] go to 0 (not to n/a so the transfer as been tried).

    I suppose this come from the Series<double>, and most likely the use of bar that it is doing, since i have been enable to transfer value with double using all of the methods above (transfer trough addon, or directly from indicator to strategy), but i cannot transfer and successfully recover the value of a Series<double>, and for my script, i need to use a Series<double> where a normal double would sadly not do the job.


    So, could you help me, on how could it be possible to get the value of a ISeries from an indicator, to a strategy and recover the value successfully ?


    Thanks a lot, have a fantastic day !

    #2
    Hello Robinson94,

    Thank you for your post.

    Try utilizing Update() on the indicator in the strategy. For example:

    My Indicator code:
    Code:
    	public class IndicatorSeries : Indicator
    	{
    		private Series<double> myDoubleSeries;
    
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"Enter the description for your new custom Indicator here.";
    				Name										= "IndicatorSeries";
    			}
    			else if (State == State.DataLoaded)
    			{				
    				myDoubleSeries = new Series<double>(this);
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			myDoubleSeries[0] = Close[0];
    		}
    		
    		[Browsable(false)]
    		[XmlIgnore]
            public Series<double> MyDoubleSeries
            {
    			get { return myDoubleSeries; }
            }
    	}
    And then my Strategy code:
    Code:
    	public class StrategyCallIndicatorSeries : Strategy
    	{
    		private IndicatorSeries indySeries;
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"Enter the description for your new custom Strategy here.";
    				Name										= "StrategyCallIndicatorSeries";
    			}
    			else if (State == State.Configure)
    			{
    				AddPlot(Brushes.Orange, "MyPlot");
    			}
    			else if (State == State.DataLoaded)
    			{
    				indySeries = IndicatorSeries();
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			indySeries.Update();
    			
    			Value[0] = indySeries.MyDoubleSeries[0];
    		}
    	}
    You can find details on Update at the following link: https://ninjatrader.com/support/help...-us/update.htm

    Please let me know if you have any questions.

    Comment


      #3
      Thanks so much, using the update, the value transferred can be used in the double.

      Unfortunately, for some reasons, a unusual situation happened in the strategy that i'm building, is that, i have some plots, the value are printing, showing in the databox and the mini data box, but the plots are not plotting and being displayed on the chart.

      The stranger thing, is that i created 2 firsts plots which had this issue (the plot that received the transferred data and values), they were working one time on 3, so if i was reloading NinjaScript enough, without touching the code, sometimes the plots would show and sometimes not.
      Then after waiting a night the issue with those 2 plots vanish, and they were fully working and always displaying like supposed to.

      But now, i created 2 new plots, which have permanently the issue (that they are printing, showing in the databox, but not on the chart), and the first two plots, are working well.

      So i currently have my 4 plots with the value intended, but only 2 of them actually and visually plot on the chart.

      Do you know what could be causing those kind of issues, and how could it be fixed ?

      Here's all the code related to the plots in the strategy :

      Plots 1 & 2 (the one that are plotting) :

      Code:
      AddPlot(new Stroke(Brushes.LimeGreen), PlotStyle.Hash, "My Plot 1");
      AddPlot(new Stroke(Brushes.LimeGreen), PlotStyle.Hash, "My Plot 2");
      
      //On Bar Update :
      Values[0][0] = StorageSavedValueforPlot1;
      Values[1][0] = StorageSavedValueforPlot2;
      
      //In properties :
      [Browsable(false)]
      [XmlIgnore()]
      private double StorageSavedValueforPlot1
      {
      	get
      	{
      		Update();
      		return mySaveValueforPlot1;
      		}
      	}
      		
      [Browsable(false)]
      [XmlIgnore()]
      private double StorageSavedValueforPlot2
      	{
      		get
      		{
      			Update();
      			return MySavedValueForPlot2
      		}
      	}
      And the lines for the 2 Plots that don't appear and are not being displayed :
      Code:
      private NinjaTrader.NinjaScript.Indicators.IndicatorName myIndicator1;
      
      AddPlot(new Stroke(Brushes.Snow), PlotStyle.Hash, "MyPlot3");
      AddPlot(new Stroke(Brushes.Snow), PlotStyle.Hash, "MyPlot4");
      
      myIndicator1 = IndicatorName(Parameters, etc);
      
      //On Bar Update
      Values[2][0] = StorageSavedValueforPlot3;
      Values[3][0] = StorageSavedValueforPlot4;
      		
      if (Values[2][0] == 0)
      {
      Values[2].Reset();
      }
      		
      if (Values[3][0] == 0)
      {
      Values[3].Reset();
      }
      
      //On properties
      [Browsable(false)]
      [XmlIgnore()]
      private double StorageSavedValueforPlot3
      {
      	get
      	{
      		Update();
      		return myIndicator1.Upper[0]; //this value is printing well and showing in the data box, same for the plot4
      	}
      }
      		
      [Browsable(false)]
      [XmlIgnore()]
      private double StorageSavedValueforPlot4
      {
      	get
      	{
      		Update();
      		return myIndicator1.Lower[0];
      	}
      }
      As you can see, the 4 plots are highly similar, and they are all printing and showing in the databox, but the Plot3 and Plot4, don't get displayed on the chart.

      I also have IsOverlay on true, DrawOnPricePanel on true, and PlotConfigurable on true.
      (PS : i made sure that the width and color of the Plots made them all visible, so the issue do not come from the visibility of the plots).

      Thanks a lot for your help !

      Comment


        #4
        Looks like the Values[2][0] and Values[3][0] in the second example don't have plots associated with them. You are showing only plots 0 and 1 added with the names MyPlot3 and MyPlot4. Hard to tell what's what with these snippets.
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment


          #5
          Hello Robinson94,

          Thank you for your response.

          eDanny is correct as it is a bit hard to tell what is occurring from the snippets. Can you attach the full code to your response?

          You can export your indicator by going to Tools > Export > NinjaScript Add On > Add > select your indicator > OK > Export > name the file 'NTsupport' > Save.

          The file will be located under Documents\NinjaTrader 8\bin\Custom\ExportNinjaScript. Please attach the file to your response.

          I look forward to your response.

          Comment


            #6
            Thanks for the quick respond !

            In did, you are both right, the lines that i included are a bit confusing.

            Surely you are right Danny about the plots not having the values associated with them, since the lines that i send you are not clear, and if you take a look at the strategy, you will see (i do on my part), that the value are well showing in the databox attached to the value of the plot, but its only the plot that is not displaying, but the value of the plots, are well there.


            So here's the complete current strategie with 2 addons and the indicator it use (you don't have to install the addons if you want to look at the code of the strategie, but if you want to test the strategie to see if it may not coming from the script, you will need the addons that are there for sharing data between the indicators).

            Also, as i was telling the first post, that the 2 firsts plots were working and displaying well, but not the last 2 (in the strategy plot1 is swinglowidentified ; plot2 is swinghighidentified ; plot3 is minimumvaguecorrectivehaussičre ; and plot 4 is minimumvaguecorrectivebaissičre), and from today, without touching the code, the first two plots stopped displaying, and the last two, still not displaying.
            So the current situation is, all 4 plots printing and having there value in the databox, but none of them actually plotting on the chart.

            PS : the strategy is not that small, but is organised in region

            PPS Edit : The issue, most likely come from something in the code of the strategy, and not the plots themselves, since, when trying to create other plots, and giving them a simple fixed value, or something without a complex calculation, the same issue happen, that the plots are printing, showing up in the databox, but not on the chart.

            Have a great day !
            Last edited by Robinson94; 03-06-2018, 05:07 AM.

            Comment


              #7
              Hello Robinson94,

              Thank you for your response.

              In the OnRender() call of your strategy make sure to call base.OnRender() to ensure the plots render as needed.

              For example:
              Code:
              		protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
              		{
              			base.OnRender(chartControl, chartScale);
              Please let me know if you have any questions.

              Comment


                #8
                Thanks a lot for your simple and highly effective answer ! The issue is fixed

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by mmenigma, Today, 02:22 PM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by frankthearm, Today, 09:08 AM
                9 responses
                35 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by NRITV, Today, 01:15 PM
                2 responses
                9 views
                0 likes
                Last Post NRITV
                by NRITV
                 
                Started by maybeimnotrader, Yesterday, 05:46 PM
                5 responses
                26 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by quantismo, Yesterday, 05:13 PM
                2 responses
                21 views
                0 likes
                Last Post quantismo  
                Working...
                X