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

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.
    Josh G.NinjaTrader 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.
        Josh G.NinjaTrader 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.
            Josh G.NinjaTrader 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 GussJ, 03-04-2020, 03:11 PM
              11 responses
              3,229 views
              0 likes
              Last Post xiinteractive  
              Started by andrewtrades, Today, 04:57 PM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by chbruno, Today, 04:10 PM
              0 responses
              7 views
              0 likes
              Last Post chbruno
              by chbruno
               
              Started by josh18955, 03-25-2023, 11:16 AM
              6 responses
              441 views
              0 likes
              Last Post Delerium  
              Started by FAQtrader, Today, 03:35 PM
              0 responses
              12 views
              0 likes
              Last Post FAQtrader  
              Working...
              X