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

Paramaters for SampleSecondarySeriesAsInputSeries Indicator in a Strategy

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

    Paramaters for SampleSecondarySeriesAsInputSeries Indicator in a Strategy

    HI there,

    I have created an indicator based on this sample indicator and wish to use it in a strategy. I have basically created SMA's of customized MAX( using highs) and MIN(using lows) to use in the Futures regular market hours using.( these are just set to calculate highs and lows instead of High Close and Low Close)

    Add(PeriodType.Minute, 405); to get regular sessions SMAs of daily session highs and lows. I have the indicator built and calculating and displaying exactly as I want. using a 5 min chart.

    I wold now like to use it in a strategy, but I am unclear on what needs to be done. Again I am using a 5 min chart.

    Do I need to Add the 405 bar to the strategy as it is already added in the indicator? and use the bars in progress logic in the strategy to mirror the indicator? I have added the customizable SMA length as per below.

    When I add the Indicator to the initialize there are 4 options.
    1. (IDataSeries input)
    2. () (+3 overloads)
    3. (int period)
    4. (IDataSeries input, int period)


    I have tried the () and the (int period) but the indicator does not produce values in the strategy. I am assuming I have to declare the PeriodType.Minute, 405 in some fashion but I am not sure how to do it.



    Here is my indicator

    Code:
    [Description("STESSecondarySeries405Edit")]
    public class STESSecondarySeries405Edit : Indicator
    {
    private SMA SMAst2;
    private MAXst MAXst2;
    private MINst MINst2;
    private SMA SMAst3;
    
    private int period = 5;
    
    protected override void Initialize()
    {
    Add(PeriodType.Minute, 405);
    Add(new Plot(Color.Green, PlotStyle.Line, "SMAMAXst"));
    Plots[0].Pen.Width = 2;
    Add(new Plot(Color.Red, PlotStyle.Line, "SMAMINst"));
    Plots[1].Pen.Width = 2;
    
    Overlay = true;
    }
    
    protected override void OnStartUp()
    {
    
    MAXst2 = MAXst(BarsArray[1], 1);
    MINst2 = MINst(BarsArray[1], 1);
    SMAst2 = SMA(MAXst2,period);
    SMAst3 = SMA(MINst2, period);
    
    }
    
    protected override void OnBarUpdate()
    {
    
    if (!Bars.BarsType.IsIntraday)
    {
    DrawTextFixed("error msg", "ST Series 405 only workes on intraday charts with a session set of 9:30 am- 4:15pm", TextPosition.BottomRight);
    
    }
    
    else
    {
    DrawTextFixed("good msg", "ST Series avg MIN & MAX last X days 9:30am-4:15pm session ", TextPosition.BottomRight);
    }
    
    // ensure both series have at least one bar
    if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
    return;
    
    // when the 405 minute series is processing set the secondary plot to the MAXst with the secondary series input
    if (BarsInProgress == 1)
    SMAst [0] = SMAst2 [0];
    SMAst1 [0] = SMAst3 [0];
    
    
    
    // when the primary series is processing set the primary plot to the MAXst with the primary series input
    if (BarsInProgress == 0)
    {
    //MAXstPrimary[0] = MAXst1[0];
    
    // if the secondary 5 minute series did not close, set the current bar's value to the previous bar's value to prevent gaps
    
    if (!SMAst.ContainsValue(0))
    SMAst[0] = SMAst[1];
    if (!SMAst1.ContainsValue(0))
    SMAst1[0] = SMAst1[1];
    
    
    }
    }
    
    [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 SMAst
    {
    get { return Values[0]; }
    }
    
    [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 SMAst1
    {
    get { return Values[1]; }
    }
    
    #region Properties
    /// <summary>
    /// </summary>
    [Description("Numbers of bars used for calculations")]
    [GridCategory("Parameters")]
    public int Period
    {
    get { return period; }
    set { period = Math.Max(1, value); }
    }
    #endregion

    #2
    Hello stalt,

    Below is a link to the help guide for this example.


    Are there errors in the Log tab of the Control Center when running the indicator?

    Can this be added and displayed on a chart without being called from a Strategy?

    Have you printed in the indicator to see when values are being set?


    The DrawTextFixed appears to be called for both BarsInProgress, is the text appearing on the chart?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks. I read the help file to get through building my indicator.

      There was an error on the log when trying to plot on daily bars. I have changed to code so it will not draw in intraday bars now, but will only print the warning if someone tries to load non-intraday bars. The new code there is as follows. Now when I load this indicator on daily bars I get the draw text and when I load the indicator on the intraday I get no text. The log is showing no errors

      if (!Bars.BarsType.IsIntraday)
      {
      DrawTextFixed("error msg", "ST Series 405 only works on intraday charts with a session set of 9:30 am- 4:15pm", TextPosition.BottomRight);
      return;
      }

      This indicator is plotting on a chart and displaying the values correctly, both in the data box and via print . I have attached an image


      In my Strategy I want to test buying above or below both these SMA lines. (They are SMA's of the 405 timeframe, so that is why the value is static during the 5 min bars.

      Again just looking for the Paramaters and process needed to reference these values in a strategy based on 5 min bars. Hope that helps.

      Click image for larger version

Name:	indicator image.jpg
Views:	293
Size:	156.9 KB
ID:	1115383


      Comment


        #4
        I got it working.....Thanks. Please consider closed. I had a spelling error in my strategy. Sorry to waste your time. I can't imagine how many request for support are simple spelling or syntax errors. guilty as charged! I do appreciate this sample immensely as it allowed me to do exactly what I wanted and is way less resource intensive than my previous solution.

        Comment


          #5
          Hello stalt,

          To call an indicator:

          MyIndicator(myParameters).MyPlot[barIndex]

          STESSecondarySeries504Edit(5).SMAMAXst[0]
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ghoul, Today, 06:02 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          44 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          20 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          179 views
          0 likes
          Last Post jeronymite  
          Started by DanielSanMartin, Yesterday, 02:37 PM
          2 responses
          13 views
          0 likes
          Last Post DanielSanMartin  
          Working...
          X