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

Type 'double' can't implicitly be converted to 'NinjaTrader.NinjaScript.Series<double

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

    Type 'double' can't implicitly be converted to 'NinjaTrader.NinjaScript.Series<double

    Hi
    I used to use NT7 but have switched to NT8. I have tried to convert the code for one of my indicators to NT8 but I can't get it to work. I get an error code CS0029 saying that the "Type 'double' can't implicitly be converted to 'NinjaTrader.NinjaScript.Series<double>'". I don't understand what the problem is since the variable is a double and so is the Series.

    The following is my code for the properties.

    #region Properties
    [Range(0.0, double.MaxValue)]
    [NinjaScriptProperty]
    [Display(Name="MarketVolume", Order=1, GroupName="Parameters")]


    public double MarketVolume
    { get; set; }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> UpVolume
    {
    get { return Values[0]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> DownVolume
    {
    get { return Values[0]; }
    }
    #endregion

    can anyone tell what I'm doing wrong?

    #2
    Hello The_Wiz, and thank you for your question.

    The provided code sample looks correct and compiles cleanly. It looks like the cause of this message is happening elsewhere in the code. Can you provide any code samples where any of MarketVolume, UpVolume, or DownVolume are used?

    The message we are receiving is telling us that we are trying to use an individual double where a series of many doubles is expected.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Hi

      Sure, you can have the whole code. It is meant to simply accumulate the volume on waves of up candles and down candles.

      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion

      //This namespace holds Indicators in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Indicators
      {
      public class VolumeAccumulationTest : Indicator
      {
      private Series<double> Values;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Accumulates Volume on waves";
      Name = "VolumeAccumulationTest";
      Calculate = Calculate.OnBarClose;
      IsOverlay = false;
      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;
      MarketVolume = 2.0;
      AddPlot(new Stroke(Brushes.Lime, 2), PlotStyle.Bar, "UpVolume");
      AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Bar, "DownVolume");
      }
      else if (State == State.Configure)
      {
      Values = new Series<double>(this);
      Print("Crap");
      }
      }
      double trendDirection = 2;

      protected override void OnBarUpdate()
      {
      Print("crap");//Add your custom indicator logic here.
      if (CurrentBar < 1)
      return;

      //if (Time[0].Date != Time[1].Date)
      //{
      //
      //marketVolume = Volume[0];
      //}
      //else
      {
      if(Close[1]>Open[1])
      { trendDirection = 1;
      }
      else if(Close[1]<Open[1])
      { trendDirection = 0;
      }
      if(trendDirection == 1)
      {
      if(Close[0]>=Open[0])
      {
      MarketVolume += Volume[0];

      Values[0] = MarketVolume;
      Values[1] = 0.0;
      }
      else if(Close[0]<Open[0])
      {
      MarketVolume = Volume[0];
      Values[1] = MarketVolume;
      Values[0] = 0.0;
      }
      }
      else if(trendDirection == 0)
      {
      if(Close[0]>Open[0])
      {
      MarketVolume = Volume[0];
      Values[0] = MarketVolume;
      Values[1] = 0.0;
      }
      else if(Close[0]<=Open[0])
      {
      MarketVolume += Volume[0];
      Values[1] = MarketVolume;
      Values[0] = 0.0;
      }
      }
      }
      Print(MarketVolume);
      }

      #region Properties
      [Range(0.0, double.MaxValue)]
      [NinjaScriptProperty]
      [Display(Name="MarketVolume", Order=1, GroupName="Parameters")]


      public double MarketVolume
      { get; set; }

      [Browsable(false)]
      [XmlIgnore]
      public Series<double> UpVolume
      {
      get { return Values[0]; }
      }

      [Browsable(false)]
      [XmlIgnore]
      public Series<double> DownVolume
      {
      get { return Values[0]; }
      }
      #endregion

      }
      }

      #region NinjaScript generated code. Neither change nor remove.

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
      {
      private VolumeAccumulationTest[] cacheVolumeAccumulationTest;
      public VolumeAccumulationTest VolumeAccumulationTest(double marketVolume)
      {
      return VolumeAccumulationTest(Input, marketVolume);
      }

      public VolumeAccumulationTest VolumeAccumulationTest(ISeries<double> input, double marketVolume)
      {
      if (cacheVolumeAccumulationTest != null)
      for (int idx = 0; idx < cacheVolumeAccumulationTest.Length; idx++)
      if (cacheVolumeAccumulationTest[idx] != null && cacheVolumeAccumulationTest[idx].MarketVolume == marketVolume && cacheVolumeAccumulationTest[idx].EqualsInput(input))
      return cacheVolumeAccumulationTest[idx];
      return CacheIndicator<VolumeAccumulationTest>(new VolumeAccumulationTest(){ MarketVolume = marketVolume }, input, ref cacheVolumeAccumulationTest);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
      {
      public Indicators.VolumeAccumulationTest VolumeAccumulationTest(double marketVolume)
      {
      return indicator.VolumeAccumulationTest(Input, marketVolume);
      }

      public Indicators.VolumeAccumulationTest VolumeAccumulationTest(ISeries<double> input , double marketVolume)
      {
      return indicator.VolumeAccumulationTest(input, marketVolume);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.Strategies
      {
      public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
      {
      public Indicators.VolumeAccumulationTest VolumeAccumulationTest(double marketVolume)
      {
      return indicator.VolumeAccumulationTest(Input, marketVolume);
      }

      public Indicators.VolumeAccumulationTest VolumeAccumulationTest(ISeries<double> input , double marketVolume)
      {
      return indicator.VolumeAccumulationTest(input, marketVolume);
      }
      }
      }

      #endregion

      Comment


        #4
        Thank you The_Wiz. For reference I have added that code to a C# file I have attached to this reply.

        Near the beginning of your code, you defined

        Code:
        [FONT=Courier New]private Series<double> Values;[/FONT]
        Doing so overrides the NinjaScript built-in Values array, which is more similar to

        Code:
        [FONT=Courier New]List<Series<double>> Values;[/FONT]
        That is documented here,



        When I delete this line of code - line 29 - and refactor your code as I have done in my second attached example, so that every time

        Code:
        [FONT=Courier New]Values[x][/FONT]
        appears on the left hand side of an equals sign, it becomes

        Code:
        [FONT=Courier New]Values[0][x][/FONT]
        Then the code compiles cleanly. Please let us know if there are any other ways we can help.
        Attached Files
        Jessica P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,604 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        8 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        4 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        13 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X