Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

using List instead of series

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

    using List instead of series

    Dear ladies and gentlemen,

    when a specific signal occure, I like to safe a lot of Data of this point. But the Problem is, that I´m not able to backtest the strategy, because of the historical Data i would need, I gess, it´s safed, I rather would use a DataSeries.

    My question is to I have to set public properties for each Data so that i can use it for plotting or to show it in the DataBox and for backtests?

    In the following a little Indicator to show what i mean.

    thanks for your help in advance.


    Code:
    public class SeriesCombinedWithList : Indicator
    {
    public MyHigh MyHigh;
    public List<MyHigh> myHighs;
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "SeriesCombinedWithList";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    AddPlot(Brushes.Orange, "MaxHigh");
    }
    else if (State == State.Configure)
    {
    myHighs = new List<MyHigh>();
    }
    }
    
    protected override void OnBarUpdate()
    {
    if (CurrentBar < 14)
    return;
    
    if(High[0] > MAX(High, 14)[1])
    {
    MyHigh = new MyHigh(High[0], Low[0], CurrentBar);
    myHighs.Add(MyHigh);
    }
    }
    
    #region Properties
    
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> MaxHigh
    {
    get { return Values[0]; }
    }
    #endregion
    
    }
    
    public class MyHigh
    {
    public double High { get; set; }
    public double Low { get; set; }
    public double Id { get; set; }
    
    public MyHigh(double high, double low, double id)
    {
    High = high;
    Low = low;
    Id = id;
    }
    }
    }


    #2
    Hi sane1111, thanks for writing in. It's easiest to use a Series<T> because there is a slot index created automatically for every bar on the chart or backtest. You must use AddPlot() to add plots to your strategy, and from there you can set Values[0][0] = MySeries[0]; Values[1][0] = MySeries1[0] and so on. If you have bars where no data should be set, you can use a sentinel value like -1, set the PlotBrushes to Transparent, and advanced to the next bar.

    Kind regards,
    -ChrisL

    Comment


      #3
      Dear ChrisL,

      thanks for your help!

      As far as "sentinel value" is concerned, I looked up at the internet about this, but I´m not sure if i unterstand it correctly and i do not know in which case I have to use it.

      in the following i constructed the Doji where i used the sentienel value. but does it makes sense to use it like this.

      thanks for your help in advande!

      Code:
      public class Doji : Indicator
      {
      int dDoji;
      public Series<double> DojiHighSeries;
      public Series<double> DojiLowSeries;
      public Series<double> DojiOpenSeries;
      public Series<double> DojiCloseSeries;
      public Series<int> DojiIdSeries;
      CandleType candleType;
      
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = "";
      Name = "Doji";
      IsOverlay = true;
      IsSuspendedWhileInactive = true;
      DojiBody = 50;
      }
      else if (State == State.Configure)
      {
      
      }
      else if(State == State.DataLoaded)
      {
      DojiHighSeries = new Series<double>(this);
      DojiLowSeries = new Series<double>(this);
      DojiOpenSeries = new Series<double>(this);
      DojiCloseSeries = new Series<double>(this);
      DojiIdSeries = new Series<int>(this);
      
      candleType = CandleType();
      }
      }
      
      protected override void OnBarUpdate()
      {
      if (CurrentBar < 1)
      return;
      
      if (IndicatorLogic())
      {
      BarBrush = Brushes.Fuchsia;
      
      //by using the Plot NT calculates to long
      //Draw.ArrowUp(this, "Doji" + CurrentBar, true, 0, Low[0] - 2, Brushes.Red);
      
      DojiHighSeries[0] = High[0];
      DojiLowSeries[0] = Low[0];
      DojiOpenSeries[0] = Open[0];
      DojiCloseSeries[0] = Close[0];
      DojiId[0] = CurrentBar;
      }
      
      DojiHighSeries[0] = -1;
      DojiLowSeries[0] = -1;
      DojiOpenSeries[0] = -1;
      DojiCloseSeries[0] = -1;
      DojiId[0] = -1;
      }
      
      private bool IndicatorLogic()
      {
      double candleLength = High[0] - Low[0];
      double candleBody;
      double upperExtreme;
      double lowerExtreme;
      
      if (candleType.CandleLong[0])
      candleBody = Close[0] - Open[0];
      else
      candleBody = Open[0] - Close[0];
      
      if (candleType.CandleLong[0])
      upperExtreme = High[0] - Close[0];
      else
      upperExtreme = High[0] - Open[0];
      
      if (candleType.CandleLong[0])
      lowerExtreme = Open[0] - Low[0];
      else
      lowerExtreme = Close[0] - Low[0];
      
      
      if (((int)Math.Round((candleBody * 100) / candleLength)) <= this.dDoji && upperExtreme == lowerExtreme)
      return true;
      
      return false;
      }
      
      public override string DisplayName
      {
      get { return "Doji"; }
      }
      
      #region Properties
      [NinjaScriptProperty]
      [Range(1, 100)]
      [Display(Name = "Dodji Body in %", Description = "", Order = 1, GroupName = "Refersal Bars")]
      public int DojiBody
      {
      get { return dDoji; }
      set { dDoji = value; }
      }
      
      [Browsable(false)]
      [XmlIgnore()]
      public Series<double> DojiHigh
      {
      get { return DojiHighSeries; }
      }
      
      [Browsable(false)]
      [XmlIgnore()]
      public Series<double> DojiLow
      {
      get { return DojiLowSeries; }
      }
      
      [Browsable(false)]
      [XmlIgnore()]
      public Series<double> DojiOpen
      {
      get { return DojiOpenSeries; }
      }
      
      [Browsable(false)]
      [XmlIgnore()]
      public Series<double> DojiClose
      {
      get { return DojiCloseSeries; }
      }
      
      [Browsable(false)]
      [XmlIgnore()]
      public Series<int> DojiId
      {
      get { return DojiIdSeries; }
      set { DojiIdSeries = value; }
      }
      #endregion
      }
      Last edited by sane1111; 07-22-2022, 06:00 AM.

      Comment


        #4
        Hi, thanks for your reply. The -1 value is just used to indicate that there is no valuable data in that particular bar index. So if you read a -1 from any series it means there is no candlestick pattern found. If you see a value that is not -1 then it means your indicator has a value for that bar index.

        Kind regards,
        -ChrisL

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        51 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        127 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X