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

What's wrong with my code??

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

    What's wrong with my code??


    Getting error codes:
    The name 'trueSlope' does not exist in the current context CS0103 Line 61
    'System.math' does not contain a definition for "Pi" CS0117 Line 61
    No overload for method 'Slope' takes 1 arguments CS1501 Line 64
    Cannot implicitly convert type "System.Windows.Media.Brush" to NinjaTrader.NinjaScript.BrushSeries CS0029 Line 66
    Cannot implicitly convert type "System.Windows.Media.Brush" to NinjaTrader.NinjaScript.BrushSeries CS0029 Line 68


    public class MyTest : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "MyTest";
    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;
    Period = 14;
    UpSlope = Brushes.LimeGreen;
    DownSlope = Brushes.Red;
    Range = Brushes.Blue;
    SlopePeriod = 45;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    Value[0] = (CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);

    trueSlope = Math.Atan(SlopePeriod * 180/Math.Pi);


    if (Slope(Value) >= trueSlope)
    {
    PlotBrushes[0] = UpSlope;
    } else {
    PlotBrushes[0] = Range;
    }
    if (Slope(Value) <= trueSlope)
    {
    PlotBrushes[0] = DownSlope;
    } else {
    PlotBrushes[0] = Range;
    }
    }

    #2
    Hello jamestrader21x,

    Thank you for the note.

    Did you create a property named trueSlope? I don't see it getting set up in State.SetDefaults.

    Math.PI (capital 'I') is the correct syntax to access PI.

    For the Slope indicator, you must pass in some additional items, below is the constructor:

    Slope(ISeries<double> series, int startBarsAgo, int endBarsAgo)

    For the PlotBrushes, you must access the second dimension of the array to set a brush, like so:

    PlotBrushes[0][0] = UpSlope;

    Please let me know if I can assist further.




    Last edited by NinjaTrader_ChrisL; 11-13-2018, 09:16 AM.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Getting error code:
      Cannot Implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?) CS0266 Line 63 Column 29

      I fixed everything I could. here is all of the code, plus corrections. I'm getting the above error now. "Did you create a property named trueSlope? I don't see it getting set up in State.SetDefaults." I don't know what you mean by this. New to c# and coding. The Slope() is confusing to me. I'd have to see some code written for it. The formula which is returned from the parameters passed is:


      (series[endBarsAgo] - series[startBarsAgo]) / (startBarsAgo - endBarsAgo) I'd need to see an example of this in code form. and how does it tie in with Tip: Thinking in degrees, for example a 1 to -1 return range would translate to 45 to -45. To convert you could look into working with this formula - Math.Atan(Slope) * 180 / Math.PI



      #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.Gui.Tools;
      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 MyTest : Indicator
      {
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Indicator here.";
      Name = "MyTest";
      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;
      Period = 14;
      UpSlope = Brushes.LimeGreen;
      DownSlope = Brushes.Red;
      Range = Brushes.Blue;
      SlopePeriod = 45;
      }
      else if (State == State.Configure)
      {
      }
      }

      protected override void OnBarUpdate()
      {
      Value[0] = (CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);



      int trueSlope = Math.Atan(SlopePeriod * 180 / Math.PI);

      if (Value[0] >= trueSlope);
      {
      PlotBrushes[0][0] = UpSlope;
      }
      if (Value[0] <= trueSlope)
      {
      PlotBrushes[0][0] = DownSlope;
      } else {
      PlotBrushes[0][0]= Range;
      }
      }

      #region Properties
      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="Period", Order=1, GroupName="Parameters")]
      public int Period
      { get; set; }

      [NinjaScriptProperty]
      [XmlIgnore]
      [Display(Name="UpSlope", Order=2, GroupName="Parameters")]
      public Brush UpSlope
      { get; set; }

      [Browsable(false)]
      public string UpSlopeSerializable
      {
      get { return Serialize.BrushToString(UpSlope); }
      set { UpSlope = Serialize.StringToBrush(value); }
      }

      [NinjaScriptProperty]
      [XmlIgnore]
      [Display(Name="DownSlope", Order=3, GroupName="Parameters")]
      public Brush DownSlope
      { get; set; }

      [Browsable(false)]
      public string DownSlopeSerializable
      {
      get { return Serialize.BrushToString(DownSlope); }
      set { DownSlope = Serialize.StringToBrush(value); }
      }

      [NinjaScriptProperty]
      [XmlIgnore]
      [Display(Name="Range", Order=4, GroupName="Parameters")]
      public Brush Range
      { get; set; }

      [Browsable(false)]
      public string RangeSerializable
      {
      get { return Serialize.BrushToString(Range); }
      set { Range = Serialize.StringToBrush(value); }
      }

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="SlopePeriod", Order=5, GroupName="Parameters")]
      public int SlopePeriod
      { get; set; }
      #endregion

      }
      }

      #region NinjaScript generated code. Neither change nor remove.

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
      {
      private MyTest[] cacheMyTest;
      public MyTest MyTest(int period, Brush upSlope, Brush downSlope, Brush range, int slopePeriod)
      {
      return MyTest(Input, period, upSlope, downSlope, range, slopePeriod);
      }

      public MyTest MyTest(ISeries<double> input, int period, Brush upSlope, Brush downSlope, Brush range, int slopePeriod)
      {
      if (cacheMyTest != null)
      for (int idx = 0; idx < cacheMyTest.Length; idx++)
      if (cacheMyTest[idx] != null && cacheMyTest[idx].Period == period && cacheMyTest[idx].UpSlope == upSlope && cacheMyTest[idx].DownSlope == downSlope && cacheMyTest[idx].Range == range && cacheMyTest[idx].SlopePeriod == slopePeriod && cacheMyTest[idx].EqualsInput(input))
      return cacheMyTest[idx];
      return CacheIndicator<MyTest>(new MyTest(){ Period = period, UpSlope = upSlope, DownSlope = downSlope, Range = range, SlopePeriod = slopePeriod }, input, ref cacheMyTest);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
      {
      public Indicators.MyTest MyTest(int period, Brush upSlope, Brush downSlope, Brush range, int slopePeriod)
      {
      return indicator.MyTest(Input, period, upSlope, downSlope, range, slopePeriod);
      }

      public Indicators.MyTest MyTest(ISeries<double> input , int period, Brush upSlope, Brush downSlope, Brush range, int slopePeriod)
      {
      return indicator.MyTest(input, period, upSlope, downSlope, range, slopePeriod);
      }
      }
      }

      Comment


        #4
        Try either
        • double trueSlope = Math.Atan(SlopePeriod * 180 / Math.PI);
        or
        • int trueSlope = (int)Math.Atan(SlopePeriod * 180 / Math.PI);
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment


          #5
          Hello jamestrader21x,

          Thanks for the reply.

          eDanny is correct in fixing the type issue. Math.Atan will return a double data type, not an int.

          There is an example of using the Slope indicator on the help guide page here:



          The first parameter is the series to evaluate (an array of values) the second is where it should start the calculation (counting from the right) and the third parameter is where it should end. If you wanted the most current value to end at, put a 0.

          Please let me know if I can assist further.
          Chris L.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by sidlercom80, 10-28-2023, 08:49 AM
          168 responses
          2,262 views
          0 likes
          Last Post sidlercom80  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by WeyldFalcon, 12-10-2020, 06:48 PM
          14 responses
          1,429 views
          0 likes
          Last Post Handclap0241  
          Started by DJ888, 04-16-2024, 06:09 PM
          2 responses
          9 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          41 views
          0 likes
          Last Post jeronymite  
          Working...
          X