• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

My Code compiles, yet doesn't work right.

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

    My Code compiles, yet doesn't work right.

    The code Compiles and I can see an EMA on a chart . However, it stays solid blue. If I remove the else {
    PlotBrushes[0][0]= Range; }, it stays solid lime green. My Slopeperiod = 45 shows up in the indicator parameters, however, it does nothing when adjusted. I've been working on this all day. Frustrated as hell!

    #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;
    AddPlot(Brushes.Orange, "Slope_Color");
    }
    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]);


    double slopePeriod1 = Math.Tan(5 * Math.PI/180);

    double trueSlope = Math.Atan(slopePeriod1 * 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);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    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);
    }
    }
    }

    #endregion



    #2
    Hello jamestrader21x,
    Thanks for your post.

    Lets start with your SlopePeriod parameter. I do see that you would be able to set it inside the indicators window, but I do not set that you are actually using SlopePeriod in your logic.
    JoshNinjaTrader Customer Service

    Comment


      #3
      I don't understand the Syntax for Slope(). Some one would need to provide a better example than what's in the help guide and I don't mean (Slope(20),5,0).
      that Iseries<double>series doesn't make any sense to a newbie like myself. i don't know how it coincides with the math.atan (slope * 180/math.PI) or whatever. It would be nice if NJ would put out some videos explaining these things with examples. Coding is frustrating.

      Comment


        #4
        jamestrader21x,

        I'd be happy to submit a request for you. I see there is already demand for for an increased library of NinjaScript tips videos and will have your vote added to the requests that I see.

        Before I do, can you please elaborate on the specific tips you would want discussed in this video about Slope? Do you mean just more NinjaScript tutorial videos in general?


        Last edited by NinjaTrader_JoshG; 11-13-2018, 03:27 PM.
        JoshNinjaTrader Customer Service

        Comment


          #5
          I'd like them to explain the whole concept of Slope() in general.
          "
          Syntax Slope(ISeries<double>series,intstartBarsAgo,intendBarsAgo)" What does "ISeries<double>series" mean? How about an example of what it looks like it c# code.

          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

          They don't tell you how to use it along with Slope(). The help guide is very vague; and for a newbie like myself, frustrating to try and figure out. NJ uses non traditional C# jargon. I tried to find my own work around but was unsuccessful.

          Comment


            #6
            jamestrader21x,

            I have recorded this request in SFT-3168,

            Maybe if you tell me the general pseudocode for your logic I may be able to help you figure this out. I find copy/paste code difficult to read.
            Last edited by NinjaTrader_JoshG; 11-14-2018, 12:15 PM.
            JoshNinjaTrader Customer Service

            Comment


              #7
              I'm trying to develop a Tri-colored EMA with a Slope parameter. If EMA up slope reaches x degrees, then the EMA changes to Up trend color, If EMA down slope reaches x degrees, then the EMA changes to the down trend color. If neither +/- degree parameter is triggered, then the EMA remains the Range Color. I wanted to add in a custom Slope period setting. That is what I'm trying to write code for. Having trouble with the syntax for Slope() and the math.atan(slope) * 180/math.PI.... Still working on it. Still unsuccessful.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by johnnybegoode, Today, 11:35 AM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_ChrisL  
              Started by NickyD, Today, 09:07 AM
              3 responses
              14 views
              0 likes
              Last Post NickyD
              by NickyD
               
              Started by 7robert, Today, 06:46 AM
              3 responses
              62 views
              0 likes
              Last Post NinjaTrader_ChrisL  
              Started by ElMagoR, Today, 07:49 AM
              4 responses
              31 views
              0 likes
              Last Post NinjaTrader_ChrisL  
              Started by Nabil, 09-13-2019, 11:44 AM
              5 responses
              35 views
              0 likes
              Last Post Nabil
              by Nabil
               
              Working...
              X